aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/resources/scripts/sdcBePy/consumers/run.py
blob: 6f5cbe76d0f905c42aa6a01683ba56cbf8eb48bd (plain)
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
import time

from sdcBePy import properties
from sdcBePy.common.healthCheck import check_backend, get_args
from sdcBePy.common.sdcBeProxy import SdcBeProxy
from sdcBePy.consumers.models.consumerCandidateList import get_consumers
from sdcBePy.users.run import colors


def be_consumers_init(be_ip, be_port, header, protocol, tls_cert, tls_key, tls_key_pw, ca_cert, consumer_candidate_list):
    sdc_be_proxy = SdcBeProxy(be_ip, be_port, header, protocol, tls_cert, tls_key, tls_key_pw, ca_cert)
    if check_backend(sdc_be_proxy, properties.retry_attempts):
        for consumer in consumer_candidate_list:
            if sdc_be_proxy.check_user(consumer.consumer_name) != 200:
                result = sdc_be_proxy.create_consumer(*consumer.get_parameters())
                if result == 201:
                    print('[INFO]: ' + consumer.consumer_name +
                          ' created, result: [' + str(result) + ']')
                else:
                    print('[ERROR]: ' + colors.FAIL + consumer.consumer_name + colors.END_C +
                          ' error creating , result: [' + str(result) + ']')
            else:
                print('[INFO]: ' + consumer.consumer_name + ' 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 main():
    be_ip, be_port, header, protocol, tls_key, tls_cert, tls_key_pw, ca_cert = get_args()
    be_consumers_init(be_ip, be_port, header, protocol, tls_cert, tls_key, tls_key_pw, ca_cert, get_consumers())


if __name__ == '__main__':
    main()