summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/resources/scripts/sdcBePy/users
diff options
context:
space:
mode:
authork.kedron <k.kedron@partner.samsung.com>2020-03-05 13:12:27 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-06-24 06:01:11 +0000
commitcb30f3a566b73c78c3ea666acfcd3f288098684a (patch)
tree38cd1acb83ddde2b927485611d130bbeec3c1a4b /catalog-be/src/main/resources/scripts/sdcBePy/users
parentbdbfc2e460ccb561c3e174260b2908b974996d4f (diff)
Refactoring the sdc-BE-init python scripts
Deeper refactoring of python script: - create the python package with init script - support for python 3.x - reuse code - new design - support for .json conf file - update the docker chef script Issue-ID: SDC-2784 Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com> Change-Id: I02169eb7d0e3e90851ba1811536d1712c3b4145f
Diffstat (limited to 'catalog-be/src/main/resources/scripts/sdcBePy/users')
-rwxr-xr-xcatalog-be/src/main/resources/scripts/sdcBePy/users/__init__.py0
-rwxr-xr-xcatalog-be/src/main/resources/scripts/sdcBePy/users/data/users.json44
-rwxr-xr-xcatalog-be/src/main/resources/scripts/sdcBePy/users/run.py64
3 files changed, 108 insertions, 0 deletions
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/users/__init__.py b/catalog-be/src/main/resources/scripts/sdcBePy/users/__init__.py
new file mode 100755
index 0000000000..e69de29bb2
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/users/__init__.py
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/users/data/users.json b/catalog-be/src/main/resources/scripts/sdcBePy/users/data/users.json
new file mode 100755
index 0000000000..9ce2be4dd3
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/users/data/users.json
@@ -0,0 +1,44 @@
+[
+ {
+ "userId": "demo",
+ "firstName": "demo",
+ "lastName": "demo",
+ "role": "ADMIN",
+ "email": "demo@openecomp.org"
+ },
+ {
+ "userId": "op0001",
+ "firstName": "Oper",
+ "lastName": "P",
+ "role": "OPS",
+ "email": "op0001@openecomp.org"
+ },
+ {
+ "userId": "gv0001",
+ "firstName": "Giuseppe",
+ "lastName": "Verdi",
+ "role": "GOVERNOR",
+ "email": "gv0001@openecomp.org"
+ },
+ {
+ "userId": "jh0003",
+ "firstName": "Jimmy",
+ "lastName": "Hendrix",
+ "role": "Admin",
+ "email": "jh0003@openecomp.org"
+ },
+ {
+ "userId": "jm0007",
+ "firstName": "Joni",
+ "lastName": "Mitchell",
+ "role": "TESTER",
+ "email": "jm0007@openecomp.org"
+ },
+ {
+ "userId": "cs0008",
+ "firstName": "Carlos",
+ "lastName": "Santana",
+ "role": "DESIGNER",
+ "email": "cs0008r@openecomp.org"
+ }
+] \ No newline at end of file
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/users/run.py b/catalog-be/src/main/resources/scripts/sdcBePy/users/run.py
new file mode 100755
index 0000000000..b933afe7ca
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/users/run.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+
+import json
+import os
+import time
+from argparse import ArgumentParser
+
+from sdcBePy.common.bColors import BColors
+from sdcBePy.common.healthCheck import check_backend, RETRY_ATTEMPTS
+from sdcBePy.common.sdcBeProxy import SdcBeProxy
+
+colors = BColors()
+
+
+def load_users(conf_path):
+ with open(conf_path, 'r') as f:
+ return json.load(f)
+
+
+def be_user_init(be_ip, be_port, protocol, conf_path):
+ sdc_be_proxy = SdcBeProxy(be_ip, be_port, protocol)
+ if check_backend(sdc_be_proxy, RETRY_ATTEMPTS):
+ users = load_users(conf_path)
+ for user in users:
+ if sdc_be_proxy.check_user(user['userId']) != 200:
+ result = sdc_be_proxy.create_user(user['firstName'],
+ user['lastName'],
+ user['userId'],
+ user['email'],
+ user['role'])
+ if result == 201:
+ print('[INFO]: ' + user['userId'] +
+ ' created, result: [' + str(result) + ']')
+ else:
+ print('[ERROR]: ' + colors.FAIL + user['userId'] + colors.END_C +
+ ' error creating , result: [' + str(result) + ']')
+ else:
+ print('[INFO]: ' + user['userId'] + ' already exists')
+ else:
+ print('[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + colors.FAIL
+ + 'Backend is DOWN :-(' + colors.END_C)
+ raise Exception("Cannot communicate with the backend!")
+
+
+def get_args():
+ parser = ArgumentParser()
+
+ parser.add_argument('-i', '--ip', required=True)
+ parser.add_argument('-p', '--port', required=True)
+ parser.add_argument('--https', action='store_true')
+ path = os.path.dirname(__file__)
+ parser.add_argument('--conf', default=os.path.join(path, 'data', 'users.json'))
+
+ args = parser.parse_args()
+
+ return [args.ip, args.port, 'https' if args.https else 'http', args.conf]
+
+
+def main():
+ be_user_init(*get_args())
+
+
+if __name__ == "__main__":
+ main()