Skip to content

Commit 0ee18b0

Browse files
feat: add support for all retrievers in cli (#4025)
* add support for github retriever Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * refactor evaluate struct Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add gitlab retriever support Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * fix formatting Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add support for bitbucket retriever Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add support for s3 retriever Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * start adding support for http retriever Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add test for http retriever Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add check flag Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add test for evaluate cmd http retriever Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add more tests Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add more tests for s3 and bitbucket Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add support for gcs Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * little refactor Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add support for mongodb Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add support for azure and postgres Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * start writing docs Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add readme Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add timeout in docs Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * link redis options issue Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * add todo comment Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * little refactor Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * trailing space Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * make lint happy Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * correct readme for cli Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * correct initialization of retrievers Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * correct tests after adding init calls Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * remove json tags Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> * nolint Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> --------- Signed-off-by: deamondev <piotr.rudnicki94@protonmail.com> Co-authored-by: Thomas Poignant <thomas.poignant@gofeatureflag.org>
1 parent 1a7db09 commit 0ee18b0

File tree

21 files changed

+1501
-115
lines changed

21 files changed

+1501
-115
lines changed

cmd/cli/README.md

Lines changed: 157 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,194 @@
44

55
The GO Feature Flag Command Line is a CLI tool to interact with GO Feature Flag in your terminal.
66
For now it supports the following commands:
7+
78
- `evaluate` to evaluate feature flags directly in your terminal
89
- `lint` to validate a configuration file format.
910

1011
## How to install the cli
1112

1213
### Install using Homebrew (mac and linux)
14+
1315
```shell
1416
brew tap thomaspoignant/homebrew-tap
1517
brew install go-feature-flag-cli
1618
```
1719

1820
### Install using docker
21+
1922
```shell
2023
docker pull gofeatureflag/go-feature-flag-cli
2124
```
22-
More information about the usage of the container in the [dockerhub page](https://hub.docker.com/r/gofeatureflag/go-feature-flag-cli).
25+
26+
More information about the usage of the container in
27+
the [dockerhub page](https://hub.docker.com/r/gofeatureflag/go-feature-flag-cli).
2328

2429
# How to use the command line
2530

2631
**`go-feature-flag-cli`** is a command line tool.
2732

2833
## How to evaluate a flag
34+
35+
The evaluate command allows you to evaluate a feature flag or inspect the configuration of your retriever using
36+
`--check-mode`
37+
38+
```shell
39+
go-feature-flag-cli evaluate [OPTIONS]
40+
```
41+
42+
### Key Flags
43+
44+
| Flag | Shorthand | Description | Default |
45+
|----------------|-----------|---------------------------------------------------------------------------------------------------------------------------------|---------|
46+
| `--kind` | k | Kind of configuration source. Determines where to read your flags from | file |
47+
| `--config` | c | Path to the local flag configuration file (⚠️ deprecated, use `--path` instead) | "" |
48+
| `--format` | f | Format of your input file (YAML, JSON or TOML) | yaml |
49+
| `--flag` | | Name of the flag to evaluate | "" |
50+
| `--timeout` | | Timeout in seconds to access your configuration file | 0 |
51+
| `--ctx` | | Evaluation context as a json string | {} |
52+
| `--check-mode` | | Check only mode - when set, the command will not perform any <br/>evaluation and returns the configuration of spanned retriever | false |
53+
54+
Supported values for `--kind` are:
55+
56+
- `file`
57+
- `http`
58+
- `github`
59+
- `gitlab`
60+
- `s3`
61+
- `googleStorage`
62+
- `configmap` (kubernetes)
63+
- `mongodb`
64+
- `bitbucket`
65+
- `azureBlobStorage`
66+
- `postgresql`
67+
68+
**Caution**: We do not support `redis` retriever as for now due
69+
to: https://github.com/thomaspoignant/go-feature-flag/issues/4023.
70+
71+
### Retriever specific flags
72+
73+
The aforementioned `--kind` parameter is used to determine the retriever to use. The semantic meaning of other flags
74+
depends on that one, for
75+
example `--path` parameter is used to specify local file when `--kind` being `file` but when `--kind` being `github` it
76+
is used to specify
77+
the path to the remote file.
78+
79+
#### File
80+
81+
| Flag | Description | Default |
82+
|----------|-------------------------------------------|---------|
83+
| `--path` | Path to the local flag configuration file | "" |
84+
85+
#### HTTP
86+
87+
| Flag | Description | Default |
88+
|------------|---------------------------------------------------------------------|---------|
89+
| `--url` | URL of the remote flag configuration file | "" |
90+
| `--method` | HTTP method to access your configuration file on HTTP | GET |
91+
| `--body` | Http body to access your configuration file on HTTP | "" |
92+
| `--header` | Header to add to the request. Supported formats are `k:v` and `k=v` | "" |
93+
94+
#### GitHub
95+
96+
| Flag | Description | Default |
97+
|---------------------|-------------------------------------------------------------------------------------------------------------------|---------|
98+
| `--repository-slug` | Name of the repository | "" |
99+
| `--branch` | Git branch name | "" |
100+
| `--auth-token` | Authentication token to access your configuration file | "" |
101+
| `--github-token` | Authentication token to access your configuration file on GitHub<br/> (⚠️ deprecated, use `--auth-token` instead) | "" |
102+
| `--path` | Path to the remote flag configuration file inside github repository | "" |
103+
104+
#### GitLab
105+
106+
| Flag | Description | Default |
107+
|---------------------|---------------------------------------------------------------------|---------|
108+
| `--base-url` | Base URL of your configuration file on Gitlab | "" |
109+
| `--repository-slug` | Name of the repository | "" |
110+
| `--branch` | Git branch name | "" |
111+
| `--path` | Path to the remote flag configuration file inside gitlab repository | "" |
112+
113+
#### BitBucket
114+
115+
| Flag | Description | Default |
116+
|---------------------|------------------------------------------------------------------------|---------|
117+
| `--base-url` | Base URL of your configuration file on BitBucket | "" |
118+
| `--repository-slug` | Name of the repository | "" |
119+
| `--branch` | Git branch name | "" |
120+
| `--path` | Path to the remote flag configuration file inside bitbucket repository | "" |
121+
122+
#### S3
123+
124+
| Flag | Description | Default |
125+
|------------|--------------------|---------|
126+
| `--bucket` | Name of the bucket | "" |
127+
| `--item` | Item of the bucket | "" |
128+
129+
#### Google Storage
130+
131+
| Flag | Description | Default |
132+
|------------|----------------------|---------|
133+
| `--bucket` | Name of the bucket | "" |
134+
| `--object` | Object of the bucket | "" |
135+
136+
#### ConfigMap (Kubernetes)
137+
138+
| Flag | Description | Default |
139+
|----------------|----------------------------|-----------|
140+
| `--namespace` | Namespace of the ConfigMap | "default" |
141+
| `--config-map` | Name of the ConfigMap | "" |
142+
| `--key` | Key of the ConfigMap | "" |
143+
144+
#### MongoDB
145+
146+
| Flag | Description | Default |
147+
|----------------|-----------------------------------------------------|---------|
148+
| `--uri` | URI of your configuration file | "" |
149+
| `--database` | Database name of your configuration file on mongodb | "" |
150+
| `--collection` | Collection of your configuration file on mongodb | "" |
151+
152+
#### Azure Blob Storage
153+
154+
| Flag | Description | Default |
155+
|------------------|-----------------------------|---------|
156+
| `--account-name` | Name of the storage account | "" |
157+
| `--account-key` | Key of the storage account | "" |
158+
| `--container` | Name of the container | "" |
159+
| `--object` | Name of the object blob | "" |
160+
161+
#### PostgreSQL
162+
163+
| Flag | Description | Default |
164+
|------------|----------------------------------------------------|---------|
165+
| `--uri` | URI of your configuration file | "" |
166+
| `--table` | Table of your configuration file | "" |
167+
| `--column` | Column mapping to add. Supported format is `c1:c2` | "" |
168+
169+
As mentioned above the `--config` flag is deprecated and we encourage you to use the `--path` flag instead. For example
170+
the following command:
171+
29172
```shell
30173
go-feature-flag-cli evaluate --config="<location_of_your_flag_configuration_file>" --flag="<name_of_your_flag_to_evaluate>" --ctx='<evaluation_ctx_as_json_string>'
31174
```
32175

176+
may be replaced by:
177+
178+
```shell
179+
go-feature-flag-cli evaluate --kind="file" --path="<location_of_your_flag_configuration_file>" --flag="<name_of_your_flag_to_evaluate>" --ctx='<evaluation_ctx_as_json_string>'
180+
```
181+
33182
## How to lint a configuration file
183+
34184
```shell
35185
go-feature-flag-cli lint <location_of_your_flag_configuration_file> --format="<yaml or json or toml>"
36186
```
37187

38188
# License
39189

40-
View [license](https://github.com/thomaspoignant/go-feature-flag/blob/main/LICENSE) information for the software contained in this image.
190+
View [license](https://github.com/thomaspoignant/go-feature-flag/blob/main/LICENSE) information for the software
191+
contained in this image.
41192

42193
## How can I contribute?
43-
This project is open for contribution, see the [contributor's guide](https://github.com/thomaspoignant/go-feature-flag/blob/main/CONTRIBUTING.md) for some helpful tips.
194+
195+
This project is open for contribution, see
196+
the [contributor's guide](https://github.com/thomaspoignant/go-feature-flag/blob/main/CONTRIBUTING.md) for some helpful
197+
tips.

cmd/cli/evaluate/evaluate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
ffclient "github.com/thomaspoignant/go-feature-flag"
1010
"github.com/thomaspoignant/go-feature-flag/modules/core/model"
1111
"github.com/thomaspoignant/go-feature-flag/modules/core/utils"
12-
"github.com/thomaspoignant/go-feature-flag/retriever/fileretriever"
12+
"github.com/thomaspoignant/go-feature-flag/retriever"
1313
)
1414

1515
type evaluate struct {
16-
config string
16+
retriever retriever.Retriever
1717
fileFormat string
1818
flag string
1919
evaluationCtx string
@@ -25,7 +25,7 @@ func (e evaluate) Evaluate() (map[string]model.RawVarResult, error) {
2525
PollingInterval: 10 * time.Minute,
2626
DisableNotifierOnInit: true,
2727
Context: context.Background(),
28-
Retriever: &fileretriever.Retriever{Path: e.config},
28+
Retriever: e.retriever,
2929
FileFormat: e.fileFormat,
3030
}
3131

0 commit comments

Comments
 (0)