-
Notifications
You must be signed in to change notification settings - Fork 6
/
ideclr.py
executable file
·248 lines (212 loc) · 6.06 KB
/
ideclr.py
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env python3
import argparse
import uuid
import sys
import json
# closure which generates a function that returns a simple DDM declaration
def make_simple_wrap(decl_type):
def make_simple(args):
nonlocal decl_type
return {
"Type": decl_type,
"Payload": {},
}
return make_simple
def make_activation(args):
decl = {
"Type": "com.apple.activation.simple",
"Payload": {
"StandardConfigurations": args.declaration,
},
}
if hasattr(args, "predicate") and args.predicate:
decl["Payload"]["Predicate"] = args.predicate
return decl
def make_subscription(args):
decl = {
"Type": "com.apple.configuration.management.status-subscriptions",
"Payload": {
"StatusItems": [{"Name": x} for x in args.item],
},
}
return decl
def make_profile_wrap(decl_type="com.apple.configuration.legacy"):
def make_profile(args):
payload = {
"ProfileURL": args.url,
}
if decl_type == "com.apple.configuration.legacy.interactive":
payload["VisibleName"] = args.visiblename
decl = {
"Type": decl_type,
"Payload": payload,
}
return decl
return make_profile
def make_org(args):
payload = {
"Name": args.name,
}
if hasattr(args, "email") and args.email:
payload["Email"] = args.email
if hasattr(args, "url") and args.url:
payload["URL"] = args.url
if hasattr(args, "identitytoken") and args.identitytoken:
payload["Proof"] = {"IdentityToken": args.identitytoken}
return {
"Type": "com.apple.management.organization-info",
"Payload": payload,
}
def make_test(args):
payload = {
"Echo": args.echo,
}
if hasattr(args, "returnstatus") and args.returnstatus:
payload["ReturnStatus"] = args.returnstatus
return {
"Type": "com.apple.configuration.management.test",
"Payload": payload,
}
def make_test_subp(parent_parser):
decl_type = "com.apple.configuration.management.test"
p = parent_parser.add_parser("test", help=decl_type + " DDM declaration")
p.add_argument(
"echo",
type=str,
help="echo string",
)
p.add_argument(
"-r",
"--returnstatus",
type=str,
help="email address",
)
p.set_defaults(func=make_test)
return p
def make_org_subp(parent_parser):
decl_type = "com.apple.management.organization-info"
p = parent_parser.add_parser("org-info", help=decl_type + " DDM declaration")
p.add_argument(
"name",
type=str,
help="name of organization",
)
p.add_argument(
"-e",
"--email",
type=str,
help="email address",
)
p.add_argument(
"-u",
"--url",
type=str,
help="URL of the organization",
)
p.add_argument(
"-t",
"--identitytoken",
type=str,
help="Organization verification identity token",
)
p.set_defaults(func=make_org)
return p
def make_profile_subp(parent_parser):
decl_type = "com.apple.configuration.legacy"
p = parent_parser.add_parser("profile", help=decl_type + " DDM declaration")
p.add_argument(
"url",
type=str,
help="URL of profile",
)
p.set_defaults(func=make_profile_wrap(decl_type))
return p
def make_iprofile_subp(parent_parser):
decl_type = "com.apple.configuration.legacy.interactive"
p = parent_parser.add_parser("iprofile", help=decl_type + " DDM declaration")
p.add_argument(
"url",
type=str,
help="URL of profile",
)
p.add_argument(
"visiblename",
type=str,
help="Visible name of configuration.",
)
p.set_defaults(func=make_profile_wrap(decl_type))
return p
def make_subscription_subp(parent_parser):
decl_type = "com.apple.configuration.management.status-subscriptions"
p = parent_parser.add_parser("subscription", help=decl_type + " DDM declaration")
p.add_argument(
"item",
nargs="+",
type=str,
help="status item to subscribe to",
)
p.set_defaults(func=make_subscription)
return p
def make_activation_subp(parent_parser):
decl_type = "com.apple.activation.simple"
p = parent_parser.add_parser("activation", help=decl_type + " DDM declaration")
p.add_argument(
"-p",
"--predicate",
type=str,
help="activation predicate",
)
p.add_argument(
"declaration",
nargs="+",
type=str,
help="declaration to activate",
)
p.set_defaults(func=make_activation)
return p
def make_simple_decl_subp(simple_name, decl_type, parent_parser):
p = parent_parser.add_parser(
simple_name,
help=decl_type + " DDM declaration",
)
p.set_defaults(func=make_simple_wrap(decl_type))
return p
def main():
p = argparse.ArgumentParser(description="DDM declaration generator")
p.add_argument(
"-i",
"--identifier",
type=str,
default=str(uuid.uuid4()),
help="declaration identifier (auto-generated UUID if not specified)",
)
p.add_argument(
"-t",
"--token",
type=str,
help="declaration ServerToken",
)
subps = p.add_subparsers(
title="DDM declarations",
help="supported DDM declarations",
)
make_simple_decl_subp("properties", "com.apple.management.properties", subps)
make_activation_subp(subps)
make_subscription_subp(subps)
make_profile_subp(subps)
make_iprofile_subp(subps)
make_org_subp(subps)
make_test_subp(subps)
args = p.parse_args()
# command and random are mutually exclusive
if not hasattr(args, "func"):
p.print_help()
sys.exit(2)
d = args.func(args)
d["Identifier"] = args.identifier
if hasattr(args, "token") and args.token:
d["ServerToken"] = args.token
json.dump(d, sys.stdout, indent=4)
print()
if __name__ == "__main__":
main()