mcm-cli 1.0.0__py3-none-any.whl → 1.1.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- {mcm_cli-1.0.0.dist-info → mcm_cli-1.1.0.dist-info}/METADATA +1 -1
- {mcm_cli-1.0.0.dist-info → mcm_cli-1.1.0.dist-info}/RECORD +10 -9
- mcmcli/__main__.py +5 -1
- mcmcli/command/admin.py +88 -0
- mcmcli/command/wallet.py +17 -7
- {mcm_cli-1.0.0.dist-info → mcm_cli-1.1.0.dist-info}/LICENSE +0 -0
- {mcm_cli-1.0.0.dist-info → mcm_cli-1.1.0.dist-info}/NOTICE +0 -0
- {mcm_cli-1.0.0.dist-info → mcm_cli-1.1.0.dist-info}/WHEEL +0 -0
- {mcm_cli-1.0.0.dist-info → mcm_cli-1.1.0.dist-info}/entry_points.txt +0 -0
- {mcm_cli-1.0.0.dist-info → mcm_cli-1.1.0.dist-info}/top_level.txt +0 -0
@@ -1,12 +1,13 @@
|
|
1
1
|
mcmcli/__init__.py,sha256=-U6lMZ9_99IXAKwnqnYXYr6NcO6TSmG-kxewgvJjU4k,575
|
2
|
-
mcmcli/__main__.py,sha256=
|
2
|
+
mcmcli/__main__.py,sha256=9eAfYXz2reT3cOAgkqgCAuk169yB8KSla_rIF4oak6E,1616
|
3
3
|
mcmcli/logging.py,sha256=xjRS5ey1ONx_d34qB1Fetb_SwPysoh2hzNDuNAaYYWQ,1739
|
4
4
|
mcmcli/requests.py,sha256=50N_LiWIWr8-3EPs_yR9f4uEQf8rQ68s_FoMYRhgjzI,2343
|
5
5
|
mcmcli/command/account.py,sha256=EtcYZsC5LL5ue-hKsZZl3_0oZ09nJdVi774yqiTykl8,14712
|
6
|
+
mcmcli/command/admin.py,sha256=nJ7rm0nm0jHPobg0PjNHIWaWURTQu6QEUEUKIo__GO0,3010
|
6
7
|
mcmcli/command/auth.py,sha256=QLdr_XFW5BVw9r4a7Kjj5BTBXpSux3AWI9eI03S8aiA,2480
|
7
8
|
mcmcli/command/config.py,sha256=sdzge-l_Yi2P_TlTgSLqShcGyPCzpW3QJzctpIvc-g4,4195
|
8
9
|
mcmcli/command/decision.py,sha256=Zjbmt71OVU-oL8Itt9O-SvwT9Lbxw-PAgRZaIgiXi-E,8411
|
9
|
-
mcmcli/command/wallet.py,sha256=
|
10
|
+
mcmcli/command/wallet.py,sha256=0MprkN5hJqJCTbMpMnFLRcLKnnc5PNYpx5Sjhys6XTY,9242
|
10
11
|
mcmcli/data/account.py,sha256=pe7tPapP6vlUD5D5L5Nh5k2bkWdYOK01Mpt5fBYFnJs,1782
|
11
12
|
mcmcli/data/account_user.py,sha256=27nQp52nMma5a3QszSJGqgq5Z0ivIb-nMZcZuhEgbEg,1328
|
12
13
|
mcmcli/data/decision.py,sha256=bQ5j_PbPRSFa0sY5g9UVqdNzl_2epchcz1lHoDVuV90,2880
|
@@ -14,10 +15,10 @@ mcmcli/data/error.py,sha256=d6xa_jTXumlA0EzXy2PJQ86ajBb0Pm90fss9R3LuHUc,1094
|
|
14
15
|
mcmcli/data/seller.py,sha256=40SA7QekM3a3svDrDYLo_QYJ68VUxDO0KeGejJMp4k4,1004
|
15
16
|
mcmcli/data/token.py,sha256=11wtyLHCAZHu0LVbNDPa-yipcL6lenxoYIKEI58VzFs,1744
|
16
17
|
mcmcli/data/wallet.py,sha256=W-CksF9SPqiv3jZg07Wy8ehVUP5Ot1Gbq2LEGNQCOC8,1906
|
17
|
-
mcm_cli-1.
|
18
|
-
mcm_cli-1.
|
19
|
-
mcm_cli-1.
|
20
|
-
mcm_cli-1.
|
21
|
-
mcm_cli-1.
|
22
|
-
mcm_cli-1.
|
23
|
-
mcm_cli-1.
|
18
|
+
mcm_cli-1.1.0.dist-info/LICENSE,sha256=RFhQPdSOiMTguUX7JSoIuTxA7HVzCbj_p8WU36HjUQQ,10947
|
19
|
+
mcm_cli-1.1.0.dist-info/METADATA,sha256=zXrJD8pf59IjAeaqxJed60ROfk6-5eFQprXggZZSqOM,3018
|
20
|
+
mcm_cli-1.1.0.dist-info/NOTICE,sha256=Ldnl2MjRaXPxcldUdbI2NTybq60XAa2LowRhFrRTuiI,76
|
21
|
+
mcm_cli-1.1.0.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
|
22
|
+
mcm_cli-1.1.0.dist-info/entry_points.txt,sha256=qTHAWZ-ejSiU4t11RYwtAU8ScqhQPDeMVTG9y4wMVLg,60
|
23
|
+
mcm_cli-1.1.0.dist-info/top_level.txt,sha256=sh7oqIaqLQlMtKHlxHHgpV2xGMrBMPFWpSp0C6nvJ_Y,7
|
24
|
+
mcm_cli-1.1.0.dist-info/RECORD,,
|
mcmcli/__main__.py
CHANGED
@@ -17,7 +17,10 @@
|
|
17
17
|
"""mcm cli entry point script."""
|
18
18
|
# mcmcli/__main__.py
|
19
19
|
|
20
|
+
from typing import Optional
|
21
|
+
|
20
22
|
import mcmcli.command.account
|
23
|
+
import mcmcli.command.admin
|
21
24
|
import mcmcli.command.auth
|
22
25
|
import mcmcli.command.config
|
23
26
|
import mcmcli.command.decision
|
@@ -32,9 +35,10 @@ def version():
|
|
32
35
|
"""
|
33
36
|
Show the tool version
|
34
37
|
"""
|
35
|
-
typer.echo(f"Version: mcm-cli v1.
|
38
|
+
typer.echo(f"Version: mcm-cli v1.1.0")
|
36
39
|
|
37
40
|
app.add_typer(mcmcli.command.account.app, name="account", help="Ad account management")
|
41
|
+
app.add_typer(mcmcli.command.admin.app, name="admin", help="Platform administration")
|
38
42
|
app.add_typer(mcmcli.command.auth.app, name="auth", help="Authentication management")
|
39
43
|
app.add_typer(mcmcli.command.config.app, name="config", help="Configurations")
|
40
44
|
app.add_typer(mcmcli.command.decision.app, name="decision", help="Decision command")
|
mcmcli/command/admin.py
ADDED
@@ -0,0 +1,88 @@
|
|
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 mcmcli.command.account
|
16
|
+
import mcmcli.command.auth
|
17
|
+
import mcmcli.command.config
|
18
|
+
import mcmcli.command.wallet
|
19
|
+
import mcmcli.requests
|
20
|
+
import sys
|
21
|
+
import typer
|
22
|
+
|
23
|
+
app = typer.Typer(add_completion=False)
|
24
|
+
|
25
|
+
def _create_admin_command(profile):
|
26
|
+
auth = mcmcli.command.auth.AuthCommand(profile)
|
27
|
+
_, error, token = auth.get_token()
|
28
|
+
if error:
|
29
|
+
print(f"ERROR: {error.message}")
|
30
|
+
return None
|
31
|
+
return AdminCommand(profile, auth, token.token)
|
32
|
+
|
33
|
+
@app.command()
|
34
|
+
def list_wallet_balances(
|
35
|
+
profile: str = typer.Option("default", help="profile name of the MCM CLI."),
|
36
|
+
):
|
37
|
+
"""
|
38
|
+
List the wallet balances of all of the ad accounts
|
39
|
+
"""
|
40
|
+
admin = _create_admin_command(profile)
|
41
|
+
if admin is None:
|
42
|
+
return
|
43
|
+
admin.list_wallet_balances()
|
44
|
+
|
45
|
+
|
46
|
+
class AdminCommand:
|
47
|
+
def __init__(
|
48
|
+
self,
|
49
|
+
profile,
|
50
|
+
auth_command: mcmcli.command.auth.AuthCommand,
|
51
|
+
token
|
52
|
+
):
|
53
|
+
self.profile = profile
|
54
|
+
self.auth_command = auth_command
|
55
|
+
self.config = mcmcli.command.config.get_config(profile)
|
56
|
+
mcmcli.command.config.assert_config_exists(self.config)
|
57
|
+
|
58
|
+
self.token = token
|
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
|
+
"Authorization": f"Bearer {token}"
|
64
|
+
}
|
65
|
+
|
66
|
+
def list_wallet_balances(
|
67
|
+
self
|
68
|
+
):
|
69
|
+
ac = mcmcli.command.account.AccountCommand(self.profile, self.auth_command, self.token)
|
70
|
+
wc = mcmcli.command.wallet.WalletCommand(self.profile, self.auth_command, self.token)
|
71
|
+
_, error, accounts = ac.list_accounts()
|
72
|
+
if error:
|
73
|
+
print(error, file=sys.stderr, flush=True)
|
74
|
+
return
|
75
|
+
|
76
|
+
print("ad_account_title, ad_account_id, credit_balance, prepaid_balance")
|
77
|
+
for id in accounts:
|
78
|
+
_, error, wallet = wc.get_balance(id, to_curl=False)
|
79
|
+
if error:
|
80
|
+
continue
|
81
|
+
w0 = wallet.accounts[0]
|
82
|
+
w1 = wallet.accounts[1]
|
83
|
+
credits = w0 if w0.type == 'CREDITS' else w1
|
84
|
+
prepaid = w1 if w1.type == 'PRE_PAID' else w0
|
85
|
+
credits = int(credits.balance.amount_micro) / 1000000
|
86
|
+
prepaid = int(prepaid.balance.amount_micro) / 1000000
|
87
|
+
print(f'"{accounts[id].title}", {id}, {credits}, {prepaid}')
|
88
|
+
|
mcmcli/command/wallet.py
CHANGED
@@ -52,7 +52,7 @@ def balance(
|
|
52
52
|
print(f"ERROR: {error.message}")
|
53
53
|
return
|
54
54
|
|
55
|
-
wc = WalletCommand(profile, token.token)
|
55
|
+
wc = WalletCommand(profile, auth, token.token)
|
56
56
|
curl, error, wallet = wc.get_balance(account_id, to_curl)
|
57
57
|
if to_curl:
|
58
58
|
print(curl)
|
@@ -97,7 +97,7 @@ def deposit(
|
|
97
97
|
print(f"ERROR: {error.message}")
|
98
98
|
return
|
99
99
|
|
100
|
-
wc = WalletCommand(profile, token.token)
|
100
|
+
wc = WalletCommand(profile, auth, token.token)
|
101
101
|
|
102
102
|
# Check the wallet first
|
103
103
|
curl, error, wallet = wc.get_balance(account_id, to_curl=False)
|
@@ -127,7 +127,7 @@ def deposit(
|
|
127
127
|
credits_amount = float(credits_amount_micro) / float(1000000)
|
128
128
|
pre_paid_amount = float(pre_paid_amount_micro) / float(1000000)
|
129
129
|
|
130
|
-
print(f"
|
130
|
+
print(f"Funds have been deposited into the wallet. The current balance for ad account ID {account_id} is {pre_paid_amount} in PRE_PAID and {credits_amount} in CREDITS.")
|
131
131
|
return
|
132
132
|
|
133
133
|
@app.command()
|
@@ -148,7 +148,7 @@ def withdraw(
|
|
148
148
|
print(f"ERROR: {error.message}")
|
149
149
|
return
|
150
150
|
|
151
|
-
wc = WalletCommand(profile, token.token)
|
151
|
+
wc = WalletCommand(profile, auth, token.token)
|
152
152
|
|
153
153
|
# Check the wallet first
|
154
154
|
curl, error, wallet = wc.get_balance(account_id, to_curl=False)
|
@@ -178,14 +178,23 @@ def withdraw(
|
|
178
178
|
credits_amount = float(credits_amount_micro) / float(1000000)
|
179
179
|
pre_paid_amount = float(pre_paid_amount_micro) / float(1000000)
|
180
180
|
|
181
|
-
print(f"
|
181
|
+
print(f"Funds were withdrawn out of the wallet. The current balance of ad account ID {account_id} is {pre_paid_amount} for PRE_PAID and {credits_amount} for CREDITS.")
|
182
182
|
return
|
183
183
|
|
184
184
|
class WalletCommand:
|
185
|
-
def __init__(
|
185
|
+
def __init__(
|
186
|
+
self,
|
187
|
+
profile,
|
188
|
+
auth_command: mcmcli.command.auth.AuthCommand,
|
189
|
+
token
|
190
|
+
):
|
186
191
|
self.config = mcmcli.command.config.get_config(profile)
|
187
|
-
|
192
|
+
if (self.config is None):
|
193
|
+
print(f"ERROR: Failed to load the CLI profile", file=sys.stderr, flush=True)
|
194
|
+
sys.exit()
|
188
195
|
|
196
|
+
self.profile = profile
|
197
|
+
self.auth_command = auth_command
|
189
198
|
self.api_base_url = f"{self.config['management_api_hostname']}/rmp/mgmt/v1/platforms/{self.config['platform_id']}"
|
190
199
|
self.headers = {
|
191
200
|
"accept": "application/json",
|
@@ -193,6 +202,7 @@ class WalletCommand:
|
|
193
202
|
"Authorization": f"Bearer {token}"
|
194
203
|
}
|
195
204
|
|
205
|
+
|
196
206
|
def get_balance(
|
197
207
|
self,
|
198
208
|
account_id: str,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|