mcm-cli 0.45__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- mcm_cli-0.45.dist-info/LICENSE +201 -0
- mcm_cli-0.45.dist-info/METADATA +77 -0
- mcm_cli-0.45.dist-info/NOTICE +1 -0
- mcm_cli-0.45.dist-info/RECORD +17 -0
- mcm_cli-0.45.dist-info/WHEEL +5 -0
- mcm_cli-0.45.dist-info/entry_points.txt +2 -0
- mcm_cli-0.45.dist-info/top_level.txt +1 -0
- mcmcli/__init__.py +13 -0
- mcmcli/__main__.py +45 -0
- mcmcli/command/auth.py +82 -0
- mcmcli/command/config.py +120 -0
- mcmcli/command/wallet.py +259 -0
- mcmcli/data/error.py +34 -0
- mcmcli/data/token.py +64 -0
- mcmcli/data/wallet.py +69 -0
- mcmcli/logging.py +53 -0
- mcmcli/requests.py +78 -0
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
@@ -0,0 +1,77 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: mcm-cli
|
3
|
+
Version: 0.45
|
4
|
+
Summary: A command-line interface for Moloco Commerde Media
|
5
|
+
Home-page: https://github.com/moloco-mcm/mcm-cli
|
6
|
+
Author: Moloco MCM Team
|
7
|
+
Author-email: mcm-help@moloco.com
|
8
|
+
License: Apache-2.0 license
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
11
|
+
Classifier: Operating System :: OS Independent
|
12
|
+
Requires-Python: >=3.6
|
13
|
+
Description-Content-Type: text/markdown
|
14
|
+
License-File: LICENSE
|
15
|
+
License-File: NOTICE
|
16
|
+
Requires-Dist: colorama
|
17
|
+
Requires-Dist: gitpython
|
18
|
+
Requires-Dist: pydantic
|
19
|
+
Requires-Dist: pygithub
|
20
|
+
Requires-Dist: python-terraform
|
21
|
+
Requires-Dist: requests
|
22
|
+
Requires-Dist: rich
|
23
|
+
Requires-Dist: shortuuid
|
24
|
+
Requires-Dist: toml
|
25
|
+
Requires-Dist: typer
|
26
|
+
|
27
|
+
# Moloco Commerce Media (MCM) CLI utility
|
28
|
+
|
29
|
+
This tool is a command-line interface for the Moloco Commerce Media Platform, formerly known as the Retail Media Platform.
|
30
|
+
|
31
|
+
Please contact the Moloco representative for more details.
|
32
|
+
|
33
|
+
## How to install
|
34
|
+
|
35
|
+
Run the command from a terminal.
|
36
|
+
```
|
37
|
+
git clone https://github.com/moloco-mcm/mcm-cli.git && pip install mcm-cli
|
38
|
+
```
|
39
|
+
|
40
|
+
## How to upgrade
|
41
|
+
|
42
|
+
Run the command from a terminal.
|
43
|
+
```
|
44
|
+
git -C mcm-cli pull && pip install mcm-cli
|
45
|
+
```
|
46
|
+
|
47
|
+
## How to uninstall
|
48
|
+
|
49
|
+
Run the command from a terminal.
|
50
|
+
```
|
51
|
+
pip uninstall mcm-cli
|
52
|
+
```
|
53
|
+
|
54
|
+
## How to use
|
55
|
+
Run `$ mcm config init` to initialize the configuration. It saves the configuration to `~/.mcm/config.toml`.
|
56
|
+
|
57
|
+
Use `--help` option to learn more of each command.
|
58
|
+
|
59
|
+
```
|
60
|
+
$ mcm --help
|
61
|
+
|
62
|
+
Usage: mcm [OPTIONS] COMMAND [ARGS]...
|
63
|
+
|
64
|
+
╭─ Options ────────────────────────────────────────────────────────╮
|
65
|
+
│ --help Show this message and exit. │
|
66
|
+
╰──────────────────────────────────────────────────────────────────╯
|
67
|
+
╭─ Commands ───────────────────────────────────────────────────────╮
|
68
|
+
│ auth Authentication management │
|
69
|
+
│ config Configurations │
|
70
|
+
│ version │
|
71
|
+
│ wallet Wallet management │
|
72
|
+
╰──────────────────────────────────────────────────────────────────╯
|
73
|
+
|
74
|
+
$
|
75
|
+
```
|
76
|
+
|
77
|
+
© Moloco, Inc. 2023 All rights reserved. Released under Apache 2.0 License
|
@@ -0,0 +1 @@
|
|
1
|
+
© Moloco, Inc. 2023 All rights reserved. Released under Apache 2.0 License
|
@@ -0,0 +1,17 @@
|
|
1
|
+
mcmcli/__init__.py,sha256=-U6lMZ9_99IXAKwnqnYXYr6NcO6TSmG-kxewgvJjU4k,575
|
2
|
+
mcmcli/__main__.py,sha256=Mil8isMhqc3nzQyTDIfC8q3bgmM8jDHaIKtDupyj_xw,1267
|
3
|
+
mcmcli/logging.py,sha256=xjRS5ey1ONx_d34qB1Fetb_SwPysoh2hzNDuNAaYYWQ,1739
|
4
|
+
mcmcli/requests.py,sha256=50N_LiWIWr8-3EPs_yR9f4uEQf8rQ68s_FoMYRhgjzI,2343
|
5
|
+
mcmcli/command/auth.py,sha256=QLdr_XFW5BVw9r4a7Kjj5BTBXpSux3AWI9eI03S8aiA,2480
|
6
|
+
mcmcli/command/config.py,sha256=sdzge-l_Yi2P_TlTgSLqShcGyPCzpW3QJzctpIvc-g4,4195
|
7
|
+
mcmcli/command/wallet.py,sha256=TB3WrmniREsDk0ui20p3ha6OZMwA2wAJaxQ9QDGtKnA,8968
|
8
|
+
mcmcli/data/error.py,sha256=d6xa_jTXumlA0EzXy2PJQ86ajBb0Pm90fss9R3LuHUc,1094
|
9
|
+
mcmcli/data/token.py,sha256=11wtyLHCAZHu0LVbNDPa-yipcL6lenxoYIKEI58VzFs,1744
|
10
|
+
mcmcli/data/wallet.py,sha256=HvFJsRsPNRw-n_lwm6kAKlUxQbtnft97QFkHiS3StjY,1915
|
11
|
+
mcm_cli-0.45.dist-info/LICENSE,sha256=RFhQPdSOiMTguUX7JSoIuTxA7HVzCbj_p8WU36HjUQQ,10947
|
12
|
+
mcm_cli-0.45.dist-info/METADATA,sha256=4G0mNs2xqIgMeE3GkIoDDNiFxFIrl2hSrrWDFE9zkKA,2755
|
13
|
+
mcm_cli-0.45.dist-info/NOTICE,sha256=Ldnl2MjRaXPxcldUdbI2NTybq60XAa2LowRhFrRTuiI,76
|
14
|
+
mcm_cli-0.45.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
|
15
|
+
mcm_cli-0.45.dist-info/entry_points.txt,sha256=qTHAWZ-ejSiU4t11RYwtAU8ScqhQPDeMVTG9y4wMVLg,60
|
16
|
+
mcm_cli-0.45.dist-info/top_level.txt,sha256=sh7oqIaqLQlMtKHlxHHgpV2xGMrBMPFWpSp0C6nvJ_Y,7
|
17
|
+
mcm_cli-0.45.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
mcmcli
|
mcmcli/__init__.py
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Copyright 2023 Moloco, Inc
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
mcmcli/__main__.py
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Copyright 2023 Moloco, Inc
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
#!/usr/bin/env python3
|
16
|
+
|
17
|
+
"""mcm cli entry point script."""
|
18
|
+
# mcmcli/__main__.py
|
19
|
+
|
20
|
+
from typing import Optional
|
21
|
+
|
22
|
+
import mcmcli.command.auth
|
23
|
+
import mcmcli.command.config
|
24
|
+
import mcmcli.command.wallet
|
25
|
+
import mcmcli.logging
|
26
|
+
import typer
|
27
|
+
|
28
|
+
app = typer.Typer(add_completion=False)
|
29
|
+
|
30
|
+
@app.command()
|
31
|
+
def version():
|
32
|
+
"""
|
33
|
+
Show the tool version
|
34
|
+
"""
|
35
|
+
typer.echo(f"Version: mcm-cli v0.45")
|
36
|
+
|
37
|
+
app.add_typer(mcmcli.command.auth.app, name="auth", help="Authentication management")
|
38
|
+
app.add_typer(mcmcli.command.config.app, name="config", help="Configurations")
|
39
|
+
app.add_typer(mcmcli.command.wallet.app, name="wallet", help="Wallet management")
|
40
|
+
|
41
|
+
if __name__ == "__main__":
|
42
|
+
app()
|
43
|
+
|
44
|
+
def console_entry_point():
|
45
|
+
app()
|
mcmcli/command/auth.py
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Copyright 2023 Moloco, Inc
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from mcmcli.data.error import Error
|
16
|
+
from mcmcli.data.token import Token
|
17
|
+
from mcmcli.requests import CurlString, api_request
|
18
|
+
|
19
|
+
import mcmcli.command.config
|
20
|
+
import mcmcli.logging
|
21
|
+
import sys
|
22
|
+
import typer
|
23
|
+
|
24
|
+
app = typer.Typer(add_completion=False)
|
25
|
+
|
26
|
+
#
|
27
|
+
# Typer commands
|
28
|
+
#
|
29
|
+
@app.command()
|
30
|
+
def get_token(
|
31
|
+
to_curl: bool = typer.Option(False, help="Generate the curl command instead of executing it."),
|
32
|
+
to_json: bool = typer.Option(False, help="Print raw output in json"),
|
33
|
+
profile: str = "default",
|
34
|
+
):
|
35
|
+
"""
|
36
|
+
Get a new authentication token.
|
37
|
+
"""
|
38
|
+
auth = AuthCommand(profile)
|
39
|
+
curl, error, token = auth.get_token(to_curl)
|
40
|
+
|
41
|
+
if to_curl:
|
42
|
+
print(curl)
|
43
|
+
elif error:
|
44
|
+
print(f"ERROR: {error.message}")
|
45
|
+
elif to_json:
|
46
|
+
print(token.model_dump_json())
|
47
|
+
else:
|
48
|
+
print(token.token)
|
49
|
+
|
50
|
+
|
51
|
+
#
|
52
|
+
# Command executors
|
53
|
+
#
|
54
|
+
class AuthCommand:
|
55
|
+
def __init__(self, profile):
|
56
|
+
self.config = mcmcli.command.config.get_config(profile)
|
57
|
+
mcmcli.command.config.assert_config_exists(self.config)
|
58
|
+
|
59
|
+
self.api_base_url = f"{self.config['management_api_hostname']}/rmp/mgmt/v1/platforms/{self.config['platform_id']}"
|
60
|
+
self.headers = {
|
61
|
+
"accept": "application/json",
|
62
|
+
"content-type": "application/json",
|
63
|
+
}
|
64
|
+
self.payload = {
|
65
|
+
"auth_type": "CREDENTIAL",
|
66
|
+
"credential_type_payload": {
|
67
|
+
"email": self.config['admin_email'],
|
68
|
+
"password": self.config['admin_password']
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
def get_token(self, to_curl=False) -> tuple[CurlString, Error, Token]:
|
73
|
+
_api_url = f"{self.api_base_url}/tokens"
|
74
|
+
|
75
|
+
curl, error, json_obj = api_request('POST', to_curl, _api_url, self.headers, self.payload)
|
76
|
+
if curl:
|
77
|
+
return curl, None, None
|
78
|
+
if error:
|
79
|
+
return None, error, None
|
80
|
+
|
81
|
+
return None, None, Token(**json_obj)
|
82
|
+
|
mcmcli/command/config.py
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# Copyright 2023 Moloco, Inc
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from enum import Enum
|
16
|
+
from typing import Optional
|
17
|
+
|
18
|
+
import os
|
19
|
+
import sys
|
20
|
+
import toml
|
21
|
+
import typer
|
22
|
+
|
23
|
+
DEFAULT_CONFIG_DIR = os.path.expanduser('~') + "/.mcm/"
|
24
|
+
DEFAULT_CONFIG_FILE = os.path.expanduser('~') + "/.mcm/config.toml"
|
25
|
+
|
26
|
+
#
|
27
|
+
# Enum classes
|
28
|
+
#
|
29
|
+
|
30
|
+
class Profile(Enum):
|
31
|
+
default = "default"
|
32
|
+
shared = "shared"
|
33
|
+
|
34
|
+
app = typer.Typer(add_completion=False)
|
35
|
+
|
36
|
+
|
37
|
+
def get_config(profile = "default") -> Optional[dict]:
|
38
|
+
|
39
|
+
if not os.path.exists(DEFAULT_CONFIG_FILE):
|
40
|
+
return None
|
41
|
+
|
42
|
+
with open(DEFAULT_CONFIG_FILE, "r") as f:
|
43
|
+
d = toml.load(f)
|
44
|
+
|
45
|
+
if profile in d:
|
46
|
+
return d[profile]
|
47
|
+
|
48
|
+
return None
|
49
|
+
|
50
|
+
def assert_config_exists(config) -> None:
|
51
|
+
if config is None:
|
52
|
+
print(f"ERROR: the configuration file or the profile doesn't exist.")
|
53
|
+
sys.exit()
|
54
|
+
|
55
|
+
@app.command()
|
56
|
+
def init(profile: str = "default"):
|
57
|
+
"""
|
58
|
+
The tool sets up the configuration file ~/.mcm/config.toml if it does not already exist.
|
59
|
+
By default, it creates the "default" profile.
|
60
|
+
To specify a different profile name, use the --profile option.
|
61
|
+
To save your GitHub token, run the following command:
|
62
|
+
`mcm config init --profile shared`
|
63
|
+
"""
|
64
|
+
if not os.path.exists(DEFAULT_CONFIG_DIR):
|
65
|
+
# ~/.mcm directory doesn't exist. Create one.
|
66
|
+
os.mkdir(DEFAULT_CONFIG_DIR)
|
67
|
+
|
68
|
+
if not os.path.isdir(DEFAULT_CONFIG_DIR):
|
69
|
+
print("Error: A file ~/.mcm already exists. Please delete it so we tool can create ~/.mcm directory.")
|
70
|
+
sys.exit()
|
71
|
+
|
72
|
+
config = {}
|
73
|
+
if os.path.exists(DEFAULT_CONFIG_FILE):
|
74
|
+
with open(DEFAULT_CONFIG_FILE, "r") as f:
|
75
|
+
config = toml.load(f)
|
76
|
+
|
77
|
+
print(f"Creating a profile [{profile}] ...")
|
78
|
+
config[profile] = {
|
79
|
+
"platform_id": typer.prompt("Platform ID"),
|
80
|
+
"admin_email": typer.prompt("Your email address of the Campaign Manager"),
|
81
|
+
"admin_password": typer.prompt("Password of the Campaign Manager"),
|
82
|
+
"currency": typer.prompt("Currency in a three digit code like 'USD'", default="USD"),
|
83
|
+
"timezone": typer.prompt("Timezone", default="unknown"),
|
84
|
+
"decision_api_hostname": typer.prompt("Decision API hostname", default="unknown"),
|
85
|
+
"management_api_hostname": typer.prompt("Management API hostname", default="unknown"),
|
86
|
+
"event_api_hostname": typer.prompt("Event API hostname", default="unknown"),
|
87
|
+
"decision_api_key": typer.prompt("Decision API key", default="unknown"),
|
88
|
+
"decision_api_key_name": typer.prompt("Friendly name of the decision API key", default="unknown"),
|
89
|
+
"event_api_key": typer.prompt("Event API key", default="unknown"),
|
90
|
+
"event_api_key_name": typer.prompt("Friendly name of the event API key", default="unknown"),
|
91
|
+
}
|
92
|
+
print(f"The profile [{profile}] has been created.")
|
93
|
+
|
94
|
+
with open(DEFAULT_CONFIG_FILE, "w") as f:
|
95
|
+
toml.dump(config, f)
|
96
|
+
print("Configuration saved to ~/.mcm/config.toml")
|
97
|
+
|
98
|
+
@app.command()
|
99
|
+
def list(profile: str = "default"):
|
100
|
+
"""
|
101
|
+
This command lists the profile name, decision api, managmement api, event api,
|
102
|
+
decision api key, event api key, admin email and password.
|
103
|
+
It will be retrieved from the ~/.mcm/config.toml
|
104
|
+
"""
|
105
|
+
c = get_config(profile)
|
106
|
+
if c is None:
|
107
|
+
return
|
108
|
+
|
109
|
+
for k, v in c.items():
|
110
|
+
print(f"{k}: {v}")
|
111
|
+
|
112
|
+
@app.command()
|
113
|
+
def list_profiles():
|
114
|
+
"""
|
115
|
+
To list all your profile names, use the `mcm config list-profiles` command.
|
116
|
+
"""
|
117
|
+
with open(DEFAULT_CONFIG_FILE) as f:
|
118
|
+
d = toml.load(f)
|
119
|
+
for profiles in d:
|
120
|
+
print(profiles)
|
mcmcli/command/wallet.py
ADDED
@@ -0,0 +1,259 @@
|
|
1
|
+
# Copyright 2023 Moloco, Inc
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from enum import Enum
|
16
|
+
from mcmcli.data.error import Error
|
17
|
+
from mcmcli.data.wallet import Wallet, WalletsWrapper
|
18
|
+
from mcmcli.requests import CurlString, api_request
|
19
|
+
|
20
|
+
import json
|
21
|
+
import mcmcli.command.auth
|
22
|
+
import mcmcli.command.config
|
23
|
+
import mcmcli.logging
|
24
|
+
import mcmcli.requests
|
25
|
+
import shortuuid
|
26
|
+
import sys
|
27
|
+
import typer
|
28
|
+
|
29
|
+
app = typer.Typer(add_completion=False)
|
30
|
+
|
31
|
+
class FundType(Enum):
|
32
|
+
CREDITS = "CREDITS"
|
33
|
+
PRE_PAID = "PRE_PAID"
|
34
|
+
|
35
|
+
class OperationType(Enum):
|
36
|
+
DEPOSIT = "deposit"
|
37
|
+
WITHDRAW = "withdraw"
|
38
|
+
|
39
|
+
@app.command()
|
40
|
+
def balance(
|
41
|
+
account_id: str = typer.Option(help="Ad account ID"),
|
42
|
+
to_curl: bool = typer.Option(False, help="Generate the curl command instead of executing it."),
|
43
|
+
to_json: bool = typer.Option(False, help="Print raw output in json"),
|
44
|
+
profile: str = "default",
|
45
|
+
):
|
46
|
+
"""
|
47
|
+
Retrive the current balance of the given ad account's wallet.
|
48
|
+
"""
|
49
|
+
auth = mcmcli.command.auth.AuthCommand(profile)
|
50
|
+
curl, error, token = auth.get_token()
|
51
|
+
if error:
|
52
|
+
print(f"ERROR: {error.message}")
|
53
|
+
return
|
54
|
+
|
55
|
+
wc = WalletCommand(profile, token.token)
|
56
|
+
curl, error, wallet = wc.get_balance(account_id, to_curl)
|
57
|
+
if to_curl:
|
58
|
+
print(curl)
|
59
|
+
return
|
60
|
+
if error:
|
61
|
+
print(f"ERROR: {error.message}")
|
62
|
+
return
|
63
|
+
if to_json:
|
64
|
+
print(wallet.model_dump_json())
|
65
|
+
return
|
66
|
+
|
67
|
+
wa0 = wallet.accounts[0]
|
68
|
+
wa1 = wallet.accounts[1]
|
69
|
+
|
70
|
+
credits_amount_micro = wa0.balance.amount_micro if wa0.type == 'CREDITS' else wa1.balance.amount_micro
|
71
|
+
pre_paid_amount_micro = wa0.balance.amount_micro if wa0.type == 'PRE_PAID' else wa1.balance.amount_micro
|
72
|
+
credit_amount = float(credits_amount_micro) / float(1000000)
|
73
|
+
money_amount = float(pre_paid_amount_micro) / float(1000000)
|
74
|
+
|
75
|
+
print(f"Ad account ID = {account_id}")
|
76
|
+
print(f"Wallet ID = {wallet.id}")
|
77
|
+
print(f"PRE_PAID balance = {money_amount}")
|
78
|
+
print(f"CREDITS balance = {credit_amount}")
|
79
|
+
return
|
80
|
+
|
81
|
+
|
82
|
+
@app.command()
|
83
|
+
def deposit(
|
84
|
+
account_id: str = typer.Option(help="Ad account ID"),
|
85
|
+
fund_type: FundType = typer.Option(help="CREDITS or PREPAID"),
|
86
|
+
fund_amount: float = typer.Option(help="The fund amount to deposit"),
|
87
|
+
to_curl: bool = typer.Option(False, help="Generate the curl command instead of executing it."),
|
88
|
+
to_json: bool = typer.Option(False, help="Print raw output in json"),
|
89
|
+
profile: str = "default",
|
90
|
+
):
|
91
|
+
"""
|
92
|
+
Add or top up the money amount to the current balance of the given ad account's wallet.
|
93
|
+
"""
|
94
|
+
auth = mcmcli.command.auth.AuthCommand(profile)
|
95
|
+
curl, error, token = auth.get_token()
|
96
|
+
if error:
|
97
|
+
print(f"ERROR: {error.message}")
|
98
|
+
return
|
99
|
+
|
100
|
+
wc = WalletCommand(profile, token.token)
|
101
|
+
|
102
|
+
# Check the wallet first
|
103
|
+
curl, error, wallet = wc.get_balance(account_id, to_curl=False)
|
104
|
+
if curl:
|
105
|
+
print(curl)
|
106
|
+
return
|
107
|
+
if error:
|
108
|
+
print(f"ERROR: {error.message}")
|
109
|
+
return
|
110
|
+
|
111
|
+
# Deposit funds
|
112
|
+
curl, error, wallet = wc.update_balance(OperationType.DEPOSIT, account_id, wallet.id, fund_type, fund_amount, to_curl)
|
113
|
+
if curl:
|
114
|
+
print(curl)
|
115
|
+
return
|
116
|
+
if error:
|
117
|
+
print(f"ERROR: {error.message}")
|
118
|
+
return
|
119
|
+
if to_json:
|
120
|
+
print(wallet.model_dump_json())
|
121
|
+
return
|
122
|
+
|
123
|
+
wa0 = wallet.accounts[0]
|
124
|
+
wa1 = wallet.accounts[1]
|
125
|
+
credits_amount_micro = wa0.balance.amount_micro if wa0.type == 'CREDITS' else wa1.balance.amount_micro
|
126
|
+
pre_paid_amount_micro = wa0.balance.amount_micro if wa0.type == 'PRE_PAID' else wa1.balance.amount_micro
|
127
|
+
credits_amount = float(credits_amount_micro) / float(1000000)
|
128
|
+
pre_paid_amount = float(pre_paid_amount_micro) / float(1000000)
|
129
|
+
|
130
|
+
print(f"Deposited to the wallet. Currence balance of the ad account id {account_id} is {pre_paid_amount} for PRE_PAID and {credits_amount} for CREDITS.")
|
131
|
+
return
|
132
|
+
|
133
|
+
@app.command()
|
134
|
+
def withdraw(
|
135
|
+
account_id: str = typer.Option(help="Ad account ID"),
|
136
|
+
fund_type: FundType = typer.Option(help="CREDITS or PREPAID"),
|
137
|
+
fund_amount: float = typer.Option(help="The amount of credit to add"),
|
138
|
+
to_curl: bool = typer.Option(False, help="Generate the curl command instead of executing it."),
|
139
|
+
to_json: bool = typer.Option(False, help="Print raw output in json"),
|
140
|
+
profile: str = "default",
|
141
|
+
):
|
142
|
+
"""
|
143
|
+
Withdraws the money amount from the current balance of the given ad account's wallet.
|
144
|
+
"""
|
145
|
+
auth = mcmcli.command.auth.AuthCommand(profile)
|
146
|
+
curl, error, token = auth.get_token()
|
147
|
+
if error:
|
148
|
+
print(f"ERROR: {error.message}")
|
149
|
+
return
|
150
|
+
|
151
|
+
wc = WalletCommand(profile, token.token)
|
152
|
+
|
153
|
+
# Check the wallet first
|
154
|
+
curl, error, wallet = wc.get_balance(account_id, to_curl=False)
|
155
|
+
if to_curl:
|
156
|
+
print(curl)
|
157
|
+
return
|
158
|
+
if error:
|
159
|
+
print(f"ERROR: {error.message}")
|
160
|
+
return
|
161
|
+
|
162
|
+
# Withdraw funds
|
163
|
+
curl, error, wallet = wc.update_balance(OperationType.WITHDRAW, account_id, wallet.id, fund_type, fund_amount, to_curl)
|
164
|
+
if to_curl:
|
165
|
+
print(curl)
|
166
|
+
return
|
167
|
+
if error:
|
168
|
+
print(f"ERROR: {error.message}")
|
169
|
+
return
|
170
|
+
if to_json:
|
171
|
+
print(wallet.model_dump_json())
|
172
|
+
return
|
173
|
+
|
174
|
+
wa0 = wallet.accounts[0]
|
175
|
+
wa1 = wallet.accounts[1]
|
176
|
+
credits_amount_micro = wa0.balance.amount_micro if wa0.type == 'CREDITS' else wa1.balance.amount_micro
|
177
|
+
pre_paid_amount_micro = wa0.balance.amount_micro if wa0.type == 'PRE_PAID' else wa1.balance.amount_micro
|
178
|
+
credits_amount = float(credits_amount_micro) / float(1000000)
|
179
|
+
pre_paid_amount = float(pre_paid_amount_micro) / float(1000000)
|
180
|
+
|
181
|
+
print(f"Withdrew the funds from to the wallet. Currence balance of the ad account id {account_id} is {pre_paid_amount} for PRE_PAID and {credits_amount} for CREDITS.")
|
182
|
+
return
|
183
|
+
|
184
|
+
class WalletCommand:
|
185
|
+
def __init__(self, profile, token):
|
186
|
+
self.config = mcmcli.command.config.get_config(profile)
|
187
|
+
mcmcli.command.config.assert_config_exists(self.config)
|
188
|
+
|
189
|
+
self.api_base_url = f"{self.config['management_api_hostname']}/rmp/mgmt/v1/platforms/{self.config['platform_id']}"
|
190
|
+
self.headers = {
|
191
|
+
"accept": "application/json",
|
192
|
+
"content-type": "application/json",
|
193
|
+
"Authorization": f"Bearer {token}"
|
194
|
+
}
|
195
|
+
|
196
|
+
def get_balance(
|
197
|
+
self,
|
198
|
+
account_id: str,
|
199
|
+
to_curl: bool,
|
200
|
+
) -> tuple[
|
201
|
+
None | CurlString,
|
202
|
+
None | Error,
|
203
|
+
None | Wallet,
|
204
|
+
]:
|
205
|
+
_api_url = f"{self.api_base_url}/ad-accounts/{account_id}/wallets"
|
206
|
+
|
207
|
+
curl, error, json_obj = api_request('GET', to_curl, _api_url, self.headers)
|
208
|
+
if curl:
|
209
|
+
return curl, None, None
|
210
|
+
if error:
|
211
|
+
return None, error, None
|
212
|
+
|
213
|
+
wallets_wrapper = WalletsWrapper(**json_obj)
|
214
|
+
if not wallets_wrapper.wallets:
|
215
|
+
return None, Error(code=0, message="Wallet doesn't exist"), None
|
216
|
+
|
217
|
+
wallet = wallets_wrapper.wallets[0] # The MCM supports one wallet per account as of March 2024.
|
218
|
+
return None, None, wallet
|
219
|
+
|
220
|
+
def update_balance(
|
221
|
+
self,
|
222
|
+
operation_type: OperationType,
|
223
|
+
account_id: str,
|
224
|
+
wallet_id: str,
|
225
|
+
fund_type: FundType,
|
226
|
+
fund_amount: float,
|
227
|
+
to_curl: bool,
|
228
|
+
) -> tuple[
|
229
|
+
None | CurlString,
|
230
|
+
None | Error,
|
231
|
+
None | Wallet,
|
232
|
+
]:
|
233
|
+
if fund_amount <= 0:
|
234
|
+
return None, Error(code=0, message="The fund amount should be greater than zero."), None
|
235
|
+
|
236
|
+
_api_url = f"{self.api_base_url}/ad-accounts/{account_id}/wallets/{wallet_id}"
|
237
|
+
_request_id = str(shortuuid.ShortUUID().random(length=16))
|
238
|
+
if operation_type == OperationType.DEPOSIT:
|
239
|
+
_api_url += f"/top-up/{_request_id}"
|
240
|
+
else:
|
241
|
+
_api_url += f"/withdraw/{_request_id}"
|
242
|
+
|
243
|
+
_message = {
|
244
|
+
"type": fund_type.value,
|
245
|
+
"amount": {
|
246
|
+
"currency": self.config['currency'],
|
247
|
+
"amount_micro": int(fund_amount * 1000000)
|
248
|
+
}
|
249
|
+
}
|
250
|
+
_payload = { "top_up": _message } if operation_type == operation_type.DEPOSIT else { "withdraw": _message }
|
251
|
+
|
252
|
+
curl, error, json_obj = api_request('PUT', to_curl, _api_url, self.headers, _payload)
|
253
|
+
if curl:
|
254
|
+
return curl, None, None
|
255
|
+
if error:
|
256
|
+
return None, error, None
|
257
|
+
|
258
|
+
wallet = Wallet(**json_obj['wallet'])
|
259
|
+
return None, None, wallet
|
mcmcli/data/error.py
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Copyright 2023 Moloco, Inc
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from pydantic import BaseModel
|
16
|
+
|
17
|
+
#
|
18
|
+
# API error response dataclasses
|
19
|
+
#
|
20
|
+
# get-token command's example error response is as below:
|
21
|
+
#
|
22
|
+
# {
|
23
|
+
# "code": 16,
|
24
|
+
# "message": "{\"reason\":\"the given credential doesn't match with database record\",\"status\":401}\n [id:Fd35MbLKRZyTQxo3]",
|
25
|
+
# "details": [
|
26
|
+
# {
|
27
|
+
# "@type": "type.googleapis.com/api.adcloud.common.ErrorInfo",
|
28
|
+
# "category": "DEFAULT_ERROR_CATEGORY"
|
29
|
+
# }
|
30
|
+
# ]
|
31
|
+
# }
|
32
|
+
class Error(BaseModel):
|
33
|
+
code: int
|
34
|
+
message: str
|
mcmcli/data/token.py
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Copyright 2023 Moloco, Inc
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from pydantic import BaseModel
|
16
|
+
|
17
|
+
#
|
18
|
+
# API response dataclasses
|
19
|
+
#
|
20
|
+
# get-token command's example response is as below:
|
21
|
+
#
|
22
|
+
# {
|
23
|
+
# 'token': 'eyJhbGciOiJpD4',
|
24
|
+
# 'expires_at': '2024-03-09T19:57:46Z',
|
25
|
+
# 'user': {
|
26
|
+
# 'id': 'QFrrnyjtf2bGtHDLgbno',
|
27
|
+
# 'email': 'user@example.com',
|
28
|
+
# 'name': 'Ada Lovelace',
|
29
|
+
# 'roles': [
|
30
|
+
# {
|
31
|
+
# 'name': 'PLATFORM_STAFF',
|
32
|
+
# 'resource_type': 'PLATFORM',
|
33
|
+
# 'resource_id': 'MYPLATFORM_TEST'
|
34
|
+
# },
|
35
|
+
# {
|
36
|
+
# 'name': 'PLATFORM_USER',
|
37
|
+
# 'resource_type': 'PLATFORM',
|
38
|
+
# 'resource_id': 'MYPLATFORM_TEST'
|
39
|
+
# }
|
40
|
+
# ],
|
41
|
+
# 'status': 'NOT_REGISTERED',
|
42
|
+
# 'created_at': '2023-10-28T16:38:47Z',
|
43
|
+
# 'updated_at': '2023-12-12T21:27:41Z'
|
44
|
+
# }
|
45
|
+
# }
|
46
|
+
#
|
47
|
+
class Role(BaseModel):
|
48
|
+
name: str
|
49
|
+
resource_type: str
|
50
|
+
resource_id: str
|
51
|
+
|
52
|
+
class User(BaseModel):
|
53
|
+
id: str
|
54
|
+
email: str
|
55
|
+
name: str
|
56
|
+
roles: list[Role]
|
57
|
+
status: str
|
58
|
+
created_at: str
|
59
|
+
updated_at: str
|
60
|
+
|
61
|
+
class Token(BaseModel):
|
62
|
+
token: str
|
63
|
+
expires_at: str
|
64
|
+
user: User
|
mcmcli/data/wallet.py
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Copyright 2023 Moloco, Inc
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from pydantic import BaseModel
|
16
|
+
|
17
|
+
#
|
18
|
+
# API response dataclasses
|
19
|
+
#
|
20
|
+
# The balance command's example response is as below:
|
21
|
+
#
|
22
|
+
# {
|
23
|
+
# "wallets": [
|
24
|
+
# {
|
25
|
+
# "id": "TjNwMMlONkaMqNyn",
|
26
|
+
# "title": "",
|
27
|
+
# "ad_account_id": "side_bar_1-ME",
|
28
|
+
# "type": "PRE_PAYMENT",
|
29
|
+
# "accounts": [
|
30
|
+
# {
|
31
|
+
# "type": "CREDITS",
|
32
|
+
# "balance": {
|
33
|
+
# "currency": "USD",
|
34
|
+
# "amount_micro": "1000000"
|
35
|
+
# }
|
36
|
+
# },
|
37
|
+
# {
|
38
|
+
# "type": "PRE_PAID",
|
39
|
+
# "balance": {
|
40
|
+
# "currency": "USD",
|
41
|
+
# "amount_micro": "1002011000000"
|
42
|
+
# }
|
43
|
+
# }
|
44
|
+
# ],
|
45
|
+
# "created_at": "2024-02-29T21:24:21.743177Z",
|
46
|
+
# "updated_at": "2024-03-04T16:41:25.717512Z"
|
47
|
+
# }
|
48
|
+
# ]
|
49
|
+
# }
|
50
|
+
|
51
|
+
class MicroPrice(BaseModel):
|
52
|
+
currency: str
|
53
|
+
amount_micro: str
|
54
|
+
|
55
|
+
class WalletAccount(BaseModel):
|
56
|
+
type: str
|
57
|
+
balance: MicroPrice
|
58
|
+
|
59
|
+
class Wallet(BaseModel):
|
60
|
+
id: str
|
61
|
+
title: str
|
62
|
+
ad_account_id: str
|
63
|
+
type: str
|
64
|
+
accounts: list[WalletAccount]
|
65
|
+
created_at: str
|
66
|
+
updated_at: str
|
67
|
+
|
68
|
+
class WalletsWrapper(BaseModel):
|
69
|
+
wallets: list[Wallet]
|
mcmcli/logging.py
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright 2023 Moloco, Inc
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
import sys
|
16
|
+
import threading
|
17
|
+
import time
|
18
|
+
import typer
|
19
|
+
|
20
|
+
def print_error(api_url, message):
|
21
|
+
# Something's wrong. Print error and exit.
|
22
|
+
|
23
|
+
_msg = typer.style(f"\nERROR: {message}", fg=typer.colors.RED, bold=True)
|
24
|
+
typer.echo(_msg, file=sys.stderr)
|
25
|
+
|
26
|
+
_msg = typer.style(f"URL = {api_url}", fg=typer.colors.YELLOW, bold=True)
|
27
|
+
typer.echo(_msg, file=sys.stderr)
|
28
|
+
|
29
|
+
friendly_message = "Check if you used the accurate values of the API hostname, Platform ID, and Ad Account ID."
|
30
|
+
_msg = typer.style(friendly_message, fg=typer.colors.WHITE, bold=True)
|
31
|
+
typer.echo(_msg, file=sys.stderr)
|
32
|
+
|
33
|
+
def _print_dot(stopper):
|
34
|
+
while not stopper.is_set():
|
35
|
+
print(".", file=sys.stderr, end="", flush=True)
|
36
|
+
time.sleep(1)
|
37
|
+
|
38
|
+
def start_dot_printing():
|
39
|
+
stopper = threading.Event()
|
40
|
+
thread = threading.Thread(target=_print_dot, args=[stopper])
|
41
|
+
thread.setDaemon(True)
|
42
|
+
thread.start()
|
43
|
+
return (thread, stopper)
|
44
|
+
|
45
|
+
def stop_dot_printing(thread, stopper):
|
46
|
+
stopper.set()
|
47
|
+
thread.join()
|
48
|
+
|
49
|
+
def echo(message):
|
50
|
+
print(message, file=sys.stderr, end="", flush=True)
|
51
|
+
|
52
|
+
def echo_newline(message):
|
53
|
+
print(message, file=sys.stderr, flush=True)
|
mcmcli/requests.py
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Copyright 2023 Moloco, Inc
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
from mcmcli.data.error import Error
|
16
|
+
|
17
|
+
import json
|
18
|
+
import requests
|
19
|
+
import sys
|
20
|
+
|
21
|
+
CurlString = str
|
22
|
+
|
23
|
+
def to_curl_str(method, api_base_url, headers, payload = None):
|
24
|
+
c = f"""curl --request {method} \\
|
25
|
+
--url {api_base_url} \\
|
26
|
+
"""
|
27
|
+
for k in headers:
|
28
|
+
c = c + f" --header '{k}: {headers[k]}' \\\n"
|
29
|
+
if payload is None:
|
30
|
+
c = c + "\n"
|
31
|
+
else:
|
32
|
+
c = c + f" --data '\n"
|
33
|
+
c = c + json.dumps(payload, indent=4)
|
34
|
+
c = c + f"\n'"
|
35
|
+
return c
|
36
|
+
|
37
|
+
def get(url, headers):
|
38
|
+
try:
|
39
|
+
res = requests.get(url, headers=headers)
|
40
|
+
return None, json.loads(res.text)
|
41
|
+
except Exception as e:
|
42
|
+
return e, None
|
43
|
+
|
44
|
+
def post(url, headers, payload):
|
45
|
+
try:
|
46
|
+
res = requests.post(url, headers=headers, json=payload)
|
47
|
+
return None, json.loads(res.text)
|
48
|
+
except Exception as e:
|
49
|
+
return e, None
|
50
|
+
|
51
|
+
def put(url, headers, payload):
|
52
|
+
try:
|
53
|
+
res = requests.put(url, headers=headers, json=payload)
|
54
|
+
return None, json.loads(res.text)
|
55
|
+
except Exception as e:
|
56
|
+
return e, None
|
57
|
+
|
58
|
+
def api_request(method, to_curl, url, headers, payload=None) -> tuple[CurlString, Error, dict]:
|
59
|
+
if to_curl:
|
60
|
+
curl = to_curl_str(method, url, headers, payload)
|
61
|
+
return curl, None, None
|
62
|
+
|
63
|
+
if method == 'GET':
|
64
|
+
error, json_obj = get(url, headers)
|
65
|
+
elif method == 'POST':
|
66
|
+
error, json_obj = post(url, headers, payload)
|
67
|
+
elif method == 'PUT':
|
68
|
+
error, json_obj = put(url, headers, payload)
|
69
|
+
else:
|
70
|
+
return None, Error(code=0, message="Unsupported HTTP method"), None
|
71
|
+
|
72
|
+
if error:
|
73
|
+
return None, Error(code=0, message=str(error)), None
|
74
|
+
if 'code' in json_obj:
|
75
|
+
return None, Error(**json_obj), None
|
76
|
+
|
77
|
+
return None, None, json_obj
|
78
|
+
|