Skip to content

Commit d956305

Browse files
authored
Refactor package name (opendistro-for-elasticsearch#14)
delete odfe-cli folder inside repo and update package path accordingly.
1 parent 7033a16 commit d956305

Some content is hidden

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

68 files changed

+229
-213
lines changed

.github/workflows/odfe-cli-test-build-workflow.yml

+5-13
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,21 @@ on:
1111

1212
jobs:
1313
test:
14-
defaults:
15-
run:
16-
working-directory: odfe-cli
1714
runs-on: ubuntu-latest
1815
steps:
1916
- name: Set up Go ubuntu-latest
2017
uses: actions/setup-go@v2
2118
with:
2219
go-version: 1.14
2320

21+
- name: Install goimports
22+
run: go get golang.org/x/tools/cmd/goimports
23+
2424
- name: Check out source code
2525
uses: actions/checkout@v2
2626

2727
- name: Format check
28-
run: |
29-
cd ..
30-
go get golang.org/x/tools/cmd/goimports
31-
cd odfe-cli
32-
goimports -w .
28+
run: goimports -w .
3329

3430
- name: Check for modified files
3531
id: git-check
@@ -47,7 +43,6 @@ jobs:
4743
uses: golangci/golangci-lint-action@v1
4844
with:
4945
version: v1.28
50-
working-directory: odfe-cli
5146

5247
- name: Run Unit Tests
5348
env:
@@ -70,14 +65,11 @@ jobs:
7065
uses: codecov/codecov-action@v1.0.3
7166
with:
7267
token: ${{secrets.CODECOV_TOKEN}}
73-
file: odfe-cli/coverage.out
68+
file: coverage.out
7469
flags: odfe-cli
7570
name: codecov-umbrella
7671

7772
build:
78-
defaults:
79-
run:
80-
working-directory: odfe-cli
8173
strategy:
8274
matrix:
8375
platform: [ ubuntu-latest, macos-latest, windows-latest ]

odfe-cli/.gitignore .gitignore

File renamed without changes.

odfe-cli/Makefile Makefile

File renamed without changes.

README.md

+135-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,140 @@
1-
## ODFE Command Line Interface
1+
![Build and Test odfe-cli](https://github.com/opendistro-for-elasticsearch/odfe-cli/workflows/Build%20and%20Test%20odfe-cli/badge.svg?branch=main)
2+
[![codecov](https://codecov.io/gh/opendistro-for-elasticsearch/odfe-cli/branch/main/graph/badge.svg?flag=odfe-cli)](https://codecov.io/gh/opendistro-for-elasticsearch/odfe-cli)
3+
![PRs welcome!](https://img.shields.io/badge/PRs-welcome!-success)
4+
# ODFE Command Line Interface
5+
6+
ODFE Command Line Interface (odfe-cli) is an open source tool that lets you manage your Open Distro for Elasticsearch
7+
cluster from the command line and automate tasks. In addition to standard Elasticsearch operations, you can configure,
8+
manage, and use the ODFE plugins, such as Alerting, Anomaly Detection, and SQL
9+
10+
odfe-cli is best suited for situations in which you want to quickly combine a few commands, possibly adding them to
11+
a script for easy access or automation. This example moves a detector "ecommerce-count-qualtity" from staging
12+
to prod cluster, provided both profiles are available in config file.
13+
14+
```
15+
odfe-cli ad get ecommerce-count-qualtity --profile stg > ecommerce-count-qualtity.json
16+
odfe-cli ad create ecommerce-count-qualtity.json --profile prod
17+
odfe-cli ad start ecommerce-count-qualtity.json --profile prod
18+
odfe-cli ad stop ecommerce-count-qualtity --profile stg
19+
odfe-cli ad delete ecommerce-count-qualtity --profile stg
20+
```
21+
## Installation:
22+
23+
You can download the binaries directly from the [downloads](https://opendistro.github.io/for-elasticsearch/downloads.html) page
24+
or from the [releases](https://github.com/opendistro-for-elasticsearch/odfe-cli/releases) section.
25+
26+
27+
## Development
28+
29+
### Minimum requirements
30+
31+
odfe-cli shares [minimum requirements](https://github.com/golang/go/wiki/MinimumRequirements#minimum-requirements) as Go
32+
and [docker](https://docs.docker.com/get-docker/) to run integration tests.
33+
34+
### Build from source
35+
1. Install [Go](https://golang.org/doc/install) > = 1.14
36+
2. Clone the repository:
37+
```
38+
cd $GOPATH/src
39+
git clone git@github.com:opendistro-for-elasticsearch/odfe-cli.git
40+
```
41+
3. Run build from source directory to generate binary:
42+
```
43+
cd odfe-cli
44+
go build .
45+
```
46+
4. Make binary executable:
47+
```
48+
chmod +x ./odfe-cli
49+
```
50+
51+
### Unit Testing
52+
Go has a simple tool for running tests. To run every unit test, use this command:
53+
```
54+
go test ./...
55+
```
56+
57+
However, often when writing tests, you may want to run your new test as below
58+
```
59+
cd folder-path/to/test;
60+
go test -v -run TestName;
61+
```
62+
63+
### Integration Testing
64+
In order to test odfe-cli end-to-end, we need a running odfe cluster. We can use Docker to accomplish this.
65+
The [Docker Compose file](./docker-compose.yml) supports the ability to run integration tests for the project in local environments respectively.
66+
If you have not installed docker-compose, you can install it from this [link](https://docs.docker.com/compose/install/)
67+
68+
Integration tests are often slower, so you may want to only run them after the unit test. In order to differentiate unit tests from integration tests, Go has a built-in mechanism for allowing you to logically separate your tests
69+
with build tags. The build tag needs to be placed as close to the top of the file as possible, and must have a blank line beneath it.
70+
We recommend you to create all integration tests inside [this](./it) folder with build tag 'integration'.
71+
72+
#### Execute test integration command from your CLI
73+
1. Run docker compose to start containers, by default it will launch latest odfe version.
74+
```
75+
docker-compose up -d;
76+
```
77+
2. Run all integration tests with build tag 'integration'
78+
```
79+
go test -tags=integration ./it/...
80+
```
81+
82+
## Usage
83+
84+
```
85+
odfe-cli --help
86+
```
87+
88+
### Create default profile
89+
A profile is a collection of credentials that will be applied to the odfe-cli command. When a user specifies a profile,
90+
the settings and credentials of that profile will be used to execute the command.
91+
Users can create one profile with the name "default", and is used when no profile is explicitly referenced.
92+
93+
```
94+
$ odfe-cli profile create
95+
Enter profile's name: default
96+
Elasticsearch Endpoint: https://localhost:9200
97+
User Name: admin
98+
Password:
99+
```
100+
101+
### List existing profile
102+
103+
```
104+
$ odfe-cli profile list -l
105+
Name UserName Endpoint-url
106+
---- -------- ------------
107+
default admin https://localhost:9200
108+
prod admin https://odfe-node1:9200
109+
110+
```
111+
112+
### Using profile with odfe-cli command
113+
114+
You can specify profiles in two ways.
115+
116+
1. The first way is to add the --profile <name> option:
117+
```
118+
$ odfe-cli ad stop-detector invalid-logins --profile prod
119+
```
120+
This example stops the invalid-logins detector using the credentials and settings in the prod profile.
121+
122+
2. The second way is to use an environment variable.
123+
124+
On Linux or macOS :
125+
```
126+
$ export ODFE_PROFILE=prod
127+
```
128+
Windows
129+
```
130+
C:\> setx ODFE_PROFILE prod
131+
```
132+
These variables last for the duration of your shell session, but you can add them to .zshenv or .bash_profile
133+
for a more permanent option.
134+
2135
## Security
3136
4-
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
137+
See [CONTRIBUTING](https://github.com/opendistro-for-elasticsearch/odfe-cli/blob/main/CONTRIBUTING.md#security-issue-notifications) for more information.
5138
6139
## License
7140
File renamed without changes.

odfe-cli/client/mocks/mock_http.go client/mocks/mock_http.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
package mocks
1717

1818
import (
19-
"es-cli/odfe-cli/client"
2019
"fmt"
2120
"net/http"
21+
"odfe-cli/client"
22+
"os"
2223
)
2324

2425
// RoundTripFunc .
@@ -32,8 +33,9 @@ func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
3233
//NewTestClient returns *http.Client with Transport replaced to avoid making real calls
3334
func NewTestClient(fn RoundTripFunc) *client.Client {
3435
c, err := client.New(fn)
35-
if err == nil {
36+
if err != nil {
3637
fmt.Println("Fatal: failed to get client")
38+
os.Exit(1)
3739
}
3840
return c
3941
}

odfe-cli/commands/ad.go commands/ad.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
package commands
1717

1818
import (
19-
"es-cli/odfe-cli/client"
20-
adctrl "es-cli/odfe-cli/controller/ad"
21-
esctrl "es-cli/odfe-cli/controller/es"
22-
adgateway "es-cli/odfe-cli/gateway/ad"
23-
esgateway "es-cli/odfe-cli/gateway/es"
24-
handler "es-cli/odfe-cli/handler/ad"
2519
"fmt"
20+
"odfe-cli/client"
21+
adctrl "odfe-cli/controller/ad"
22+
esctrl "odfe-cli/controller/es"
23+
adgateway "odfe-cli/gateway/ad"
24+
esgateway "odfe-cli/gateway/es"
25+
handler "odfe-cli/handler/ad"
2626
"os"
2727

2828
"github.com/spf13/cobra"

odfe-cli/commands/ad_create.go commands/ad_create.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package commands
1717

1818
import (
19-
handler "es-cli/odfe-cli/handler/ad"
2019
"fmt"
20+
handler "odfe-cli/handler/ad"
2121

2222
"github.com/spf13/cobra"
2323
)

odfe-cli/commands/ad_delete.go commands/ad_delete.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package commands
1717

1818
import (
19-
handler "es-cli/odfe-cli/handler/ad"
2019
"fmt"
20+
handler "odfe-cli/handler/ad"
2121

2222
"github.com/spf13/cobra"
2323
)

odfe-cli/commands/ad_get.go commands/ad_get.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ package commands
1717

1818
import (
1919
"encoding/json"
20-
entity "es-cli/odfe-cli/entity/ad"
21-
"es-cli/odfe-cli/handler/ad"
2220
"fmt"
2321
"io"
22+
entity "odfe-cli/entity/ad"
23+
"odfe-cli/handler/ad"
2424
"os"
2525

2626
"github.com/spf13/cobra"

odfe-cli/commands/ad_start_stop.go commands/ad_start_stop.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package commands
1717

1818
import (
19-
"es-cli/odfe-cli/handler/ad"
2019
"fmt"
20+
"odfe-cli/handler/ad"
2121

2222
"github.com/spf13/cobra"
2323
)

odfe-cli/commands/ad_update.go commands/ad_update.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package commands
1717

1818
import (
19-
handler "es-cli/odfe-cli/handler/ad"
2019
"fmt"
20+
handler "odfe-cli/handler/ad"
2121

2222
"github.com/spf13/cobra"
2323
)

odfe-cli/commands/profile.go commands/profile.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
package commands
1717

1818
import (
19-
"es-cli/odfe-cli/controller/config"
20-
"es-cli/odfe-cli/controller/profile"
21-
"es-cli/odfe-cli/entity"
2219
"fmt"
20+
"odfe-cli/controller/config"
21+
"odfe-cli/controller/profile"
22+
"odfe-cli/entity"
2323
"os"
2424
"strings"
2525
"text/tabwriter"

odfe-cli/commands/profile_test.go commands/profile_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ package commands
1717

1818
import (
1919
"errors"
20-
"es-cli/odfe-cli/controller/profile/mocks"
21-
"es-cli/odfe-cli/entity"
2220
"fmt"
2321
"io/ioutil"
22+
"odfe-cli/controller/profile/mocks"
23+
"odfe-cli/entity"
2424
"os"
2525
"testing"
2626

File renamed without changes.
File renamed without changes.

odfe-cli/controller/ad/ad.go controller/ad/ad.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import (
1616
"context"
1717
"encoding/json"
1818
"errors"
19-
"es-cli/odfe-cli/controller/es"
20-
entity "es-cli/odfe-cli/entity/ad"
21-
"es-cli/odfe-cli/gateway/ad"
22-
"es-cli/odfe-cli/mapper"
23-
admapper "es-cli/odfe-cli/mapper/ad"
2419
"fmt"
2520
"io"
21+
"odfe-cli/controller/es"
22+
entity "odfe-cli/entity/ad"
23+
"odfe-cli/gateway/ad"
24+
"odfe-cli/mapper"
25+
admapper "odfe-cli/mapper/ad"
2626
"os"
2727
"strings"
2828

odfe-cli/controller/ad/ad_test.go controller/ad/ad_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import (
1717
"context"
1818
"encoding/json"
1919
"errors"
20-
esmockctrl "es-cli/odfe-cli/controller/es/mocks"
21-
entity "es-cli/odfe-cli/entity/ad"
22-
adgateway "es-cli/odfe-cli/gateway/ad/mocks"
23-
"es-cli/odfe-cli/mapper"
2420
"fmt"
2521
"io/ioutil"
22+
esmockctrl "odfe-cli/controller/es/mocks"
23+
entity "odfe-cli/entity/ad"
24+
adgateway "odfe-cli/gateway/ad/mocks"
25+
"odfe-cli/mapper"
2626
"os"
2727
"path/filepath"
2828
"testing"

odfe-cli/controller/ad/mocks/mock_ad.go controller/ad/mocks/mock_ad.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

odfe-cli/controller/config/config.go controller/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package config
1717

1818
import (
19-
"es-cli/odfe-cli/entity"
2019
"io/ioutil"
20+
"odfe-cli/entity"
2121
"os"
2222

2323
"gopkg.in/yaml.v3"

odfe-cli/controller/config/config_test.go controller/config/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
package config
1717

1818
import (
19-
"es-cli/odfe-cli/entity"
2019
"fmt"
2120
"io/ioutil"
21+
"odfe-cli/entity"
2222
"os"
2323
"path/filepath"
2424
"testing"

0 commit comments

Comments
 (0)