-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathshareddomain.py
executable file
·80 lines (64 loc) · 2.86 KB
/
shareddomain.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
#!/usr/bin/python3
# Copyright (C) 2023-2024 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 requests
import settings
def main():
parser = argparse.ArgumentParser(
description='Manage OX Cloud shared domains.')
subparsers = parser.add_subparsers(title="subcommands",
description="valid subcommands",
required=True,
help="Subcommand help")
parser_create = subparsers.add_parser(
"create", help="Create a shared domain.")
parser_create.add_argument(
"-d", "--domain", help="Domain to be created as shared.", required=True)
parser_create.set_defaults(func=create)
parser_delete = subparsers.add_parser(
"delete", help="Deletes a shared domain.")
parser_delete.add_argument(
"-d", "--domain", help="Domain to be deleted", required=True)
parser_delete.set_defaults(func=delete)
parser_list = subparsers.add_parser("list", help="List shared domains")
parser_list.set_defaults(func=list)
args = parser.parse_args()
args.func(args)
def create(args):
r = requests.post(settings.getAdminRestHost()+"api/oxaas/v1/admin/sharedmaildomains/"+str(
args.domain), auth=(settings.getRestCreds()), verify=settings.getVerifyTls(), proxies=settings.getProxy())
print(r.status_code)
if r.status_code == 200:
print("Created shared domain", args.domain)
else:
print("Failed to create shared domain!")
r.raise_for_status()
def delete(args):
r = requests.delete(settings.getAdminRestHost()+"api/oxaas/v1/admin/sharedmaildomains/"+str(args.domain),
auth=(settings.getRestCreds()), verify=settings.getVerifyTls(), proxies=settings.getProxy())
if r.ok:
print("Deleted shared domain")
else:
r.raise_for_status()
def list(args):
r = requests.get(settings.getAdminRestHost()+"api/oxaas/v1/admin/sharedmaildomains/*",
auth=(settings.getRestCreds()), verify=settings.getVerifyTls(), proxies=settings.getProxy())
if r.ok:
print(r.json())
else:
r.raise_for_status()
if __name__ == "__main__":
main()