8000 NS to GW changes into `main` by rustyjux · Pull Request #130 · bcgov/gwa-cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

NS to GW changes into main #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 69 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
6d18eaf
update readme
rustyjux Jun 6, 2024
f1557e3
fix `kong-httpbin` template does not work with `gwa apply` #105
rustyjux Jun 6, 2024
931d9a6
remove unused sections from cc-sidp template
rustyjux Jun 6, 2024
70d7880
Only publish service if GatewayService provided #99
rustyjux Jun 6, 2024
18c827b
fixed test for changed cc-sidp template
rustyjux Jun 6, 2024
e739252
show errors for `apply`
rustyjux Jun 6, 2024
0cd51c5
remove appId from cc-sidp template
rustyjux Jun 7, 2024
662f0c3
change visible references of `namespace` to `gateway` - #103
rustyjux Jun 7, 2024
7fc7f39
rename files to gateway
rustyjux Jun 10, 2024
729c372
complete rename Namespaces to Gateways
rustyjux Jun 10, 2024
3374569
Name > GatewayID
rustyjux Jun 10, 2024
23c9fe8
Description > DisplayName
rustyjux Jun 10, 2024
5fa5aee
amend usage doc
rustyjux Jun 10, 2024
c60dbff
revise prompts (don't ask for gateway-id)
rustyjux Jun 11, 2024
cfa6c4a
after interactive: show success msg, set current gw
rustyjux Jun 11, 2024
7d95e5e
revise stdout
rustyjux Jun 11, 2024
0042d3d
bump versions in env.example
rustyjux Jun 12, 2024
5b6c3cc
handle errors when HTML content returned
rustyjux Jun 18, 2024
a28edc6
bump API version in release GHA
rustyjux Jun 18, 2024
600df72
add --hosts flag for `status`
rustyjux Jun 25, 2024
8e82951
minor refactor
rustyjux Jun 25, 2024
7f85408
remove Hosts, prepend https:// on EnvHosts
rustyjux Jun 26, 2024
000ac3f
Merge pull request #107 from bcgov/feature/gwa-gateway
rustyjux Jun 27, 2024
e26a83d
trigger v3 prerelease
rustyjux Jul 3, 2024
d6f7588
modify GHA to patch bump version
rustyjux Jul 3, 2024
f2e4257
Service validation
Elson9 Jul 8, 2024
b819fc5
update `set token` description
rustyjux Jul 10, 2024
bfae2e6
tweak docs format
rustyjux Jul 15, 2024
c5832a8
yml -> yaml
rustyjux Jul 18, 2024
675a791
remove 'default' for apply -i help (wasn't default)
rustyjux Jul 25, 2024
e2bb0ab
APS-2673
Jul 29, 2024
a19dbc6
Merge branch 'feature/ns-to-gw' into APS-2673
Jul 29, 2024
7833a30
Update contribute.md
Jul 29, 2024
9e5d151
Update README.md
Jul 29, 2024
3253881
add quick-start template
rustyjux Jul 29, 2024
072e633
add test
rustyjux Jul 29, 2024
9355b6d
Update README.md
Jul 29, 2024
b62440f
Merge pull request #116 from bcgov/APS-2673
SateeshFW Jul 30, 2024
4716e14
Merge pull request #117 from bcgov/feature/ns-to-gw-basic-service
rustyjux Jul 30, 2024
a8e5332
add note to top of docs
rustyjux Aug 1, 2024
4dca1e8
Merge branch 'feature/ns-to-gw' of https://github.com/bcgov/gwa-cli i…
rustyjux Aug 1, 2024
299d7ad
add tests for service name validation
rustyjux Aug 1, 2024
32d9fcb
Merge branch 'feature/ns-to-gw' into feature/service-validation
rustyjux Aug 1, 2024
aac5b5f
Merge pull request #114 from bcgov/feature/service-validation
rustyjux Aug 1, 2024
86d5b77
fix mistakes during conflict resolution
rustyjux Aug 1, 2024
c7587c3
update displayname constraints
rustyjux Aug 1, 2024
e307269
Add display name and table for gateway list cmd
Elson9 Aug 13, 2024
9881732
Always use v3 for gateway list
Elson9 Aug 13, 2024
d31387c
Add display name and table for gateway current cmd
Elson9 Aug 13, 2024
a495b7f
Update tests for list and current cmds
Elson9 Aug 15, 2024
991437d
restore ctx.ApiVersion in API calls
Elson9 Aug 15, 2024
e917871
Handle invalid gateway in current cmd
Elson9 Aug 16, 2024
97070fe
Disable Set the global API version command
Elson9 Aug 16, 2024
c4d790f
Merge pull request #118 from bcgov/feature/ns-to-gw-show-disp-name
Elson9 Aug 16, 2024
943f1ff
Merge pull request #120 from bcgov/feature/ns-to-gw
Elson9 Aug 16, 2024
d9a2464
Fix generateConfig tests
Elson9 Aug 16, 2024
b8e0390
Merge pull request #121 from bcgov/feature/ns-to-gw
Elson9 Aug 16, 2024
af88117
fix security class on CC template
rustyjux Aug 27, 2024
6cfede7
trigger pre-release
rustyjux Aug 27, 2024
9d1ec6b
trigger prelease
rustyjux Aug 27, 2024
d692373
Loading message for service validation
Elson9 Aug 29, 2024
659617f
modify loader / error for generate-config
rustyjux Aug 30, 2024
46d210e
reorder error messages / next steps
rustyjux Aug 30, 2024
3a2be33
add quotes in next steps
rustyjux Aug 30, 2024
0bc1d4f
specify Gateway ID in docs
rustyjux Sep 3, 2024
53ceeb4
Merge pull request #122 from bcgov/feature/ns-to-gw-tweak-messages
rustyjux Sep 10, 2024
99c8eb8
update device login message
rustyjux Sep 10, 2024
af89578
Merge pull request #125 from bcgov/feature/handshake-msg
rustyjux Sep 10, 2024
80607d8
Merge pull request #126 from bcgov/feature/ns-to-gw
Elson9 Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
env:
GWA_API_HOST: api.gov.bc.ca
GWA_CLIENT_ID: gwa-cli
GWA_VERSION: v2
GWA_VERSION: v3

jobs:
release-tag:
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Pre-release

on:
push:
branches:
- pre-release

env:
GWA_API_HOST: api.gov.bc.ca
GWA_CLIENT_ID: gwa-cli
GWA_VERSION: v3

jobs:
release-tag:
name: create release tag
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- id: release
uses: rymndhng/release-on-push-action@v0.28.0
with:
bump_version_scheme: patch
release_body: "This is a prerelease version intended for testing purposes. It may contain new features, improvements, and bug fixes that are not yet fully stable. We encourage you to try it out and provide feedback. If you encounter any issues, please report them on our issue tracker. Thank you for helping us improve!"
outputs:
version_number: ${{ steps.release.outputs.tag_name }}

goreleaser:
runs-on: ubuntu-latest
needs: release-tag
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: extractions/setup-just@v1
- uses: actions/setup-go@v4
with:
go-version: stable
- name: Run Unit Tests
run: just test
- uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: v1.20.0
args: release --verbose --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CLI_VERSION: ${{ needs.release-tag.outputs.version_number }}
135 changes: 38 additions & 97 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,124 +1,65 @@
# GWA CLI

<img src="https://github.com/bcgov/gwa-cli/workflows/Build/badge.svg"></img>
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=gwa-cli&metric=alert_status)](https://sonarcloud.io/dashboard?id=gwa-cli)
[![img](https://img.shields.io/badge/Lifecycle-Stable-97ca00)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)

> **NOTE:** This tool is going through rapid development and could change often. Check back for updates.

`gwa` is a tool for composing, validating and generating Kong Gateway configuration files from OpenAPI (aka Swagger) specs and managing Kong Plugins.
`gwa` is a tool for composing, validating and publishing Gateway configuration files to the BC Government's [API Services Portal](https://api.gov.bc.ca).

## Documentation

Currently documentation is limited to the APS [USER-JOURNEY.md](https://github.com/bcgov/gwa-api/blob/dev/USER-JOURNEY.md) and via the installed executable's help commands. A hosted website option is in the works and will be available soon.

To run help on any command while using the CLI:

```sh
$ gwa-cli login --help
You can login via device login or by using client credentials

To use device login, simply run the command like so:
$ gwa login

To use your credentials you must supply both a client-id and client-secret:
$ gwa login --client-id <YOUR_CLIENT_ID> --client-secret <YOUR_CLIENT_SECRET>
...

```

To generate a Markdown-formatted string of every command's documentation to `stdout`, run `$ just docs`. You could then pipe it to a file like so `$ just docs > gwa-commands.md`, though this will be just a temporary solution.

## Development

Prerequisites:
- [Go](https://go.dev) 1.20 or higher
- [Just](https://github.com/casey/just) (alternative to `make`)
- [GoReleaser](https://gore 3419 leaser.com)

Tools:
- [Cobra] Command line argument parser
- [Viper](https://github.com/spf13/viper) Configuration file manager, integrates tightly with Cobra
- [Lipgloss](https://github.com/charmbracelet/lipgloss) Styles and colours

#### Steps to set up dev environment

1. Verify you have Go 1.20+ installed

```sh
$ go version
```
If you don't have `go` installed on your machine, follow instructions on [the Go website](https://golang.org/doc/install).

2. Clone this repository

```sh
$ git clone git@github.com:bcgov/gwa-cli.git
$ cd gwa-cli
$ mv env.example .env
```
**Note** Some local environments require Go projects are run from the `$HOME/go/src` directory. If any `module not found` errors are reported, try moving it.

Also be sure to fill in the environment variables before running a command.

3. Run commands

Test any commmands by running `just run` in the `cwd`. You can also use `$ just test` to run all tests.

```sh
$ just run namespace current
your-namespace
$ just test
? github.com/bcgov/gwa-cli [no test files]
ok github.com/bcgov/gwa-cli/cmd
ok github.com/bcgov/gwa-cli/pkg
```
## Installation

4. Set up your IDE
To get started with `gwa`, follow the detailed instructions provided in the DevHub [installation](https://developer.gov.bc.ca/docs/default/component/aps-infra-platform-docs/how-to/gwa-install/) guide.

Go has great tooling which is required to ensure code contributed is formatted consitently and is type-safe.
## Usage

- **VSCode:** Install the [official Go extension](https://marketplace.visualstudio.com/items?itemName=golang.Go)
- **NeoVim:** [go.nvim](https://github.com/ray-x/go.nvim) is a great plugin
### Use `--help`

#### Nix develop (optional)
To make the most out of the `gwa` tool, you can use the `--help` option to get detailed information on its various commands and options. Here's how you can use it:

Instead of installing Go on your system you can alternatively use Nix to manage Go and other dependencies for you. This option assumes you already running NixOS or have Nix installed.
1. **General Help**: To get an overview of all available commands, run:
```sh
gwa --help
```
This will list all the primary commands and provide a brief description of each.

2. **Command-Specific Help**: To get detailed information about a specific command, use `--help` with the command in question. For example, if you want to learn more about the `gateway` command, you can run:
```sh
gwa gateway --help
```
This will provide detailed information about the `gateway` command, including its syntax, options, and examples.

Simply run `$ nix develop` in the project root. This will pull all the dependencies needed to work on this project. Remember to run `exit` to leave the Nix shell when done.
### Online documentation

## Deployment
Explore `gwa` commands in an easy-to-read reference format on the DevHub [CLI commands page](https://developer.gov.bc.ca/docs/default/component/aps-infra-platform-docs/reference/gwa-commands/).

Details on how the deployment process work are coming soon as we migrate codebase languages.
The content on this page is the same as the `--help` output.

Make sure you have GoReleaser installed to test locally.
## Support

###### Tip
If you need support or have any questions about using `gwa`, you can reach out to our team in the following ways:

A dry-run of the build process can be executed by running `$ just release`. This will compile your source code into a `/dist` folder where you can run any platform's executable.
### Rocket.Chat

## Installation
Rocket.Chat is a community platform where you can connect with our team and other users.
Create an account on [Rocket.Chat](https://docs.developer.gov.bc.ca/join-bc-rocket-chat/) and join the [#aps-ops](https://chat.developer.gov.bc.ca/channel/aps-ops) channel. In this channel, you can:

Currently `gwa` is only installable by building from source. The releases page will be updated one it's ready.
- Ask questions
- Share feedback
- Get real-time support
- Engage with other users who might have similar questions or use cases

To install locally you can follow the first 2 steps in Development above, then run
### GitHub issue tracker

```sh
$ just install
...
$ gwa-cli
gwa version 2.0.0-beta
```
Alternatively, if you prefer asynchronous communication or need to report a bug, request a feature, or provide feedback, please use our GitHub [issue tracker](https://github.com/bcgov/gwa-cli/issues). On our GitHub issue tracker, you can:

#### Completions
- File new issues for bugs or feature requests
- Track the status of reported issues
- Contribute to discussions on existing issues
- View the roadmap and planned enhancements

Shell completions for all the commands ships with each version. Completions allow you to tab while entering commands to cycle though a list of possible commands.
By using either of these methods, our team will be able to assist you promptly and effectively. We are committed to ensuring you have a positive experience with `gwa` and are here to answer any questions you might have.

To install completions, run this after installing, using `zsh` for example:
## Want to contribute?

```sh
$ gwa-cli completion zsh --help
$ gwa-cli completion zsh | pbcopy
```
See [CONTRIBUTING.md](https://github.com/bcgov/gwa-cli/blob/main/contribute.md) for more info on how to make contributions to this project.

Then follow the instructions from the help command and paste the output where it needs to live. Bash, Fish and Powershell are also supported.
5 changes: 4 additions & 1 deletion build/gen-docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ func main() {

func writeDocument(rootCmd *cobra.Command) string {
var output strings.Builder
output.WriteString("# GWA CLI Commands\n\n")
output.WriteString("---\n")
output.WriteString("title: GWA CLI Commands\n")
output.WriteString("---\n\n")
output.WriteString("<!-- NOTE: This file is generated from gwa-cli, do not edit directly -->\n\n")
output.WriteString(fmt.Sprintf("%s\n", rootCmd.Long))

for _, cmd := range rootCmd.Commands() {
Expand Down
2 changes: 1 addition & 1 deletion build/gen-docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestWriteDocument(t *testing.T) {
configCmd.AddCommand(configGetCmd)
rootCmd.AddCommand(configCmd)
output := writeDocument(rootCmd)
expect := "# GWA CLI Commands\n\nThis is a long title\n\n## config\n\n**Usage:** `gwa config`\n\n\n### config.get\n\n**Usage:** `gwa config get`\n\n"
expect := "---\ntitle: GWA CLI Commands\n---\n\n<!-- NOTE: This file is generated from gwa-cli, do not edit directly -->\n\nThis is a long title\n\n## config\n\n**Usage:** `gwa config`\n\n\n### config.get\n\n**Usage:** `gwa config get`\n\n"
assert.Equal(t, expect, output)
}

Expand Down
36 changes: 30 additions & 6 deletions cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ func (o *ApplyOptions) Parse() error {
}
}
}
o.output = append([]interface{}{gatewayService}, o.output...)

// Only append gatewayService if it has configurations
if len(gatewayService.Config) > 0 {
o.output = append([]interface{}{gatewayService}, o.output...)
}
10000 return nil
}

Expand Down Expand Up @@ -142,25 +146,31 @@ $ gwa apply --input gw-config.yaml
if err != nil {
return err
}
pkg.Info("Namespace:" + ctx.Namespace)
pkg.Info("Gateway:" + ctx.Gateway)

counter := &PublishCounter{}
printBlankLine := false
var errors []string // Collect error messages here

for _, config := range opts.output {
switch c := config.(type) {
case GatewayService:
printBlankLine = true
fmt.Println()
fmt.Printf("↑ Publishing Gateway Services")
res, err := PublishGatewayService(ctx, c.Config)
if err != nil {
counter.AddFailed()
fmt.Print("\r")
fmt.Printf("%s Gateway Services publish failed\n", pkg.Times())
pkg.Error(fmt.Sprintf("Publish Error: %v", err))
errorMessage := fmt.Sprintf("[GatewayService]: %v", err)
pkg.Error(errorMessage)
errors = append(errors, errorMessage)
break
}

counter.AddSuccess()
fmt.Println()
fmt.Printf("%s Gateway Services published\n", pkg.Checkmark())
fmt.Println(res.Results)
fmt.Print("\r")
Expand All @@ -172,13 +182,19 @@ $ gwa apply --input gw-config.yaml
break

case Resource:
if !printBlankLine {
fmt.Println()
printBlankLine = true
}
fmt.Printf("↑ [%s] %s", c.Kind, c.Config["name"])
result, err := PublishResource(ctx, c.Config, c.GetAction())
if err != nil {
counter.AddFailed()
fmt.Print("\r")
fmt.Printf("%s [%s] %s failed\n", pkg.Times(), c.Kind, c.Config["name"])
pkg.Error(fmt.Sprintf("Resource Error: %v", err))
errorMessage := fmt.Sprintf("Resource [%s] %s: %v", c.Kind, c.Config["name"], err)
pkg.Error(errorMessage)
errors = append(errors, errorMessage)
break
}

Expand All @@ -192,11 +208,19 @@ $ gwa apply --input gw-config.yaml
fmt.Println()
fmt.Println(counter.Print())

if len(errors) > 0 {
fmt.Println()
fmt.Println(pkg.Times(), pkg.PrintError("Errors encountered"))
for _, errMsg := range errors {
fmt.Println(errMsg)
}
}

return nil
},
}

applyCmd.Flags().StringVarP(&opts.input, "input", "i", "gw-config.yml", "YAML file containing your configuration")
applyCmd.Flags().StringVarP(&opts.input, "input", "i", "", "YAML file containing your configuration")
applyCmd.MarkFlagRequired("input")

return applyCmd
Expand All @@ -216,7 +240,7 @@ func PublishResource(ctx *pkg.AppContext, doc map[string]interface{}, arg string
if err != nil {
return "", err
}
route := fmt.Sprintf("/ds/api/%s/namespaces/%s/%ss", ctx.ApiVersion, ctx.Namespace, arg)
route := fmt.Sprintf("/ds/api/%s/gateways/%s/%ss", ctx.ApiVersion, ctx.Gateway, arg)
URL, _ := ctx.CreateUrl(route, nil)
request, err := pkg.NewApiPut[PutResponse](ctx, URL, bytes.NewBuffer(body))
if err != nil {
Expand Down
Loading
Loading
0