-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathscript.py
More file actions
63 lines (48 loc) · 1.59 KB
/
script.py
File metadata and controls
63 lines (48 loc) · 1.59 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
# This file is part of the CloudBlue Connect connect-cli.
# Copyright (c) 2025 CloudBlue. All rights reserved.
import re
from typing import List
from connect.client import ConnectClient
from connect.cli.plugins.play.context import Context
class OptionWrapper:
def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
class Script:
context: Context = None
endpoint: str = None
def __init__(self, context=None, **kwargs):
self.context = context if context is not None else Context()
self.context.update(kwargs)
@classmethod
def command(cls) -> str:
return str(
re.sub(
r'^([A-Z])',
lambda x: x.group(1).lower(),
re.sub(
r'([a-z])([A-Z])',
lambda x: f'{x.group(1)}-{x.group(2).lower()}',
cls.__name__,
),
),
)
@classmethod
def help(cls) -> str:
return cls.__doc__
@classmethod
def options(cls) -> List[OptionWrapper]:
return []
def client(self, token) -> ConnectClient:
return ConnectClient(token, endpoint=self.context.endpoint, use_specs=False)
@property
def dclient(self) -> ConnectClient:
return self.client(self.context.distributor_account_token)
@property
def vclient(self) -> ConnectClient:
return self.client(self.context.vendor_account_token)
def do(self, context=None):
if context:
context.update(self.context)
self.context = context