1
1
#! /usr/bin/env python
2
2
3
3
from .helper import *
4
- _env_var = os .environ
5
4
import time
5
+ import yaml
6
+ import json
7
+ from os .path import join
8
+
9
+ _env_var = os .environ
6
10
_path = get_project_folder ()
7
11
8
12
9
- def update_environment_variables ( input_dict = None ):
13
+ def get_default_env ( ):
10
14
default_dict = \
11
15
{
12
- 'ADD_APP_INFO' : 'true' ,
16
+ 'ADD_APP_INFO' : True ,
17
+ 'API_ENDPOINT' : _env_var .get ('API_ENDPOINT' ),
13
18
'EVENTS' : 'ValueMetric,CounterEvent,Error,LogMessage,HttpStartStop,ContainerMetric' ,
14
19
'SPLUNK_TOKEN' : _env_var .get ('SPLUNK_TOKEN' ),
15
20
'SPLUNK_HOST' : _env_var .get ('SPLUNK_HOST' ),
16
21
'SPLUNK_INDEX' : _env_var .get ('SPLUNK_INDEX' ),
17
22
'FIREHOSE_SUBSCRIPTION_ID' : 'splunk-ci' ,
18
23
'CLIENT_ID' : _env_var .get ('CLIENT_ID' ),
19
24
'CLIENT_SECRET' : _env_var .get ('CLIENT_SECRET' ),
20
- 'ENABLE_EVENT_TRACING' : 'true' ,
21
- 'SKIP_SSL_VALIDATION_CF' : 'true' ,
22
- 'SKIP_SSL_VALIDATION_SPLUNK' : 'true' ,
25
+ 'ENABLE_EVENT_TRACING' : True ,
26
+ 'SKIP_SSL_VALIDATION_CF' : True ,
27
+ 'SKIP_SSL_VALIDATION_SPLUNK' : True ,
23
28
'EXTRA_FIELDS' : 'name:update-ci-test'
24
29
}
30
+ config_folder = get_config_folder ()
31
+ if os .path .exists (join (config_folder , 'env.json' )):
32
+ with open (join (config_folder , 'env.json' )) as json_file :
33
+ local_env = json .load (json_file )
25
34
35
+ default_dict .update (local_env )
36
+ return default_dict
37
+
38
+
39
+ def update_environment_variables (input_dict = None ):
40
+ default_env = get_default_env ()
26
41
if input_dict :
27
- default_dict .update (input_dict )
42
+ default_env .update (input_dict )
28
43
29
44
path = os .path .join (get_project_folder (), "env.sh" )
30
45
with open (path , 'w' ) as file :
31
46
file .write ('''#! /bin/bash''' )
32
- for key , value in default_dict .items ():
47
+ for key , value in default_env .items ():
33
48
file .write ("\n export {0}={1}" .format (key , value ))
34
49
time .sleep (2 )
50
+
51
+
52
+ def update_nozzle_manifest (nozzle_name = None , instances = None , input_dict = None ):
53
+ default_env = get_default_env ()
54
+ file_name = os .path .join (_path , ".circleci/ci_nozzle_manifest.yml" )
55
+ stream = open (file_name , 'r' )
56
+ config = yaml .load (stream )
57
+ if instances :
58
+ config ['applications' ][0 ].update ({'instances' : instances })
59
+ if nozzle_name :
60
+ config ['applications' ][0 ].update ({'name' : nozzle_name })
61
+
62
+ env_var = config ['applications' ][0 ]['env' ]
63
+ env_var .update (default_env )
64
+ if input_dict :
65
+ env_var .update (input_dict )
66
+
67
+ with open (file_name , 'w' ) as yaml_file :
68
+ yaml_file .write (yaml .dump (config , default_flow_style = False ))
69
+ time .sleep (0.5 )
70
+
71
+
72
+ def update_data_gen_manifest (input_dict = None ):
73
+ file_name = os .path .join (_path , ".circleci/data_gen_manifest.yml" )
74
+ stream = open (file_name , 'r' )
75
+ config = yaml .load (stream )
76
+
77
+ env_var = config ['applications' ][0 ]
78
+ env_var .update (input_dict )
79
+
80
+ with open (file_name , 'w' ) as yaml_file :
81
+ yaml_file .write (yaml .dump (config , default_flow_style = False ))
82
+ time .sleep (0.5 )
0 commit comments