This repository was archived by the owner on Dec 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
32 lines (27 loc) · 1.22 KB
/
common.py
File metadata and controls
32 lines (27 loc) · 1.22 KB
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
#!/usr/bin/env python
#coding=utf8
import sys
import os
import time
import ConfigParser
class Common:
@staticmethod
def LoadConfig():
cfg_fn = os.path.join(os.path.dirname(os.path.abspath(__file__)) + "\config.cfg")
required_ops = [("Base", "AccessKeyId"), ("Base", "AccessKeySecret"), ("Base", "Endpoint")]
optional_ops = [("Optional", "SecurityToken")]
parser = ConfigParser.ConfigParser()
parser.read(cfg_fn)
for sec,op in required_ops:
if not parser.has_option(sec, op):
sys.stderr.write("ERROR: need (%s, %s) in %s.\n" % (sec,op,cfg_fn))
sys.stderr.write("Read README to get help inforamtion.\n")
sys.exit(1)
accessKeyId = parser.get("Base", "AccessKeyId")
accessKeySecret = parser.get("Base", "AccessKeySecret")
endpoint = parser.get("Base", "Endpoint")
securityToken = ""
if parser.has_option("Optional", "SecurityToken") and parser.get("Optional", "SecurityToken") != "$SecurityToken":
securityToken = parser.get("Optional", "SecurityToken")
return accessKeyId,accessKeySecret,endpoint,securityToken
return accessKeyId,accessKeySecret,endpoint,""