-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathhelpers.py
More file actions
47 lines (37 loc) · 1.18 KB
/
helpers.py
File metadata and controls
47 lines (37 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
# This file is part of the CloudBlue Connect connect-cli.
# Copyright (c) 2025 CloudBlue. All rights reserved.
import click
from connect.client import ClientError, ConnectClient
from connect.cli.core.http import RequestLogger
def add_account(config, api_key, endpoint):
try:
client = ConnectClient(
api_key=api_key,
endpoint=endpoint,
validate_using_specs=False,
use_specs=False,
logger=RequestLogger(),
)
account_data = client.accounts.all().first()
config.add_account(
account_data['id'],
account_data['name'],
api_key,
endpoint,
)
config.store()
return account_data['id'], account_data['name']
except ClientError as h:
msg = f'Unexpected error: {h}'
if h.status_code == 401:
msg = 'Unauthorized: the provided api key is invalid.'
raise click.ClickException(msg)
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