File size: 1,717 Bytes
5120311
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import requests
import json
import os
from yaml import load
try:
    from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
    from yaml import Loader, Dumper


URL_CFG = "http://icomm-api-configserver/api/configserver/v1/configuration.yaml"
# http://10.9.2.151:31244/api/configserver/v1/configuration.yaml
# cấu hình file hosts ở thư mục C:\Windows\System32\drivers\etc như sau:
# 123.31.42.17 icomm-api-configserver

AccessToken = "wbecrEfJk8F36y0WojqBQaqT28d6NaBnCLBgkoO2sCg3aNhYACkSxMNvWwlsAj5k"
Environment = "Production"
path_save_cfg = "config/cfg.yaml"


def get_config():
    cfg = None
    try:
        payload = json.dumps({
            "AccessToken": AccessToken,
            "Environment": Environment
        })
        headers = {
            'accept': 'text/plain',
            'Content-Type': 'application/json-patch+json'
        }

        response = requests.request("POST", URL_CFG, headers=headers, data=payload)
        # if response.status_code == 200:
        #     with open(path_save_cfg, "w+") as f:
        #         f.write(response.text)
    except Exception as ve:
        print(ve)
    if os.path.exists(path_save_cfg):
        with open(path_save_cfg) as f:
            cfg = load(f, Loader)
    return cfg


def parse_connection_string(str_cnn):
    res = dict()
    split_dt = str_cnn.split(";")
    for c_sp in split_dt:
        k, v = c_sp.split("=")
        res[k.strip()] = v.replace("'", "").replace('"', '')
    return res


if __name__ == '__main__':
    cf = get_config()
    print(cf)
    print(parse_connection_string(cf["ConfigManager"]["ConnectionStrings"]["facebook_info"]["Value"]))