Skip to content

Commit

Permalink
Merge pull request #56 from aalyria/AEF21A3B2E469738714E3BCDAF044166
Browse files Browse the repository at this point in the history
Project import generated by Copybara.
  • Loading branch information
dgnemo authored Sep 5, 2023
2 parents 934a8ed + 7e6ded9 commit f9a0e37
Show file tree
Hide file tree
Showing 15 changed files with 1,006 additions and 577 deletions.
30 changes: 29 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,34 @@ gazelle_dependencies()
#
# Downloads are not cached in version control mode.

go_repository(
name = "com_github_urfave_cli_v2",
importpath = "github.com/urfave/cli/v2",
sum = "h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=",
version = "v2.25.7",
)

go_repository(
name = "com_github_xrash_smetrics",
importpath = "github.com/xrash/smetrics",
sum = "h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=",
version = "v0.0.0-20201216005158-039620a65673",
)

go_repository(
name = "com_github_cpuguy83_go_md2man_v2",
importpath = "github.com/cpuguy83/go-md2man/v2",
sum = "h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=",
version = "v2.0.2",
)

go_repository(
name = "com_github_russross_blackfriday_v2",
importpath = "github.com/russross/blackfriday/v2",
sum = "h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=",
version = "v2.1.0",
)

go_repository(
name = "com_github_cenkalti_backoff_v4",
importpath = "github.com/cenkalti/backoff/v4",
Expand Down Expand Up @@ -526,4 +554,4 @@ rules_proto_grpc_java_repos()

rules_proto_grpc_python_repos()

py_repositories()
py_repositories()
10 changes: 10 additions & 0 deletions api/nbi/v1alpha/nbi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ message ListEntitiesOverTimeRequest {

// If set, only return entities with an ID in the list.
repeated string ids = 5;

// If set, only return entities that changed between the interval's start
// and end times. End may be before start to diff backwards in time.
//
// If multiple versions of an entity exist during the interval, the version
// that existed at the end time is returned (latest commit timestamp that's
// before or equal to the end time). If the entity doesn't exist or doesn't
// match the filter at the end time, but did exist or match at the start
// time, an entity with no value is returned.
optional bool diff = 6;
}

message ListEntitiesOverTimeResponse {
Expand Down
11 changes: 9 additions & 2 deletions tools/nbictl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,26 @@ go_library(
"connection.go",
"generate_rsa_key.go",
"nbictl.go",
"set_context.go",
"set_config.go",
],
importpath = "aalyria.com/spacetime/github/tools/nbictl",
visibility = ["//visibility:public"],
deps = [
"//api/common:common_go_proto",
"//api/nbi/v1alpha:nbi_go_grpc",
"//api/nbi/v1alpha/resources:nbi_resources_go_grpc",
"//cdpi_agent/internal/auth",
"//tools/nbictl/proto:nbictl_go_proto",
"@com_github_jonboulle_clockwork//:clockwork",
"@com_github_urfave_cli_v2//:cli",
"@go_googleapis//google/type:interval_go_proto",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials",
"@org_golang_google_grpc//credentials/insecure",
"@org_golang_google_protobuf//encoding/prototext",
"@org_golang_google_protobuf//proto",
"@org_golang_google_protobuf//types/known/durationpb",
"@org_golang_google_protobuf//types/known/timestamppb",
],
)

Expand All @@ -45,7 +52,7 @@ go_test(
"connection_test.go",
"fake_nbi_server_test.go",
"generate_rsa_key_test.go",
"set_context_test.go",
"set_config_test.go",
],
embed = [":nbictl"],
deps = [
Expand Down
185 changes: 102 additions & 83 deletions tools/nbictl/README.md
Original file line number Diff line number Diff line change
@@ -1,96 +1,115 @@
# nbictl -- NBI command-line tool
<!--
This file is autogenerated! Do not edit by hand!
Run `nbictl readme > README.md` to update it.
-->

`nbctl` allows you to interact with the Spacetime NBI APIs from the command-line.
# NAME

## Usage:
nbictl - Interact with the Spacetime NBI service from the command line.

```sh
$ nbictl <action> [--operation-specific-flags]
```

### Configuration actions
# SYNOPSIS

#### generate-keys
```
Usage of nbictl generate-key:
-country string
country of certificate
-dir string
directory where you want your RSA keys to be stored. Default: ~/.nbictl/
-location string
location of certificate
-org string
[REQUIRED] organization of certificate
-state string
state of certificate
nbictl [--context=value] [--help] [-h] <command> [COMMAND OPTIONS] [ARGUMENTS...]
```

> **Note**
> After creating the Private-Public keypair, you will need to request API access by
> sharing the `.crt` file (a self-signed x509 certificate containing the public key) with
> Aalyria to receive the `USER_ID` and a `KEY_ID` needed to complete the `nbictl` configuration.
# GLOBAL OPTIONS

> **Warning**
> Only share the public certificate (`.crt`) with Aalyria or third-parties.
> The private key (`.key`) must be protected and should never be sent by email
> or communicated to others in any.
**--context**="": Context (configuration profile) to reference for connection settings.

#### set-context
**--help, -h**: show help

You can create multiple contexts by specifying a name of context using `--context` flag.
If context name is not specified, the context will have name `DEFAULT`.
# COMMANDS

```
Usage of nbictl set-context:
-context string
context of NBI API environment (default "DEFAULT")
-key_id string
key id associated with the provate key provided by Aalyria
-priv_key string
path to your private key for authentication to NBI API
-transport_security string
transport security to use when connecting to NBI. Values: insecure, system_cert_pool
-url string
url of NBI endpoint
-user_id string
user id address associated with the private key provided by Aalyria
```
## create

### NBI actions
Create one or more entities described in textproto files.

**--files, -f**="": [REQUIRED] Glob of textproto files that represent one or more Entity messages.

## update

Updates one or more entities described in textproto files.

**--files, -f**="": [REQUIRED] Glob of textproto files that represent one or more Entity messages.

## list

Lists all entities of a given type.

**--type, -t**="": [REQUIRED] Type of entities to query. Allowed values: [ANTENNA_PATTERN, BAND_PROFILE, CDPI_STREAM_INFO, COMPUTED_MOTION, DEVICES_IN_REGION, DRAIN_PROVISION, INTENT, INTERFACE_LINK_REPORT, INTERFERENCE_CONSTRAINT, MOTION_DEFINITION, NETWORK_NODE, NETWORK_STATS_REPORT, PLATFORM_DEFINITION, PROPAGATION_WEATHER, SERVICE_REQUEST, STATION_SET, SURFACE_REGION, TRANSCEIVER_LINK_REPORT]

## delete

Deletes the entity with the given type and ID.

**--id**="": [REQUIRED] ID of entity to delete.

**--timestamp, --commit_time**="": [REQUIRED] Commit timestamp of entity to delete. (default: 0)

**--type, -t**="": [REQUIRED] Type of entity to delete. Allowed values: [ANTENNA_PATTERN, BAND_PROFILE, CDPI_STREAM_INFO, COMPUTED_MOTION, DEVICES_IN_REGION, DRAIN_PROVISION, INTENT, INTERFACE_LINK_REPORT, INTERFERENCE_CONSTRAINT, MOTION_DEFINITION, NETWORK_NODE, NETWORK_STATS_REPORT, PLATFORM_DEFINITION, PROPAGATION_WEATHER, SERVICE_REQUEST, STATION_SET, SURFACE_REGION, TRANSCEIVER_LINK_REPORT]

## get-link-budget

Gets link budget details

**--analysis_end_timestamp**="": An RFC3339 formatted timestamp for the end of the interval to evaluate the signal propagation. If unset, the signal propagation is evaluated at the instant of the `analysis_start_timestamp.`

**--analysis_start_timestamp**="": An RFC3339 formatted timestamp for the beginning of the interval to evaluate the signal propagation. Defaults to the current local timestamp.

**--band_profile_id**="": The Entity ID of the BandProfile used for this link.

**--explain_inaccessibility**: If true, the server will spend additional computational time determining the specific set of access constraints that were not satisfied and including these reasons in the response.

**--input_file**="": A path to a textproto file containing a SignalPropagationRequest message. If set, it will be used as the request to the SignalPropagation service. If unset, the request will be built from the other flags.

**--output_file**="": Path to a textproto file to write the response. If unset, defaults to stdout. (default: /dev/stdout)

**--reference_data_timestamp**="": An RFC3339 formatted timestamp for the instant at which to reference the versions of the platforms. Defaults to `analysis_start_timestamp`. (default: analysis_start_timestamp)

**--spatial_propagation_step_size**="": The analysis step size for spatial propagation metrics. (default: 1m)

**--step_size**="": The analysis step size and the temporal resolution of the response. (default: 1m)

**--target_platform_id**="": The Entity ID of the PlatformDefinition that represents the target. Leave unset if the antenna is fixed or non-steerable, in which case coverage calculations will be returned.

**--target_transceiver_model_id**="": The ID of the transceiver model on the target.Leave unset if the antenna is fixed or non-steerable, in which case coverage calculations will be returned.

**--tx_platform_id**="": The Entity ID of the PlatformDefinition that represents the transmitter.

**--tx_transceiver_model_id**="": The ID of the transceiver model on the transmitter.

## generate-keys

Generate RSA keys to use for authentication with the Spacetime APIs.

>After creating the Private-Public keypair, you will need to request API access by sharing the `.crt` file (a self-signed x509 certificate containing the public key) with Aalyria to receive the `USER_ID` and a `KEY_ID` needed to complete the nbictl configuration. Only share the public certificate (`.crt`) with Aalyria or third-parties. The private key (`.key`) must be protected and should never be sent by email or communicated to others.
**--country**="": Country of certificate.

**--dir, --directory**="": Directory to store the generated RSA keys in. (default: ~/.config/nbictl/keys)

**--location**="": Location of certificate.

**--org, --organization**="": [REQUIRED] Organization of certificate.

**--state**="": State of certificate.

## set-config

Sets or updates a configuration profile that contains NBI connection settings. You can create multiple configs by specifying the name of the configuration using the `--context` flag (defaults to "DEFAULT").

**--key_id**="": Key ID associated with the private key provided by Aalyria.

**--priv_key**="": Path to the private key to use for authentication.

**--transport_security**="": Transport security to use when connecting to the NBI service. Allowed values: [insecure, system_cert_pool]

**--url**="": URL of the NBI endpoint.

**--user_id**="": User ID associated with the private key provided by Aalyria.

## help, h

Shows a list of commands or help for one command

#### create
```
Usage of nbictl create:
-context string
name of context you want to use
-files path
[REQUIRED] a path to the textproto file containing information of the entity you want to create
```
#### update
```
Usage of nbictl update:
-context string
name of context you want to use
-files path
[REQUIRED] a path to the textproto file containing information of the entity you want to update
```
#### delete
```
Usage of nbictl delete:
-commit_time int
[REQUIRED] commit timestamp of the entity you want to delete (default -1)
-context string
name of context you want to use
-id string
[REQUIRED] the id of the entity you want to delete
-type string
[REQUIRED] type of entities you want to delete. list of possible types: [STATION_SET NETWORK_NODE CDPI_STREAM_INFO DRAIN_PROVISION INTENT INTERFACE_LINK_REPORT MOTION_DEFINITION NETWORK_STATS_REPORT BAND_PROFILE COMPUTED_MOTION TRANSCEIVER_LINK_REPORT ANTENNA_PATTERN PLATFORM_DEFINITION INTERFERENCE_CONSTRAINT PROPAGATION_WEATHER SERVICE_REQUEST DEVICES_IN_REGION SURFACE_REGION]
```
#### list
```
Usage of nbictl list:
-context string
name of context you want to use
-type string
[REQUIRED] type of entities you want to query. list of possible types: [DEVICES_IN_REGION NETWORK_STATS_REPORT PLATFORM_DEFINITION PROPAGATION_WEATHER SERVICE_REQUEST COMPUTED_MOTION ANTENNA_PATTERN BAND_PROFILE INTENT NETWORK_NODE TRANSCEIVER_LINK_REPORT CDPI_STREAM_INFO STATION_SET SURFACE_REGION DRAIN_PROVISION INTERFACE_LINK_REPORT INTERFERENCE_CONSTRAINT MOTION_DEFINITION]
```
50 changes: 5 additions & 45 deletions tools/nbictl/cmd/nbictl/nbictl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,55 +15,15 @@
package main

import (
"context"
"errors"
"flag"
"fmt"
"log"
"os"

nbictl "aalyria.com/spacetime/github/tools/nbictl"
"aalyria.com/spacetime/github/tools/nbictl"
)

var subCmds = map[string]func(context.Context, []string) error{
"list": nbictl.List,
"create": nbictl.Create,
"update": nbictl.Update,
"delete": nbictl.Delete,
"generate-keys": nbictl.GenerateKeys,
"set-context": nbictl.SetContext,
}

const (
linkToAuthGuide = "https://docs.spacetime.aalyria.com/authentication"
clientName = "nbictl"
)

func getSubcommandNames() []string {
var cmdList []string
for cmd := range subCmds {
cmdList = append(cmdList, cmd)
}
return cmdList
}

func run() error {
args := flag.Args()
if flag.NArg() == 0 {
return errors.New("Please specify a subcommand")
}
cmd, args := args[0], args[1:]
ctx := context.Background()

cmdToPerform, ok := subCmds[cmd]
if !ok {
return fmt.Errorf("invalid command: %s. must be one of %v", cmd, getSubcommandNames())
}
return cmdToPerform(ctx, args)
}

func main() {
flag.Parse()
if err := run(); err != nil {
log.Fatalf("fatal error: %v", err)
if err := nbictl.App().Run(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "fatal error: %v\n", err)
os.Exit(1)
}
}
Loading

0 comments on commit f9a0e37

Please sign in to comment.