Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dist/
.vscode
.devcontainer

tests/reports/
coverage/
.coverage
/htmlcov/
docs/_build
Expand Down
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ jobs:
- DIST=windows
install:
- pip3 install -r requirements/dev.txt
- pip3 install -r requirements/test.txt
- pip3 install flake8 pyinstaller
script:
- flake8
- pytest
- ./package.sh
after_success:
- bash <(curl -s https://codecov.io/bash)
deploy:
- provider: pypi
skip_cleanup: true
Expand Down
82 changes: 68 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Connect Command Line Interface

![pyversions](https://img.shields.io/pypi/pyversions/connect-cli.svg) [![PyPi Status](https://img.shields.io/pypi/v/connect-cli.svg)](https://pypi.org/project/connect-cli/) [![Build Status](https://travis-ci.org/cloudblue/connect-cli.svg?branch=master)](https://travis-ci.org/cloudblue/connect-cli)
![pyversions](https://img.shields.io/pypi/pyversions/connect-cli.svg) [![PyPi Status](https://img.shields.io/pypi/v/connect-cli.svg)](https://pypi.org/project/connect-cli/) [![Build Status](https://travis-ci.org/cloudblue/connect-cli.svg?branch=master)](https://travis-ci.org/cloudblue/connect-cli) [![codecov](https://codecov.io/gh/cloudblue/connect-cli/branch/master/graph/badge.svg)](https://codecov.io/gh/cloudblue/connect-cli)


## Introduction
Expand Down Expand Up @@ -44,57 +44,111 @@ The preferred way to install `connect-cli` is using a [virtualenv](https://virtu

### Binary distributions

A single executable binary distribution is available for both linux and mac osx (amd64).
A single executable binary distribution is available for windows, linux and mac osx (amd64).
You can it from the [Github Releases](https://github.com/cloudblue/connect-cli/releases) page.

To install under linux:

```
$ curl -O -J https://github.com/cloudblue/connect-cli/releases/download/1.2/connect-cli_1.2_linux_amd64.tar.gz
$ tar xvfz connect-cli_1.2_linux_amd64.tar.gz
$ curl -O -J https://github.com/cloudblue/connect-cli/releases/download/21.0/connect-cli_21.0_linux_amd64.tar.gz
$ tar xvfz connect-cli_21.0_linux_amd64.tar.gz
$ sudo cp dist/ccli /usr/local/bin/ccli
```

To install under Mac OSX:

```
$ curl -O -J https://github.com/cloudblue/connect-cli/releases/download/1.2/connect-cli_1.2_osx_amd64.tar.gz
$ tar xvfz connect-cli_1.2_linux_amd64.tar.gz
$ curl -O -J https://github.com/cloudblue/connect-cli/releases/download/21.0/connect-cli_21.0_osx_amd64.tar.gz
$ tar xvfz connect-cli_21.0_osx_amd64.tar.gz
$ sudo cp dist/ccli /usr/local/bin/ccli
```

> If your user is not a sudoer, you can copy the `ccli` executable from the dist directory to a directory of your choice
> that is listed in the `PATH` variable.


To install under Windows

Download the windows single executable zipfile from [Github Releases](https://github.com/cloudblue/connect-cli/releases/download/21.0/connect-cli_21.0_windows_amd64.tar.gz), extract it and place it in a folder that is included in your `path` system variable.


## Usage

### Configure
### Add a new account

First of all you need to add an account the `connect-cli` with the CloudBlue Connect API *key*.

```
$ ccli account add "ApiKey XXXXX:YYYYY"
```

### List configured accounts

To get a list of all configured account run:

```
$ ccli account list
```


### Set the current active account

To set the current active account run:

```
$ ccli account activate VA-000-000
```

### Remove an account

To remove an account run:

```
$ ccli account remove VA-000-000
```

### List available products

First of all you need to configure the `connect-cli` with the CloudBlue Connect API *endpoint* and *key*.
To get a list of available products run:

```
$ ccli configure --url https://api.connect.cloudblue.com/public/v1 --key "ApiKey XXXXX:YYYYY"
$ ccli product list
```

### Dump products to Excel
This command will output a list of all products (id and name) available within the current active account.
You can also filter the results by adding the ``--query`` flag followed by a RQL query.
For more information about RQL see the [Resource Query Language](https://connect.cloudblue.com/community/api/rql/)
article in the Connect community documentation portal.

To dump products to Excel run:

### Export a product to Excel

To export a product to Excel run:

```
$ ccli product dump PRD-000-000-000 PRD-000-000-001 PRD-000-000-002 --out my_products.xlsx
$ ccli product export PRD-000-000-000
```

This command will generate a excel file named PRD-000-000-000.xlsx in the current working directory.

### Synchronize products

To sync products from Excel run:
### Synchronize a product from Excel

To synchronize a product from Excel run:

```
$ ccli product sync --in my_products.xlsx
```


### Getting help

To get help about the `connect-cli` commands type:

```
$ ccli --help
```

## License

`connect-cli` is released under the [Apache License Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).
12 changes: 9 additions & 3 deletions cnctcli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from setuptools_scm import get_version as scm_version
# -*- coding: utf-8 -*-

# This file is part of the Ingram Micro Cloud Blue Connect connect-cli.
# Copyright (c) 2019-2020 Ingram Micro. All Rights Reserved.

import pkg_resources


try:
__version__ = scm_version(root='..', relative_to=__file__)
except: # noqa: E722
__version__ = pkg_resources.require('connect-cli')[0].version
except: # noqa: E722
__version__ = '0.0.1'


Expand Down
44 changes: 44 additions & 0 deletions cnctcli/actions/accounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-

# This file is part of the Ingram Micro Cloud Blue Connect connect-cli.
# Copyright (c) 2019-2020 Ingram Micro. All Rights Reserved.

import click
import requests


def add_account(config, api_key, endpoint):
headers = {
'Authorization': api_key,
}

res = requests.get(f'{endpoint}/accounts', headers=headers)
if res.status_code == 401:
raise click.ClickException('Unauthorized: the provided api key is invalid.')

if res.status_code == 200:
account_data = res.json()[0]
account_id = account_data['id']
name = account_data['name']
config.add_account(
account_id,
name,
api_key,
endpoint,
)
config.store()
return account_id, name

raise click.ClickException(f'Unexpected error: {res.status_code} - {res.text}')


def activate_account(config, id):
config.activate(id)
config.store()
return config.active


def remove_account(config, id):
acc = config.remove_account(id)
config.store()
return acc
Loading