19 cfsp user (load | show) [-c CFGFILE]
22 load Load credentials from a file
23 show Show the credentials of a file
26 -c --config CFGFILE Specify the configfile that rsnapshot should use
27 [default: ./user.json]
29 from docopt
import docopt
40 """A user in the cloudFPGA world"""
52 s =
"username={0}&password={1}&project_name={2}".format(self.
usernameusername, self.
passwordpassword, self.
projectproject)
53 return requests.utils.requote_uri(s)
55 s =
"username={0}&password={1}".format(self.
usernameusername, self.
passwordpassword)
56 return requests.utils.requote_uri(s)
60 This method should be used if the cloudFPGA quota name that should be used for this handle is different from the
61 default or credentials file
65 self.
projectproject = new_project
68 print(
"File : " + self.
CFGFILECFGFILE)
69 print(
"User : " + self.
usernameusername)
70 print(
"Password : " + self.
passwordpassword)
71 print(
"Project : " + self.
projectproject)
76 if (len(args[
'<args>']) != 1):
77 print(
"ERROR: invalid arguments provided in 'cfsp user' command. Aborting...")
80 if args[
'<args>'][0] ==
'load':
81 if (len(args[
'<args>']) == 1):
82 user=
cFuser(args[
'--config'])
84 print(
"ERROR: invalid arguments provided in cfsp user load. Aborting...")
86 if args[
'--username'] !=
'username_example':
87 cfsp_globals.__cfsp_username__ = user.username = args[
'--username']
89 cfsp_globals.__cfsp_username__ = user.username
90 if args[
'--password'] !=
'password_example':
91 cfsp_globals.__cfsp_password__ = user.password = args[
'--password']
93 cfsp_globals.__cfsp_password__ = user.password
94 if args[
'--project'] !=
'project_example':
95 cfsp_globals.__cfsp_project__ = user.project = args[
'--project']
97 cfsp_globals.__cfsp_project__ = user.project
99 elif args[
'<args>'][0] ==
'show':
100 if (len(args[
'<args>']) == 1):
103 print(
"ERROR: invalid arguments provided in cfsp user show. Aborting...")
106 exit(print(
"ERROR: invalid command provided in cfsp user. Type 'cfsp help user' to get a list of supported commands. Aborting..."))
109 """returns username, password, and project from a JSON file"""
115 if os.path.exists(json_file):
116 with open(json_file,
'r')
as infile:
117 data = json.load(infile)
118 username = data[
'credentials'][
'username']
119 password = data[
'credentials'][
'password']
120 if 'project' in data:
121 project = data[
'project']
123 project = cfsp_globals.__openstack_user_template__[
'project']
125 print(
"INFO: Creating new user credentials file : {}\n".format(os.path.abspath(json_file)))
127 except Exception
as e:
129 return username, password, project
133 """writes credentials to a JSON file"""
134 __cfsp_template__ = {}
135 __cfsp_template__[
'credentials'] = {}
136 __cfsp_template__[
'credentials'][
'username'] = cfsp_globals.__cfsp_username__
137 __cfsp_template__[
'credentials'][
'password'] = cfsp_globals.__cfsp_password__
138 __cfsp_template__[
'project'] = cfsp_globals.__cfsp_project__
140 with open(json_file,
'w')
as outfile:
141 json.dump(__cfsp_template__, outfile)
142 except Exception
as e:
147 with open(json_file,
'r')
as infile:
148 data = json.load(infile)
149 username = data[
'credentials'][
'username']
150 password = data[
'credentials'][
'password']
151 if 'project' in data:
152 project = data[
'project']
154 project = cfsp_globals.__openstack_user_template__[
'project']
155 print(
"User : " + username)
156 print(
"Password : " + password)
157 print(
"Project : " + project)
159 except Exception
as e:
161 print(
"No credentials file found : "+ json_file)
167 if __name__ ==
'__main__':
def get_auth_string(self, with_project=False)
def print_credentials(self)
def set_project(self, new_project)
def __init__(self, CFGFILE)
def load_user_credentials(json_file)
def write_user_credentials(json_file)
def print_user_credentials_from_file(json_file)