Skip to content

Commit

Permalink
Merge pull request #182 from fisuda/improve/regproxy
Browse files Browse the repository at this point in the history
Add server, health and config sub-cmd to regproxy cmd
  • Loading branch information
fisuda committed Jul 18, 2021
2 parents f5256a8 + 56a06e9 commit 1e7928d
Show file tree
Hide file tree
Showing 15 changed files with 1,306 additions and 110 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NGSI Go v0.8.4-next

- Improve: Add server, health and config sub-cmd to regproxy cmd (#182)
- Improve: Refactor token manager (#181)
- Improve: Set default FIWARE Service Path to "/" in cp command (#180)
- Improve: Set default FIWARE Service Path to "/" in rm command (#179)
Expand Down
121 changes: 105 additions & 16 deletions docs/convenience/regproxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,118 @@
This command allows you to start up a registration proxy server. It's put between a context broker and
a Csource/CPr with a protected API endpoint.

- [Server](#server)
- [Sanity check](#sanity-check)
- [Configration](#config)

<a name="server"></a>

## Server

This command allows you to start up a registration proxy server.

```console
ngsi regproxy [options]
ngsi regproxy server [options]
```

## Options

| Options | Description |
| -------------------------------- | ------------------------------------------------ |
| --host value, -h value | context broker or csource host |
| --rhost value | host for registration proxy (default: "0.0.0.0") |
| --port value, -p value | port for registration proxy (default: "1028") |
| --url value, -u value | url for registration proxy (default: "/") |
| --replaceService value, -S value | replace FIWARE-Serivce |
| --replacePath value, -P value | replace FIWARE-SerivcePath |
| --replaceURL value, -U value | replace URL of forwarding destination |
| --https, -s | start in https (default: false) |
| --key value, -k value | key file (only needed if https is enabled) |
| --cert value, -c value | cert file (only needed if https is enabled) |
| --verbose, -v | verbose (default: false) |
| --help | show help (default: false) |
| Options | Description |
| ---------------------- | ------------------------------------------------ |
| --host value, -h value | context broker or csource host |
| --rhost value | host for registration proxy (default: "0.0.0.0") |
| --port value, -p value | port for registration proxy (default: "1028") |
| --url value, -u value | url for registration proxy (default: "/") |
| --replaceService value | replace FIWARE-Serivce |
| --replacePath value | replace FIWARE-SerivcePath |
| --addPath value | add path to FIWARE-SerivcePath |
| --replaceURL valuee | replace URL of forwarding destination |
| --https, -s | start in https (default: false) |
| --key value, -k value | key file (only needed if https is enabled) |
| --cert value, -c value | cert file (only needed if https is enabled) |
| --verbose, -v | verbose (default: false) |
| --help | show help (default: false) |

### Example

```console
ngsi --stderr info regproxy --host orion-with-keyrock --verbose
ngsi --stderr info regproxy server --host orion-with-keyrock --verbose
```

<a name="sanity-check"></a>

## Sanity check

This command allows you to check a regproxy server healthy.

```console
ngsi regproxy health [options]
```

## Options

| Options | Description |
| ---------------------- | ------------------------------ |
| --host value, -h value | regproxy host |
| --pretty, -P | pretty format (default: false) |
| --help | show help (default: false) |

### Example

```
ngsi server add --host regproxy --serverType regproxy --serverHost http://localhost:1028/
```

```
ngsi regproxy health --host regproxy --pretty
```

```
{
"ngsi-go": "regproxy",
"version": "0.8.4-next (git_hash:7392ed9962f42c6eca1f894465b6f7450d65958a)",
"health": "OK",
"csource": "https://orion.letfiware.jp",
"verbose": false,
"uptime": "0 d, 1 h, 32 m, 44 s",
"timesent": 5,
"success": 4,
"failure": 1
}
```

<a name="config"></a>

## Configration

This command allows you to change configration for a regproxy server.

```console
ngsi regproxy config [options]
```

## Options

| Options | Description |
| ------------------------- | --------------------------------------|
| --host value, -h value | regproxy host |
| --verbose value, -v value | verbose log (on/off) |
| --replaceService value | replace FIWARE-Serivce |
| --replacePath value | replace FIWARE-SerivcePath |
| --addPath value | add path to FIWARE-SerivcePath |
| --replaceURL value | replace URL of forwarding destination |
| --pretty, -P | pretty format (default: false)
| --help | show help (default: false)

### Example

```
ngsi regproxy config --host regproxy --verbose on --replacePath "/fiware" --replaceURL "" --pretty
```

```
{
"verbose": true,
"path": "/fiware"
}
```
6 changes: 5 additions & 1 deletion docs/management/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ ngsi server add \

### Server type

Specify the following value to `--serverType` option when you add an alias for FIWARE GE.
Specify the following value to `--serverType` option when you add an alias for FIWARE GE and other servers.

| FIWARE GE | serverType |
| ----------- | ----------- |
Expand All @@ -149,6 +149,10 @@ Specify the following value to `--serverType` option when you add an alias for F
| Keyrock | keyrock |
| WireCloud | wirecloud |

| NGSI Go | serverType |
| ----------------- | ---------- |
| regstration proxy | regproxy |

#### Example 3

The following example is how to add Keyrock as a server type. Specify an admin user name of Keyrock to
Expand Down
4 changes: 3 additions & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ ngsi [global options] command [common options] sub-command [options]
| [ls](./convenience/ls.md) | - | | list entities |
| [rm](./convenience/rm.md) | - | | remove entities |
| [receiver](./convenience/receiver.md) | - | | notification receiver |
| [regproxy](./convenience/regproxy.md) | - | | registration proxy |
| [regproxy](./convenience/regproxy.md) | [server](./convenience/regproxy.md#server) | | start up regproxy server |
| | [health](./convenience/regproxy.md#sanity-check) | | sanity check for regproxy server |
| | [config](./convenience/regproxy.md#config) | | change configuration for regproxy server |
| [template](./convenience/template.md) | [subscription](./convenience/template.md#subscription) | | create template of subscription |
| | [registration](./convenience/template.md#registration) | | create template of registration |
| [version](./convenience/version.md) | - | | print the version of Context Broker |
Expand Down
95 changes: 80 additions & 15 deletions e2e/cases/2000_convenience/1101_regproxy_command.test
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,88 @@ NAME:
ngsi regproxy - registration proxy

USAGE:
ngsi regproxy [command options] [arguments...]
ngsi regproxy command [command options] [arguments...]

CATEGORY:
CONVENIENCE
COMMANDS:
server start up regproxy server
health sanity check for regproxy server
config change configuration for regproxy server
help, h Shows a list of commands or help for one command

OPTIONS:
--host value, -h value context broker or csource host
--rhost value host for registration proxy (default: "0.0.0.0")
--port value, -p value port for registration proxy (default: "1028")
--url value, -u value url for registration proxy (default: "/")
--replaceService value, -S value replace FIWARE-Serivce
--replacePath value, -P value replace FIWARE-SerivcePath
--replaceURL value, -U value replace URL of forwarding destination
--https, -s start in https (default: false)
--key value, -k value key file (only needed if https is enabled)
--cert value, -c value cert file (only needed if https is enabled)
--verbose, -v verbose (default: false)
--help show help (default: false)
--help show help (default: false)
--version, -v print the version (default: false)

```

#
# 0002 ngsi regproxy server --help
#
ngsi regproxy server --help

```
NAME:
ngsi regproxy server - start up regproxy server

USAGE:
ngsi regproxy server [command options] [arguments...]

OPTIONS:
--host value, -h value context broker or csource host
--rhost value host for registration proxy (default: "0.0.0.0")
--port value, -p value port for registration proxy (default: "1028")
--url value, -u value url for registration proxy (default: "/")
--replaceService value replace FIWARE-Serivce
--replacePath value replace FIWARE-SerivcePath
--addPath value add path to FIWARE-SerivcePath
--replaceURL value replace URL of forwarding destination
--https, -s start in https (default: false)
--key value, -k value key file (only needed if https is enabled)
--cert value, -c value cert file (only needed if https is enabled)
--verbose, -v verbose (default: false)
--help show help (default: false)

```

#
# 0003 ngsi regproxy health --help
#
ngsi regproxy health --help

```
NAME:
ngsi regproxy health - sanity check for regproxy server

USAGE:
ngsi regproxy health [command options] [arguments...]

OPTIONS:
--host value, -h value regproxy host
--pretty, -P pretty format (default: false)
--help show help (default: false)

```

#
# 0004 ngsi regproxy config --help
#
ngsi regproxy config --help

```
NAME:
ngsi regproxy config - change configuration for regproxy server

USAGE:
ngsi regproxy config [command options] [arguments...]

OPTIONS:
--host value, -h value regproxy host
--verbose value, -v value verbose log (on/off)
--replaceService value replace FIWARE-Serivce
--replacePath value replace FIWARE-SerivcePath
--addPath value add path to FIWARE-SerivcePath
--replaceURL value replace URL of forwarding destination
--pretty, -P pretty format (default: false)
--help show help (default: false)

```
5 changes: 5 additions & 0 deletions internal/ngsicmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SOFTWARE.
package ngsicmd

import (
"fmt"
"net"
"net/http"

Expand Down Expand Up @@ -79,3 +80,7 @@ func getTime(ngsi *ngsilib.NGSI, v int64) string {
_ = ngsi.TimeLib.Unix(v/1000, 0)
return ngsi.TimeLib.Format("2006/01/02 15:04:05")
}

func humanizeUptime(t int64) string {
return fmt.Sprintf("%d d, %d h, %d m, %d s", (t/3600)/24, (t/3600)%24, (t/60)%60, t%60)
}
22 changes: 22 additions & 0 deletions internal/ngsicmd/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,25 @@ func TestGetTime(t *testing.T) {
actual := getTime(ngsi, 0)
assert.Equal(t, expected, actual)
}

func TestHumanizeUptime(t *testing.T) {
cases := []struct {
t int64
expected string
}{
{t: 0, expected: "0 d, 0 h, 0 m, 0 s"},
{t: 10, expected: "0 d, 0 h, 0 m, 10 s"},
{t: 61, expected: "0 d, 0 h, 1 m, 1 s"},
{t: 3662, expected: "0 d, 1 h, 1 m, 2 s"},
{t: 86401, expected: "1 d, 0 h, 0 m, 1 s"},
{t: 86401 + 3662, expected: "1 d, 1 h, 1 m, 3 s"},
{t: 86400 - 1, expected: "0 d, 23 h, 59 m, 59 s"},
{t: 86401*10 + 3662, expected: "10 d, 1 h, 1 m, 12 s"},
}

for _, c := range cases {
actual := humanizeUptime(c.t)
assert.Equal(t, c.expected, actual)
}

}
29 changes: 20 additions & 9 deletions internal/ngsicmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,19 +869,30 @@ var (
Usage: "cert file (only needed if https is enabled)",
}
regProxyReplaceTenantFlag = &cli.StringFlag{
Name: "replaceService",
Aliases: []string{"S"},
Usage: "replace FIWARE-Serivce",
Name: "replaceService",
Usage: "replace FIWARE-Serivce",
}
regProxyReplaceScopeFlag = &cli.StringFlag{
Name: "replacePath",
Aliases: []string{"P"},
Usage: "replace FIWARE-SerivcePath",
Name: "replacePath",
Usage: "replace FIWARE-SerivcePath",
}
regProxyAddScopeFlag = &cli.StringFlag{
Name: "addPath",
Usage: "add path to FIWARE-SerivcePath",
}
regProxyReplaceURLFlag = &cli.StringFlag{
Name: "replaceURL",
Aliases: []string{"U"},
Usage: "replace URL of forwarding destination",
Name: "replaceURL",
Usage: "replace URL of forwarding destination",
}
regProxyRegProxyHostFlag = &cli.StringFlag{
Name: "host",
Aliases: []string{"h"},
Usage: "regproxy host",
}
regProxyVerboseFlag = &cli.StringFlag{
Name: "verbose",
Aliases: []string{"v"},
Usage: "verbose log (on/off)",
}
)

Expand Down
4 changes: 4 additions & 0 deletions internal/ngsicmd/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ var configData = `{
"ngsiType": "ld",
"serverType": "broker",
"brokerType": "scorpio"
},
"regproxy": {
"serverHost": "https://regproxy",
"serverType": "regproxy"
}
},
"contexts": {
Expand Down

0 comments on commit 1e7928d

Please sign in to comment.