Add support for alternate base url (#15)

Support the usage of an alternate base url when calling the API
This commit is contained in:
Vladimir Ritz Bossicard 2021-10-20 23:33:51 +02:00 коммит произвёл GitHub
Родитель f48d18ee8d
Коммит 36a56ed972
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 42 добавлений и 4 удалений

6
.github/workflows/linting.yml поставляемый
Просмотреть файл

@ -1,10 +1,12 @@
name: Pylint name: Linting
on: on:
push: push:
branches:
- main
pull_request: pull_request:
branches: branches:
- master - main
jobs: jobs:
build: build:

Просмотреть файл

@ -45,9 +45,32 @@ It is based on the [customerinsights](https://pypi.org/project/customerinsights)
segments : Commands to manage segments. segments : Commands to manage segments.
``` ```
1. Get help on any command with `--help`:
```bash
> aui-cli instances list --help
Command
aui-cli instances list : Lists all instances.
Arguments
Global Arguments
--debug : Increase logging verbosity to show all debug logs.
--help -h : Show this help message and exit.
--only-show-errors : Only show errors, suppressing warnings.
--output -o : Output format. Allowed values: json, jsonc, none, table, tsv, yaml, yamlc.
Default: json.
--query : JMESPath query string. See http://jmespath.org/ for more information and
examples.
--verbose : Increase logging verbosity. Use --debug for full debug logs.
```
## Configuration ## Configuration
Add the `api_key` and OAuth token in the file `~/.aui-cli/config` All configuration values are stored in the file `~/.aui-cli/config`, automatically created the first time the application is run.
In the `[autentication]` section, add your `api_key` and OAuth token:
```text ```text
[authentication] [authentication]
@ -55,6 +78,13 @@ api_key = REDACTED
token = REDACTED token = REDACTED
``` ```
An alternate base url (default is `https://api.ci.ai.dynamics.com/v1`) can be defined in the `[endpoint]` section:
```text
[endpoint]
base_url = https://api.ci.ai.dynamics-alternate.com/v1
```
## Contributing ## Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [https://cla.microsoft.com](https://cla.microsoft.com). This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [https://cla.microsoft.com](https://cla.microsoft.com).

Просмотреть файл

@ -4,15 +4,21 @@
# -------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------
from dynamics.customerinsights.api import CustomerInsights from dynamics.customerinsights.api import CustomerInsights
from knack.log import get_logger
from .config import GLOBAL_CONFIG from .config import GLOBAL_CONFIG
logger = get_logger(__name__)
def get_client(): def get_client():
""" """
Returns an authenticated CustomerInsights client. Returns an authenticated CustomerInsights client.
""" """
return CustomerInsights() base_url = GLOBAL_CONFIG.get("endpoint", "base_url", None)
if base_url:
logger.info('Using base url: %s', base_url)
return CustomerInsights(base_url)
def get_custom_headers(): def get_custom_headers():