Skip to content

Commit 0495f3d

Browse files
authored
Merge pull request #3 from menuka94/master
[3.0.0] Import Export CLI - PR 3
2 parents cc5edf2 + dacd113 commit 0495f3d

Some content is hidden

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

55 files changed

+1778
-631
lines changed

.gitignore

+18-12
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,42 @@ hs_err_pid*
2828
*.iml
2929

3030
vendor
31-
import-export-cli/vendor
32-
33-
# Keep a sample API for testing
34-
!import-export-cli/exported/sampleapi.zip
3531

3632
# IDEs
3733
.idea/
3834
.settings
3935
.vscode/
4036

41-
42-
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
43-
import-export-cli/.glide/
4437
*.tar.gz
4538
*.rar
4639

4740
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
4841
hs_err_pid*
4942

50-
# YAML Config Files
51-
import-export-cli/env_endpoints_all.yaml
52-
import-export-cli/env_keys_all.yaml
43+
44+
# Import Export CLI
45+
# =================
5346

5447
# Binaries
48+
import-export-cli/apimcli
5549
import-export-cli/import-export-cli
56-
import-export-cli/wso2apim-cli
50+
import-export-cli/build/
51+
52+
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
53+
import-export-cli/.glide/
5754

55+
import-export-cli/vendor
5856

59-
# Test Coverage Indicators
57+
# Keep a sample API for testing
58+
!import-export-cli/cmd/sampleapi.zip
6059

60+
# YAML Config Files
61+
import-export-cli/env_endpoints_all.yaml
62+
import-export-cli/env_keys_all.yaml
63+
64+
# Test Coverage Indicators
6165
import-export-cli/utils/c.out
6266
import-export-cli/utils/coverage.out
6367
import-export-cli/utils/coverage.html
68+
69+
# ==================

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
# product-apim-tooling
1+
# product-apim-tooling
2+
3+
4+
### 1. [Import Export CLI](https://github.com/wso2/product-apim-tooling/tree/master/import-export-cli)

import-export-cli/CONTRIBUTING.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Contributing
2+
3+
Follow the following steps to make a contribution to this tool.
4+
5+
* [Install Go (1.8.x) locally](https://golang.org/doc/install)
6+
* [Setup `$GOPATH` and `$GOROOT`](https://www.goinggo.net/2016/05/installing-go-and-your-workspace.html)
7+
* [Install Glide - Go Dependency Manager](https://github.com/Masterminds/glide#install)
8+
* Fork the respository: [wso2/product-apim-tooling](https://github.com/wso2/product-apim-tooling)
9+
* Do `git clone https://github.com/<your-username>/product-apim-tooling`
10+
11+
NOTE: Project should be cloned such that the location would be `$GOPATH/src/github.com/wso2/product-apim-tooling` (This is mandatory for Go's dependencies to identity each other)
12+
* `cd` into `product-apim-tooling/import-export-cli`
13+
* Execute `glide install` inside `product-apim-tooling/import-export-cli` to download all dependencies
14+
* Make changes to the code
15+
* Commit to your fork
16+
* Send a pull request to [wso2/product-apim-tooling](https://github.com/wso2/product-apim-tooling)

import-export-cli/README.md

+87-27
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,50 @@
11
# CLI for Importing and Exporting APIs
2-
## WSO2 API Manager 3.0.0
2+
## For WSO2 API Manager 3.0.0
33

4-
#### Usage
4+
Command Line tool for importing and exporting APIs between different API Environemnts
5+
6+
## Getting Started
7+
8+
- ### Setting up the development environment
9+
1. Install [Go 1.8.x](https://golang.org/dl)
10+
2. Setup `$GOROOT` and `$GOPATH` correctly : [Tutorial](https://www.goinggo.net/2016/05/installing-go-and-your-workspace.html)
11+
3. [Install Glide](https://github.com/Masterminds/glide#install) - The Dependency manager for Go
12+
4. Clone the [repository](https://github.com/wso2/product-apim-tooling) to your `$GOPATH` such that the project location is `$GOPATH/src/github.com/wso2/product-apim-tooling` (This is mandatory for Go's dependencies to identify each other)
13+
5. `cd` into `product-apim-tooling/import-export-cli`
14+
6. Execute `glide install` to download all the dependencies
15+
16+
- ### Building
17+
`cd` into `product-apim-tooling/import-export-cli`
18+
19+
Execute `./build.sh -t apimcli.go -v 1.0.0 -f` to build for all platforms.
20+
21+
Created packages will be available at `build/target` directory
22+
23+
- ### Running
24+
Extract the compressed archive generated to a desired location.
25+
26+
Then execute `import-export-cli/apimcli` to start the application.
27+
28+
Execute `import-export-cli/apimcli --help` for further instructions.
29+
30+
- ### Adding Environments
31+
Add environments by either manually editing `import-export-cli/bin/main_config.yaml` or using the command
32+
`apimcli set` command.
33+
34+
Type `apimcli set --help` for detailed instructions
35+
36+
### Command Autocompletion (For Bash Only)
37+
Copy the file `apimcli_bash_completion.sh` to `/etc/bash_completion.d/` and source it with
38+
`source /etc/bash_completion.d/apimcli_bash_completion.sh` to enable bash auto-completion.
39+
40+
<hr/>
41+
<br/>
42+
43+
## Usage
544
```bash
6-
wso2apim [command]
45+
apimcli [command]
746
```
47+
848
### Commands
949
* #### export-api
1050
```bash
@@ -17,10 +57,10 @@
1757
--username, -u
1858
--password, -p
1959
Examples:
20-
wso2apim export-api -n TestAPI -v 1.0.1 -e staging
21-
wso2apim export-api -n TestAPI -v 1.0.1 -e staging -u admin -p 123456
22-
wso2apim export-api -n TestAPI -v 1.0.1 -e staging -u admin
23-
wso2apim export-api -n TestAPI -v 1.0.1 -e staging -p 123456
60+
apimcli export-api -n TestAPI -v 1.0.1 -e staging
61+
apimcli export-api -n TestAPI -v 1.0.1 -e staging -u admin -p 123456
62+
apimcli export-api -n TestAPI -v 1.0.1 -e staging -u admin
63+
apimcli export-api -n TestAPI -v 1.0.1 -e staging -p 123456
2464
```
2565

2666

@@ -29,19 +69,19 @@
2969
```bash
3070
Flags:
3171
Required:
32-
--name, -n
72+
--file, -f
3373
--environment, -e
3474
Optional:
3575
--username, -u
3676
--password, -p
3777
Examples:
38-
wso2apim import-api -n TestAPI.zip -e dev
39-
wso2apim import-api -n TestAPI.zip -e dev -u admin -p 123456
40-
wso2apim import-api -n TestAPI.zip -e dev -u admin
41-
wso2apim import-api -n TestAPI.zip -e dev -p 123456
42-
wso2apim import-api -n TestAPI -e dev
78+
apimcli import-api -f dev/TestAPI_1.0.0.zip -e dev
79+
apimcli import-api -f qa/TestAPI_1.2.1.zip -e dev -u admin -p 123456
80+
apimcli import-api -f staging/TestAPI_2.1.3.zip -e dev -u admin
81+
apimcli import-api -f production/TestAPI_3.1.0.zip -e dev -p 123456
82+
apimcli import-api -f TestAPI_1.2.1.zip -e dev
4383
```
44-
* #### list
84+
* #### list apis
4585
```bash
4686
Flags:
4787
Required:
@@ -50,22 +90,31 @@
5090
--username, -u
5191
--password, -p
5292
Examples:
53-
wso2apim list -e dev
54-
wso2apim list -e staging
55-
wso2apim list -e staging -u admin -p 123456
56-
wso2apim list -e staging -u admin
57-
wso2apim list -e staging -p 123456
93+
apimcli list -e dev
94+
apimcli list -e staging
95+
apimcli list -e staging -u admin -p 123456
96+
apimcli list -e staging -u admin
97+
apimcli list -e staging -p 123456
5898
```
99+
100+
* #### list envs
101+
```bash
102+
Flags:
103+
None
104+
Example:
105+
apimcli list envs
106+
```
107+
59108
* #### add-env
60109
```bash
61110
Flags:
62111
Required:
63112
--name, -n (Name of the environment)
64-
--apim (API Manager endpoint)
65-
--registration (Registration Endpoint)
66-
--token (Token Endpoint)
113+
--publisher, -p (Publisher endpoint)
114+
--registration, -r (Registration Endpoint)
115+
--token, -t (Token Endpoint)
67116
Examples:
68-
wso2apim add-env -n dev \
117+
apimcli add-env -n dev \
69118
--apim https://localhost:9292/api/am/publisher/v1.0 \
70119
--registration https://localhost:9443/identity/connect/register \
71120
--token https: https://localhost:9443/oauth2/token
@@ -76,24 +125,35 @@
76125
Required:
77126
--name, -n (Name of the environment)
78127
Examples:
79-
wso2apim remove-env -n dev
128+
apimcli remove-env -n dev
80129

81130
```
82131

83132
* #### reset-user
84133
```bash
85134
Flags
86135
--environment, -e
87-
Example:
88-
wso2paim reset-user -e dev
136+
Examples:
137+
apimcli reset-user -e dev
89138
```
90139
* #### version
91140
```bash
92-
wso2apim version
141+
apimcli version
93142
```
143+
144+
* #### set
145+
```bash
146+
Flags
147+
--httpRequestTimeout
148+
--exportDirectory
149+
Examples:
150+
apimcli set --httpRequestTimeout 10000
151+
apimcli set --exportDirectory /home/user/exported
152+
```
94153
95154
#### Global Flags
96155
```bash
97156
--verbose
157+
--insecure, -k
98158
--help, -h
99159
```

import-export-cli/apimcli.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3+
*
4+
* WSO2 Inc. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package main
20+
21+
import (
22+
"github.com/wso2/product-apim-tooling/import-export-cli/cmd"
23+
)
24+
25+
func main() {
26+
cmd.Execute()
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# copy this file to /etc/bash_completion.d/ and source it to enable bash completion
2+
_apimcli()
3+
{
4+
local current previous options base
5+
COMPREPLY=()
6+
current="${COMP_WORDS[COMP_CWORD]}"
7+
previous="${COMP_WORDS[COMP_CWORD-1]}"
8+
9+
options="export-api import-api list add-env remove-env reset-user version author"
10+
11+
case "${previous}" in
12+
export-api)
13+
local flags="--name -n --version -v --environment -e --help -h"
14+
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
15+
return 0
16+
;;
17+
import-api)
18+
local flags="--name -n --environment -e --help -h"
19+
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
20+
return 0
21+
;;
22+
list)
23+
local flags="apis envs"
24+
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
25+
return 0
26+
;;
27+
add-env)
28+
local flags="--name -n --publisher --registration --token --help -h"
29+
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
30+
return 0
31+
;;
32+
remove-env)
33+
local flags="--name -n --help -h"
34+
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
35+
return 0
36+
;;
37+
reset-user)
38+
local flags="--environment -e --help -h"
39+
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
40+
return 0
41+
;;
42+
set)
43+
local flags="--export-directory --http-request-timeout"
44+
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
45+
return 0
46+
;;
47+
version)
48+
return 0
49+
;;
50+
author)
51+
return 0
52+
;;
53+
*)
54+
;;
55+
56+
esac
57+
58+
COMPREPLY=($(compgen -W "${options}" -- ${current}))
59+
return 0
60+
}
61+
62+
complete -F _apimcli apimcli
63+
complete -F _apimcli ./apimcli
64+
complete -F _apimcli import-export-cli
65+
complete -F _apimcli ./import-export-cli

import-export-cli/bash_completion.sh

-15
This file was deleted.

import-export-cli/bash_completions.go

-1
This file was deleted.

0 commit comments

Comments
 (0)