Skip to content

Commit

Permalink
Merge pull request #226 from fisuda/hardening/orion_ld_version
Browse files Browse the repository at this point in the history
Support version command for Orion-LD
  • Loading branch information
fisuda committed Jan 28, 2022
2 parents 5b161c9 + 45bc42f commit 36d6005
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,6 +1,7 @@
## NGSI Go v0.10.0-next

- Update: Update Orion-LD to 1.0.1 (#225)
- Update: Update Orion-LD to 1.0.1 (#226)
- Hardening: Support version command for Orion-LD (#225)
- Hardening: Allows to create subs even if specifying only uri (#224)
- Update: Update Orion to 3.5.0 (#223)
- Update: Update copyright (#222)
Expand Down
3 changes: 1 addition & 2 deletions docs/apis_mapping_table.md
Expand Up @@ -74,8 +74,7 @@ These tables show the mapping from FIWARE Open APIs to NGSI Go commands.

| Orion-LD API | NGSI Go commands |
| -------------------------- | --------------------- |
| GET /version | version |
| GET /ngsi-ld/ex/v1/version | (not yet implemented) |
| GET /ngsi-ld/ex/v1/version | version |
| POST /ngsi-ld/ex/v1/notify | (not yet implemented) |

### Scorpio broker API
Expand Down
27 changes: 18 additions & 9 deletions e2e/cases/2000_convenience/0901_version_command.test
Expand Up @@ -62,15 +62,24 @@ ngsi version --host orion-ld

```
{
"orionld version": "REGEX(.*)",
"orion version": "REGEX(.*)",
"uptime": "REGEX(.*)",
"git_hash": "REGEX(([0-9a-f]{40}|nogitversion))",
"compile_time": "REGEX(.*)",
"compiled_by": "REGEX(.*)",
"compiled_in": "REGEX(.*)",
"release_date": "REGEX(.*)",
"doc": "REGEX(.*)"
"Orion-LD version": "REGEX(.*)",
"based on orion": "REGEX(.*)",
"kbase version": "REGEX(.*)",
"kalloc version": "REGEX(.*)",
"khash version": "REGEX(.*)",
"kjson version": "REGEX(.*)",
"microhttpd version": "REGEX(.*)",
"rapidjson version": "REGEX(.*)",
"libcurl version": "REGEX(.*)",
"libuuid version": "REGEX(.*)",
"mongocpp version": "REGEX(.*)",
"mongoc version": "REGEX(.*)",
"mongodb server version": "REGEX(.*)",
"boost version": "REGEX(.*)",
"openssl version": "REGEX(.*)",
"branch": "REGEX(.*)",
"cached subscriptions": REGEX(.*),
"Next File Descriptor": REGEX(.*)
}
```

Expand Down
8 changes: 6 additions & 2 deletions internal/convenience/version.go
Expand Up @@ -42,9 +42,9 @@ import (
func cbVersion(c *ngsicli.Context, ngsi *ngsilib.NGSI, client *ngsilib.Client) error {
const funcName = "cbVersion"

client.SetPath("/version")

switch client.Server.ServerType {
default:
client.SetPath("/version")
case "cygnus":
client.SetPath("/v1/version")
case "iota":
Expand All @@ -53,6 +53,10 @@ func cbVersion(c *ngsicli.Context, ngsi *ngsilib.NGSI, client *ngsilib.Client) e
client.SetPath("/perseo-core/version")
case "wirecloud":
client.SetPath("/api/features")
case "broker":
if client.Server.NgsiType == "ld" && client.Server.BrokerType == "orion-ld" {
client.SetPath("/ngsi-ld/ex/v1/version")
}
}

res, body, err := client.HTTPGet()
Expand Down
9 changes: 7 additions & 2 deletions internal/convenience/version_test.go
Expand Up @@ -57,12 +57,17 @@ func TestVersionLD(t *testing.T) {

reqRes := helper.MockHTTPReqRes{}
reqRes.Res.StatusCode = http.StatusOK
reqRes.Path = "/version"
reqRes.Path = "/ngsi-ld/ex/v1/version"
reqRes.ResBody = []byte(`{"Orion-LD version":"1.0.1-PRE-468","based on orion":"1.15.0-next","kbase version":"0.8","kalloc version":"0.8","khash version":"0.8","kjson version":"0.8","microhttpd version":"0.9.72-0","rapidjson version":"1.0.2","libcurl version":"7.61.1","libuuid version":"UNKNOWN","mongocpp version":"1.1.3","mongoc version":"1.17.5","mongodb server version":"4.4.11","boost version":"1_66","openssl version":"OpenSSL 1.1.1k FIPS 25 Mar 2021","branch":"","cached subscriptions":0,"Next File Descriptor":20}`)
helper.SetClientHTTP(c, reqRes)

err := cbVersion(c, c.Ngsi, c.Client)

assert.NoError(t, err)
if assert.NoError(t, err) {
actual := helper.GetStdoutString(c)
expected := "{\"Orion-LD version\":\"1.0.1-PRE-468\",\"based on orion\":\"1.15.0-next\",\"kbase version\":\"0.8\",\"kalloc version\":\"0.8\",\"khash version\":\"0.8\",\"kjson version\":\"0.8\",\"microhttpd version\":\"0.9.72-0\",\"rapidjson version\":\"1.0.2\",\"libcurl version\":\"7.61.1\",\"libuuid version\":\"UNKNOWN\",\"mongocpp version\":\"1.1.3\",\"mongoc version\":\"1.17.5\",\"mongodb server version\":\"4.4.11\",\"boost version\":\"1_66\",\"openssl version\":\"OpenSSL 1.1.1k FIPS 25 Mar 2021\",\"branch\":\"\",\"cached subscriptions\":0,\"Next File Descriptor\":20}"
assert.Equal(t, expected, actual)
}
}

func TestVersionIota(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/ngsilib/client.go
Expand Up @@ -169,7 +169,7 @@ func (client *Client) SetAcceptGeoJSON() {
// SetPath is ...
func (client *Client) SetPath(urlPath string) {
if client.Server.ServerType == "broker" {
if !hasPrefix([]string{"/version", "/admin", "/log", "/statistics", "/cache", "/scorpio", "/v1"}, urlPath) {
if !hasPrefix([]string{"/version", "/admin", "/log", "/statistics", "/cache", "/scorpio", "/v1", "/ngsi-ld/ex"}, urlPath) {
if client.NgsiType == ngsiLd {
urlPath = "/ngsi-ld/v1" + urlPath
} else {
Expand Down

0 comments on commit 36d6005

Please sign in to comment.