Skip to content

Commit

Permalink
Merge pull request #3 from menuka94/master
Browse files Browse the repository at this point in the history
[3.0.0] Import Export CLI - PR 3
  • Loading branch information
nuwand authored Nov 24, 2017
2 parents cc5edf2 + dacd113 commit 0495f3d
Show file tree
Hide file tree
Showing 55 changed files with 1,778 additions and 631 deletions.
30 changes: 18 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,42 @@ hs_err_pid*
*.iml

vendor
import-export-cli/vendor

# Keep a sample API for testing
!import-export-cli/exported/sampleapi.zip

# IDEs
.idea/
.settings
.vscode/


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

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

# YAML Config Files
import-export-cli/env_endpoints_all.yaml
import-export-cli/env_keys_all.yaml

# Import Export CLI
# =================

# Binaries
import-export-cli/apimcli
import-export-cli/import-export-cli
import-export-cli/wso2apim-cli
import-export-cli/build/

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
import-export-cli/.glide/

import-export-cli/vendor

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

# YAML Config Files
import-export-cli/env_endpoints_all.yaml
import-export-cli/env_keys_all.yaml

# Test Coverage Indicators
import-export-cli/utils/c.out
import-export-cli/utils/coverage.out
import-export-cli/utils/coverage.html

# ==================
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# product-apim-tooling
# product-apim-tooling


### 1. [Import Export CLI](https://github.com/wso2/product-apim-tooling/tree/master/import-export-cli)
16 changes: 16 additions & 0 deletions import-export-cli/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Contributing

Follow the following steps to make a contribution to this tool.

* [Install Go (1.8.x) locally](https://golang.org/doc/install)
* [Setup `$GOPATH` and `$GOROOT`](https://www.goinggo.net/2016/05/installing-go-and-your-workspace.html)
* [Install Glide - Go Dependency Manager](https://github.com/Masterminds/glide#install)
* Fork the respository: [wso2/product-apim-tooling](https://github.com/wso2/product-apim-tooling)
* Do `git clone https://github.com/<your-username>/product-apim-tooling`

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)
* `cd` into `product-apim-tooling/import-export-cli`
* Execute `glide install` inside `product-apim-tooling/import-export-cli` to download all dependencies
* Make changes to the code
* Commit to your fork
* Send a pull request to [wso2/product-apim-tooling](https://github.com/wso2/product-apim-tooling)
114 changes: 87 additions & 27 deletions import-export-cli/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,50 @@
# CLI for Importing and Exporting APIs
## WSO2 API Manager 3.0.0
## For WSO2 API Manager 3.0.0

#### Usage
Command Line tool for importing and exporting APIs between different API Environemnts

## Getting Started

- ### Setting up the development environment
1. Install [Go 1.8.x](https://golang.org/dl)
2. Setup `$GOROOT` and `$GOPATH` correctly : [Tutorial](https://www.goinggo.net/2016/05/installing-go-and-your-workspace.html)
3. [Install Glide](https://github.com/Masterminds/glide#install) - The Dependency manager for Go
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)
5. `cd` into `product-apim-tooling/import-export-cli`
6. Execute `glide install` to download all the dependencies

- ### Building
`cd` into `product-apim-tooling/import-export-cli`

Execute `./build.sh -t apimcli.go -v 1.0.0 -f` to build for all platforms.

Created packages will be available at `build/target` directory

- ### Running
Extract the compressed archive generated to a desired location.

Then execute `import-export-cli/apimcli` to start the application.

Execute `import-export-cli/apimcli --help` for further instructions.

- ### Adding Environments
Add environments by either manually editing `import-export-cli/bin/main_config.yaml` or using the command
`apimcli set` command.

Type `apimcli set --help` for detailed instructions

### Command Autocompletion (For Bash Only)
Copy the file `apimcli_bash_completion.sh` to `/etc/bash_completion.d/` and source it with
`source /etc/bash_completion.d/apimcli_bash_completion.sh` to enable bash auto-completion.

<hr/>
<br/>

## Usage
```bash
wso2apim [command]
apimcli [command]
```

### Commands
* #### export-api
```bash
Expand All @@ -17,10 +57,10 @@
--username, -u
--password, -p
Examples:
wso2apim export-api -n TestAPI -v 1.0.1 -e staging
wso2apim export-api -n TestAPI -v 1.0.1 -e staging -u admin -p 123456
wso2apim export-api -n TestAPI -v 1.0.1 -e staging -u admin
wso2apim export-api -n TestAPI -v 1.0.1 -e staging -p 123456
apimcli export-api -n TestAPI -v 1.0.1 -e staging
apimcli export-api -n TestAPI -v 1.0.1 -e staging -u admin -p 123456
apimcli export-api -n TestAPI -v 1.0.1 -e staging -u admin
apimcli export-api -n TestAPI -v 1.0.1 -e staging -p 123456
```


Expand All @@ -29,19 +69,19 @@
```bash
Flags:
Required:
--name, -n
--file, -f
--environment, -e
Optional:
--username, -u
--password, -p
Examples:
wso2apim import-api -n TestAPI.zip -e dev
wso2apim import-api -n TestAPI.zip -e dev -u admin -p 123456
wso2apim import-api -n TestAPI.zip -e dev -u admin
wso2apim import-api -n TestAPI.zip -e dev -p 123456
wso2apim import-api -n TestAPI -e dev
apimcli import-api -f dev/TestAPI_1.0.0.zip -e dev
apimcli import-api -f qa/TestAPI_1.2.1.zip -e dev -u admin -p 123456
apimcli import-api -f staging/TestAPI_2.1.3.zip -e dev -u admin
apimcli import-api -f production/TestAPI_3.1.0.zip -e dev -p 123456
apimcli import-api -f TestAPI_1.2.1.zip -e dev
```
* #### list
* #### list apis
```bash
Flags:
Required:
Expand All @@ -50,22 +90,31 @@
--username, -u
--password, -p
Examples:
wso2apim list -e dev
wso2apim list -e staging
wso2apim list -e staging -u admin -p 123456
wso2apim list -e staging -u admin
wso2apim list -e staging -p 123456
apimcli list -e dev
apimcli list -e staging
apimcli list -e staging -u admin -p 123456
apimcli list -e staging -u admin
apimcli list -e staging -p 123456
```

* #### list envs
```bash
Flags:
None
Example:
apimcli list envs
```

* #### add-env
```bash
Flags:
Required:
--name, -n (Name of the environment)
--apim (API Manager endpoint)
--registration (Registration Endpoint)
--token (Token Endpoint)
--publisher, -p (Publisher endpoint)
--registration, -r (Registration Endpoint)
--token, -t (Token Endpoint)
Examples:
wso2apim add-env -n dev \
apimcli add-env -n dev \
--apim https://localhost:9292/api/am/publisher/v1.0 \
--registration https://localhost:9443/identity/connect/register \
--token https: https://localhost:9443/oauth2/token
Expand All @@ -76,24 +125,35 @@
Required:
--name, -n (Name of the environment)
Examples:
wso2apim remove-env -n dev
apimcli remove-env -n dev

```

* #### reset-user
```bash
Flags
--environment, -e
Example:
wso2paim reset-user -e dev
Examples:
apimcli reset-user -e dev
```
* #### version
```bash
wso2apim version
apimcli version
```

* #### set
```bash
Flags
--httpRequestTimeout
--exportDirectory
Examples:
apimcli set --httpRequestTimeout 10000
apimcli set --exportDirectory /home/user/exported
```
#### Global Flags
```bash
--verbose
--insecure, -k
--help, -h
```
27 changes: 27 additions & 0 deletions import-export-cli/apimcli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package main

import (
"github.com/wso2/product-apim-tooling/import-export-cli/cmd"
)

func main() {
cmd.Execute()
}
65 changes: 65 additions & 0 deletions import-export-cli/apimcli_bash_completion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# copy this file to /etc/bash_completion.d/ and source it to enable bash completion
_apimcli()
{
local current previous options base
COMPREPLY=()
current="${COMP_WORDS[COMP_CWORD]}"
previous="${COMP_WORDS[COMP_CWORD-1]}"

options="export-api import-api list add-env remove-env reset-user version author"

case "${previous}" in
export-api)
local flags="--name -n --version -v --environment -e --help -h"
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
return 0
;;
import-api)
local flags="--name -n --environment -e --help -h"
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
return 0
;;
list)
local flags="apis envs"
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
return 0
;;
add-env)
local flags="--name -n --publisher --registration --token --help -h"
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
return 0
;;
remove-env)
local flags="--name -n --help -h"
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
return 0
;;
reset-user)
local flags="--environment -e --help -h"
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
return 0
;;
set)
local flags="--export-directory --http-request-timeout"
COMPREPLY=( $(compgen -W "${flags}" -- ${current}) )
return 0
;;
version)
return 0
;;
author)
return 0
;;
*)
;;

esac

COMPREPLY=($(compgen -W "${options}" -- ${current}))
return 0
}

complete -F _apimcli apimcli
complete -F _apimcli ./apimcli
complete -F _apimcli import-export-cli
complete -F _apimcli ./import-export-cli
15 changes: 0 additions & 15 deletions import-export-cli/bash_completion.sh

This file was deleted.

1 change: 0 additions & 1 deletion import-export-cli/bash_completions.go

This file was deleted.

Loading

0 comments on commit 0495f3d

Please sign in to comment.