-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathstore-publish.py
More file actions
91 lines (69 loc) · 3.17 KB
/
store-publish.py
File metadata and controls
91 lines (69 loc) · 3.17 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import json
import os
import sys
from urllib.request import urlopen, Request
DIRECTORY_ID = os.environ["MSSTORE_TENANT_ID"]
CLIENT_ID = os.environ["MSSTORE_CLIENT_ID"]
CLIENT_SECRET = os.environ["MSSTORE_CLIENT_SECRET"]
SELLER_ID = os.environ["MSSTORE_SELLER_ID"]
APP_ID = os.environ["MSSTORE_APP_ID"]
PATCH_JSON = os.environ["PATCH_JSON"]
with open(PATCH_JSON, "rb") as f:
patch_data = json.load(f)
SERVICE_URL = "https://manage.devcenter.microsoft.com/v1.0/my/"
################################################################################
# Get auth token/header
################################################################################
OAUTH_URL = f"https://login.microsoftonline.com/{DIRECTORY_ID}/oauth2/v2.0/token"
SERVICE_SCOPE = "https://manage.devcenter.microsoft.com/.default"
reqAuth = Request(
OAUTH_URL,
method="POST",
headers={"Content-Type": "application/x-www-form-urlencoded"},
data=(f"grant_type=client_credentials&client_id={CLIENT_ID}&" +
f"client_secret={CLIENT_SECRET}&scope={SERVICE_SCOPE}").encode("utf-8"),
)
with urlopen(reqAuth) as r:
jwt = json.loads(r.read())
auth = {"Authorization": f"Bearer {jwt['access_token']}"}
################################################################################
# Get application data (for current submission)
################################################################################
reqApps = Request(f"{SERVICE_URL}applications/{APP_ID}", method="GET", headers=auth)
print("Getting application data from", reqApps.full_url)
with urlopen(reqApps) as r:
app_data = json.loads(r.read())
submission_url = app_data["pendingApplicationSubmission"]["resourceLocation"]
################################################################################
# Get current submission data
################################################################################
reqSubmission = Request(f"{SERVICE_URL}{submission_url}", method="GET", headers=auth)
print("Getting submission data from", reqSubmission.full_url)
with urlopen(reqSubmission) as r:
sub_data = json.loads(r.read())
################################################################################
# Patch submission data
################################################################################
if patch_data:
def _patch(target, key, src):
if key.startswith("#"):
return
if isinstance(src, dict):
for k, v in src.items():
_patch(target.setdefault(key, {}), k, v)
else:
target[key] = src
for k, v in patch_data.items():
_patch(sub_data, k, v)
################################################################################
# Update submission data
################################################################################
reqUpdate = Request(f"{SERVICE_URL}{submission_url}", method="PUT",
headers={**auth, "Content-Type": "application/json; charset=utf-8"},
data=json.dumps(sub_data).encode("utf-8"))
print("Updating submission data at", reqUpdate.full_url)
with urlopen(reqUpdate) as r:
new_data = r.read()
new_data.pop("fileUploadUrl", None)
print("Current submission metadata:")
print(json.dumps(new_data, indent=2))