Repository navigation
Expand file tree
/
Copy pathcreatecontext.py
More file actions
executable file
·96 lines (81 loc) · 3.35 KB
/
Copy pathcreatecontext.py
File metadata and controls
executable file
·96 lines (81 loc) · 3.35 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
92
93
94
95
96
#!/usr/bin/python3
# Copyright (C) 2022 OX Software GmbH
# Wolfgang Rosenauer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import random
import settings
import soapclient
import string
import sys
def genPasswd(length=10, chars=string.ascii_letters+string.digits):
return ''.join([random.choice(chars) for i in range(length)])
def main():
parser = argparse.ArgumentParser(
description='Creates an OX Cloud context.')
parser.add_argument("-n", dest="context_name",
required=True, help="Context name to be created.")
parser.add_argument("-e", "--email", help="Name/email (optional)")
parser.add_argument("-p", "--password",
help="Password for the user.", default=genPasswd())
parser.add_argument("-q", "--quota", default=1024,
help="Quota of the context in MiB", type=int)
parser.add_argument("-a", "--access-combination",
default="cloud_pim", help="Default access-combination")
parser.add_argument("--supportcontact",
help="Contact information for about dialog")
args = parser.parse_args()
client = soapclient.getService("OXResellerContextService")
# check if a context with that name already exists
context = client.list(
settings.getCreds()["login"] + "_" + args.context_name, settings.getCreds())
if (context):
for ctx in context:
print("Context", ctx.name, "already exists:", ctx.id)
sys.exit(1)
# create context
newContext = {
"name": settings.getCreds()["login"] + "_" + args.context_name,
"maxQuota": args.quota
}
if args.email is not None:
email = args.email
else:
email = "admin@"+args.context_name
adminUser = {
"name": email,
"password": args.password,
"display_name": "admin",
"sur_name": args.context_name,
"given_name": "admin",
"primaryEmail": email,
"email1": email
}
# we need some userAttributes, e.g. support string and dynamic theme
# in most cases meanwhile should be set on the reselleradmin
if args.supportcontact:
supportAttributes = [
{
"key": "com.openexchange.appsuite.servercontact",
"value": args.supportcontact
}
]
newContext["userAttributes"] = {"entries": [
{"key": "config", "value": {"entries": supportAttributes}}]}
context = client.createModuleAccessByName(
newContext, adminUser, args.access_combination, settings.getCreds())
print("Created context:", context.id, context.name,
"with password", args.password, "and quota", args.quota)
if __name__ == "__main__":
main()