Skip to content

Commit f237d94

Browse files
committed
chore: #174 merge 1.x on master before release
Signed-off-by: Laurent Broudoux <[email protected]>
2 parents 14c1ee8 + 48ac36f commit f237d94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3128
-554
lines changed

.github/workflows/build-verify.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
run: echo "date=$(date +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
2828

2929
- name: Checkout Code
30-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v4
30+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
3131

3232
- name: Setup Go
3333
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 #v6.0.0
@@ -37,19 +37,30 @@ jobs:
3737

3838
- name: Build Go packages
3939
run: |
40-
./build-binaries.sh github.com/microcks/microcks-cli
40+
make clean
41+
make build-binaries
4142
4243
- name: Set environment for branch
4344
run: |
4445
set -x
4546
if [[ $GITHUB_REF == 'refs/heads/master' ]]; then
4647
echo "IMAGE_TAG=nightly" >> "$GITHUB_ENV"
48+
echo "IMAGE_TAG=nightly" >> "$GITHUB_OUTPUT"
4749
echo "PACKAGE_IMAGE=true" >> "$GITHUB_ENV"
50+
echo "PACKAGE_IMAGE=true" >> "$GITHUB_OUTPUT"
51+
elif [[ $GITHUB_REF == 'refs/heads/1.x' ]]; then
52+
echo "IMAGE_TAG=next" >> "$GITHUB_ENV"
53+
echo "IMAGE_TAG=next" >> "$GITHUB_OUTPUT"
54+
echo "PACKAGE_IMAGE=true" >> "$GITHUB_ENV"
55+
echo "PACKAGE_IMAGE=true" >> "$GITHUB_OUTPUT"
4856
elif [[ $GITHUB_REF == "refs/tags/$GITHUB_REF_NAME" ]]; then
4957
echo "IMAGE_TAG=$GITHUB_REF_NAME" >> "$GITHUB_ENV"
58+
echo "IMAGE_TAG=$GITHUB_REF_NAME" >> "$GITHUB_OUTPUT"
5059
echo "PACKAGE_IMAGE=true" >> "$GITHUB_ENV"
60+
echo "PACKAGE_IMAGE=true" >> "$GITHUB_OUTPUT"
5161
else
5262
echo "PACKAGE_IMAGE=false" >> "$GITHUB_ENV"
63+
echo "PACKAGE_IMAGE=false" >> "$GITHUB_OUTPUT"
5364
fi
5465
5566
- name: Install Cosign

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
id-token: write
2121
steps:
2222
- name: Checkout Code
23-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v4
23+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
2424
with:
2525
ssh-key: ${{ secrets.RELEASE_DEPLOY_KEY }}
2626
fetch-depth: 0

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@
1212
*.out
1313

1414
# Ouput of the build-binaries script
15-
build/_output
15+
build/dist
16+
17+
# .DS_Store file of MacOS
18+
.DS_Store
19+
20+
# test data files
21+
**/testdata/**

.goreleaser.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22

33
builds:
44
- main: ./main.go
5-
binary: microcks-cli
5+
binary: microcks
66
env:
77
- CGO_ENABLED=0
88

@@ -25,7 +25,7 @@ signs:
2525
- "${artifact}"
2626

2727
brews:
28-
- name: microcks-cli
28+
- name: microcks
2929
homepage: https://github.com/microcks/microcks-cli
3030
repository:
3131
owner: microcks

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
PACKAGE=github.com/microcks/microcks-cli
2+
CURRENT_DIR=$(shell pwd)
3+
DIST_DIR=${CURRENT_DIR}/build/dist
4+
CLI_NAME=microcks
5+
BIN_NAME=microcks
6+
WATCHER_NAME=watcher
7+
8+
HOST_OS=$(shell go env GOOS)
9+
HOST_ARCH=$(shell go env GOARCH)
10+
11+
.PHONY: build-local
12+
build-local:
13+
go build -o ${DIST_DIR}/${BIN_NAME}
14+
15+
.PHONY: clean
16+
clean:
17+
rm -rf ${CURRENT_DIR}/build/dist
18+
19+
.PHONY: build-binaries
20+
build-binaries:
21+
make BIN_NAME=${CLI_NAME}-linux-amd64 GOOS=linux build-local
22+
make BIN_NAME=${CLI_NAME}-linux-arm64 GOOS=linux GOARCH=arm64 build-local
23+
make BIN_NAME=${CLI_NAME}-darwin-amd64 GOOS=darwin build-local
24+
make BIN_NAME=${CLI_NAME}-darwin-arm64 GOOS=darwin GOARCH=arm64 build-local
25+
make BIN_NAME=${CLI_NAME}-windows-amd64.exe GOOS=windows build-local
26+
make BIN_NAME=${CLI_NAME}-windows-386.exe GOOS=windows GOARCH=386 build-local
27+
28+
.PHONY: build-watcher
29+
build-watcher:
30+
go build -o ${DIST_DIR}/${BIN_NAME}-${WATCHER_NAME} ${PACKAGE}/pkg/importer

README.md

Lines changed: 40 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -43,128 +43,57 @@ To get involved with our community, please make sure you are familiar with the p
4343

4444
## Usage instructions
4545

46-
Usage is simply `microcks-cli [command]`
47-
48-
where `[command]` can be one of the following:
49-
50-
* `version` to check this CLI version,
51-
* `help` to display usage informations,
52-
* `test` to launch new test on Microcks server.
53-
* `import` to import API artifacts on Microcks server.
54-
55-
### Test command
56-
57-
The `test` command has a bunch of arguments and flags so that you can use it that way:
58-
59-
```
60-
microcks-cli test <apiName:apiVersion> <testEndpoint> <runner>
61-
--microcksURL=<> --waitFor=5sec
62-
--keycloakClientId=<> --keycloakClientSecret=<>
63-
```
64-
65-
The arguments:
66-
67-
* `<apiName:apiVersion>` : Service to test reference. Example: `'Beer Catalog API:0.9'`
68-
* `<testEndpoint>` : URL where is deployed implementation to test
69-
* `<runner>` : Test strategy (one of: `HTTP`, `SOAP`, `SOAP_UI`, `POSTMAN`, `OPEN_API_SCHEMA`, `ASYNC_API_SCHEMA`, `GRPC_PROTOBUF`, `GRAPHQL_SCHEMA`)
70-
71-
The flags:
72-
73-
* `--microcksURL` for the Microcks API endpoint,
74-
* `--waitFor` for the time to wait for test to finish (int + one of: milli, sec, min),
75-
* `--keycloakClientId` for the Keycloak Realm Service Account ClientId,
76-
* `--keycloakClientSecret` for the Keycloak Realm Service Account ClientSecret.
77-
78-
> Since `0.5.2` release, `microcks-cli` also works in unauthenticated mode, without Keycloak being deployed and configured with your Microcks instance. However, you still have to specify the Keycloak flags on the command even if you put random values there. For eg. `--keycloakClientId=foo --keycloakClientSecret=bar`.
79-
80-
Real life example command and execution:
81-
82-
```sh
83-
$ ./microcks-cli test 'Beer Catalog API:0.9' http://localhost:9090/api/ POSTMAN \
84-
--microcksURL=http://localhost:8080/api/ \
85-
--keycloakClientId=microcks-serviceaccount \
86-
--keycloakClientSecret=7deb71e8-8c80-4376-95ad-00a399ee3ca1 \
87-
--waitFor=3sec
88-
[...]
89-
MicrocksClient got status for test "5c1781cf6310d94f8169384e" - success: false, inProgress: true
90-
MicrocksTester waiting for 2 seconds before checking again.
91-
MicrocksClient got status for test "5c1781cf6310d94f8169384e" - success: true, inProgress: false
92-
Full TestResult details are available here: http://localhost:8080/#/tests/5c1781cf6310d94f8169384e
46+
### Usage
47+
```bash
48+
microcks [command] [flags]
9349
```
9450

95-
#### Advanced options
96-
97-
The `test` command provides additional flags for advanced usages and options:
98-
99-
* `--verbose` allows to dump on standard output all the HTTP requests and responses,
100-
* `--insecure` allows to interact with Microcks and Keycloak instances through HTTPS without checking certificates issuer CA,
101-
* `--caCerts=<path1,path2>` allows to specify additional certificates CRT files to add to trusted roots ones,
102-
* `--secretName='<Secret Name>'` is an optional flag specifying the name of a Secret to use for connecting endpoint,
103-
* `--filteredOperations=<JSON>` allows to filter a list of operations to launch a test for,
104-
* `--operationsHeaders=<JSON>` allows to override some operations headers for the tests to launch,
105-
* `--oAuth2Context=<JSON>` allows specification of an OAuth2 grant flow to execute before launching the test (starts with Microcks version `1.8.0`).
51+
### Available Commands
52+
| Command | Description | Documentation |
53+
| ------------ | -------------------------------------------------------- | ----------------------------------------------- |
54+
| `login` | Log in to a Microcks instance using Keycloak credentials | [`login`](documentation/cmd/login.md) |
55+
| `logout` | Log out and remove authentication from a given context | [`logout`](documentation/cmd/logout.md) |
56+
| `context` | Manage CLI contexts (list, use, delete) | [`context`](documentation/cmd/context.md) |
57+
| `start` | Start a local Microcks instance via Docker/Podman | [`start`](documentation/cmd/start.md) |
58+
| `stop` | Stop a local Microcks instance | [`stop`](documentation/cmd/stop.md) |
59+
| `import` | Import API spec files from local filesystem | [`import`](documentation/cmd/import.md) |
60+
| `import-url` | Import API spec files directly from a remote URL | [`import-url`](documentation/cmd/import-url.md) |
61+
| `test` | Run tests against a deployed API using selected runner | [`test`](documentation/cmd/test.md) |
62+
| `version` | Print Microcks CLI version | [`version`](documentation/cmd/version.md) |
63+
64+
### Options
65+
66+
| Flag | Description |
67+
| ------------------------ | ------------------------------------------- |
68+
| `-h, --help` | help for microck command |
69+
| `--config` | Path to Microcks config file |
70+
| `--microcks-context` | Name of the Microcks context to use |
71+
| `--verbose` | Produce dumps of HTTP exchanges |
72+
| `--insecure-tls` | Allow insecure HTTPS connections |
73+
| `--caCerts` | Comma-separated paths of CA cert files |
74+
| `--keycloakClientId` | Keycloak Realm Service Account ClientId |
75+
| `--keycloakClientSecret` | Keycloak Realm Service Account ClientSecret |
76+
| `--microcksURL` | Microcks API URL |
10677

107-
Overriden test operations headers is a JSON strings where 1st level keys are operation name (eg. `GET /beer`) or `globals` for header applying to all the operations of the API. Headers are specified as an array of objects defining `key` and `values` properties.
10878

109-
Here's below an example of using some of this flags:
110-
111-
```sh
112-
$ ./microcks-cli test 'Beer Catalog API:0.9' http://localhost:9090/api/ OPEN_API_SCHEMA \
113-
--microcksURL=http://localhost:8080/api/ \
114-
--keycloakClientId=microcks-serviceaccount \
115-
--keycloakClientSecret=7deb71e8-8c80-4376-95ad-00a399ee3ca1 \
116-
--insecure --verbose --waitFor=3sec \
117-
--filteredOperations='["GET /beer", "GET /beer/{name}"]' \
118-
--operationsHeaders='{"globals": [{"name": "x-api-key", "values": "my-values"}], "GET /beer": [{"name": "x-trace-id", "values": "xcvbnsdfghjklm"}]}' \
119-
--oAuth2Context='{"clientId": "microcks-test", "clientSecret": "ab54d329-e435-41ae-a900-ec6b3fe15c54", "tokenUri": "https://idp.acme.org/realms/my-app/protocol/openid-connect/token", "grantType": "CLIENT_CREDENTIALS"}'
79+
## Installation
12080

121-
MicrocksClient got status for test "64c25f7ddec62569f9a0ed95" - success: true, inProgress: false
122-
Full TestResult details are available here: http://localhost:8080/#/tests/64c25f7ddec62569f9a0ed95
81+
### Building from Source
82+
To build the CLI locally:
83+
```bash
84+
make build-local
12385
```
12486

125-
### Import command
126-
127-
The `import` command has one argument and common flags with `test` command. You can use it that way:
128-
87+
The resulting binary will be available at:
88+
```bash
89+
/build/dist/microcks
12990
```
130-
microcks-cli import <specificationFile1[:primary],specificationFile2[:primary]>
131-
--microcksURL=<>
132-
--keycloakClientId=<> --keycloakClientSecret=<>
133-
```
134-
135-
The arguments:
136-
137-
* `<specificationFile1[:primary],specificationFile2[:primary]>` : Comma separated list of API specs to import with flag telling if it's a primary artifact. Example: `'specs/my-openapi.yaml:true,specs/my-postmancollection.json:false'`
138-
139-
The flags:
14091

141-
* `--microcksURL` for the Microcks API endpoint,
142-
* `--keycloakClientId` for the Keycloak Realm Service Account ClientId,
143-
* `--keycloakClientSecret` for the Keycloak Realm Service Account ClientSecret.
144-
145-
> Since `0.5.2` release, `microcks-cli` also works in unauthenticated mode, without Keycloak being deployed and configured with your Microcks instance. However, you still have to specify the Keycloak flags on the command even if you put random values there. For eg. `--keycloakClientId=foo --keycloakClientSecret=bar`.
146-
147-
Real life example command and execution:
148-
149-
```sh
150-
$ ./microcks-cli import 'samples/weather-forecast-openapi.yml:true,samples/weather-forecast-postman.json:false' \
151-
--microcksURL=http://localhost:8080/api/ \
152-
--keycloakClientId=microcks-serviceaccount \
153-
--keycloakClientSecret=7deb71e8-8c80-4376-95ad-00a399ee3ca1
154-
Microcks has discovered 'WeatherForecast API:1.1.0'
155-
Microcks has discovered 'WeatherForecast API:1.1.0'
92+
You can move it to a location in your $PATH for global usage, for example:
93+
```bash
94+
sudo mv build/dist/microcks /usr/local/bin/microcks
15695
```
15796

158-
#### Advanced options
159-
160-
The `import` command provides additional flags for advanced usages and options:
161-
162-
* `--verbose` allows to dump on standard output all the HTTP requests and responses,
163-
* `--insecure` allows to interact with Microcks and Keycloak instances through HTTPS without checking certificates issuer CA,
164-
* `--caCerts=<path1,path2>` allows to specify additional certificates CRT files to add to trusted roots ones,
165-
166-
167-
## Installation
16897

16998
### Binary
17099

build/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WORKDIR /app
55
ARG TARGETOS
66
ARG TARGETARCH
77
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
8-
go build -ldflags="-s -w" -o microcks-cli github.com/microcks/microcks-cli
8+
go build -ldflags="-s -w" -o microcks github.com/microcks/microcks-cli
99

1010
# Build image
1111
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5-1742914212
@@ -19,12 +19,12 @@ LABEL maintainer="Laurent Broudoux <[email protected]>" \
1919
org.opencontainers.image.documentation="https://github.com/microcks/microcks-cli" \
2020
io.artifacthub.package.readme-url="https://raw.githubusercontent.com/microcks/microcks-cli/master/README.md"
2121

22-
ENV CLI=/usr/local/bin/microcks-cli \
22+
ENV CLI=/usr/local/bin/microcks \
2323
USER_UID=1001 \
2424
USER_NAME=microcks-cli
2525

2626
# install cli binary
27-
COPY --from=build-env /app/microcks-cli ${CLI}
27+
COPY --from=build-env /app/microcks ${CLI}
2828

2929
COPY build/bin /usr/local/bin
3030
RUN /usr/local/bin/user_setup

cmd/cmd.go

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,50 @@
1515
*/
1616
package cmd
1717

18-
// Command define single method interface
19-
type Command interface {
20-
Execute()
18+
import (
19+
"github.com/microcks/microcks-cli/pkg/config"
20+
"github.com/microcks/microcks-cli/pkg/connectors"
21+
"github.com/microcks/microcks-cli/pkg/errors"
22+
"github.com/spf13/cobra"
23+
)
24+
25+
func NewCommad() *cobra.Command {
26+
27+
var clientOpts connectors.ClientOptions
28+
29+
command := &cobra.Command{
30+
Use: "microcks",
31+
Short: "A CLI tool for Microcks",
32+
SilenceUsage: true,
33+
Run: func(cmd *cobra.Command, args []string) {
34+
cmd.HelpFunc()(cmd, args)
35+
},
36+
CompletionOptions: cobra.CompletionOptions{
37+
HiddenDefaultCmd: true,
38+
},
39+
}
40+
41+
command.AddCommand(NewImportCommand(&clientOpts))
42+
command.AddCommand(NewVersionCommand())
43+
command.AddCommand(NewTestCommand(&clientOpts))
44+
command.AddCommand(NewImportURLCommand(&clientOpts))
45+
command.AddCommand(NewStartCommand(&clientOpts))
46+
command.AddCommand(NewStopCommand(&clientOpts))
47+
command.AddCommand(NewContextCommand(&clientOpts))
48+
command.AddCommand(NewLoginCommand(&clientOpts))
49+
command.AddCommand(NewLogoutCommand(&clientOpts))
50+
51+
defaultLocalConfigPath, err := config.DefaultLocalConfigPath()
52+
errors.CheckError(err)
53+
command.PersistentFlags().StringVar(&clientOpts.ConfigPath, "config", defaultLocalConfigPath, "Path to Microcks config")
54+
command.PersistentFlags().StringVar(&clientOpts.Context, "microcks-context", "", "Name of the Microcks context to use")
55+
command.PersistentFlags().BoolVar(&clientOpts.Verbose, "verbose", false, "Produce dumps of HTTP exchanges")
56+
command.PersistentFlags().BoolVar(&clientOpts.InsecureTLS, "insecure-tls", false, "Whether to accept insecure HTTPS connection")
57+
command.PersistentFlags().StringVar(&clientOpts.CaCertPaths, "caCerts", "", "Comma separated paths of CRT files to add to Root CAs")
58+
command.PersistentFlags().StringVar(&clientOpts.ClientId, "keycloakClientId", "", "Keycloak Realm Service Account ClientId")
59+
command.PersistentFlags().StringVar(&clientOpts.ClientSecret, "keycloakClientSecret", "", "Keycloak Realm Service Account ClientSecret")
60+
command.PersistentFlags().StringVar(&clientOpts.ServerAddr, "microcksURL", "", "Microcks API URL")
61+
command.MarkFlagsRequiredTogether("keycloakClientId", "microcksURL", "keycloakClientSecret")
62+
63+
return command
2164
}

0 commit comments

Comments
 (0)