Commit afaca326 authored by Diego Molteni's avatar Diego Molteni
Browse files

update init for default command

parent dc87039d
Pipeline #44062 passed with stage
in 23 seconds
......@@ -45,7 +45,10 @@ def main():
cmd = import_from('sdlib.cmd.%s.cmd' % cmd_name.lower(),
cmd_name.capitalize())
auth_provider = AuthFactory.build(Config.get_auth_provider(), keyword_args.idtoken)
if cmd_name != "config":
auth_provider = AuthFactory.build(Config.get_auth_provider(), keyword_args.idtoken)
else:
auth_provider = None
cmd(auth_provider).execute(positional_args, keyword_args)
except Exception as ex: # pylint: disable=W0703
......
......@@ -59,22 +59,24 @@ class Config(SDUtilCMD):
command(args)
def init(self, args):
# set the cloud provider
idx_to_env = {str(idx+1): env
for idx, env in enumerate(Configuration.get_service_configurations().keys())}
print()
for idx, env in enumerate(Configuration.get_service_configurations().keys()):
print("[" + str(idx + 1) + "] " + env)
print("\nSelect the cloud provider: ", end='')
sys.stdout.flush()
idx = sys.stdin.readline()
try:
idx = int(idx)
except Exception:
raise Exception("\nInvalid choice.")
if idx < 1 or idx > len(Configuration.get_service_configurations().keys()):
raise Exception("\nInvalid choice.")
if len(Configuration.get_service_configurations().keys()) > 1:
print()
for idx, env in enumerate(Configuration.get_service_configurations().keys()):
print("[" + str(idx + 1) + "] " + env)
print("\nSelect the cloud provider: ", end='')
sys.stdout.flush()
idx = sys.stdin.readline()
try:
idx = int(idx)
except Exception:
raise Exception("\nInvalid choice.")
if idx < 1 or idx > len(Configuration.get_service_configurations().keys()):
raise Exception("\nInvalid choice.")
else:
idx=1
provider = idx_to_env[str(idx)]
provider_envs = Configuration.get_service_configurations()[provider]
......
......@@ -60,16 +60,16 @@ class Config(object):
# check if the auth provider implement exist
auth_provider_name = list(cls.__configuration['auth_provider'].keys())[0]
if not os.path.isdir(os.path.join(*[os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "auth", "providers", auth_provider_name])):
if auth_provider_name == 'default':
raise Exception("\nNo auth provider has been found. Please re-run the command with the extra argument --idtoken=\"user-access-credential\"")
else:
raise Exception("\nThe auth provider \""+auth_provider_name+"\" implementation has not been found.");
if len([i for i in sys.argv if i.startswith('--idtoken') or i == 'config']) == 0:
if auth_provider_name == 'default':
raise Exception("\nNo auth provider has been found. Please re-run the command with the extra argument --idtoken=\"user-access-credential\"")
else:
raise Exception("\nThe auth provider \""+auth_provider_name+"\" implementation has not been found.");
# load configurations as json
cls.__configuration['seistore']['service'] = json.loads(cls.__configuration['seistore']['service'])
cls.__configuration['auth_provider'][auth_provider_name] = json.loads(cls.__configuration['auth_provider'][auth_provider_name])
@classmethod
def load_user_config(cls, forced_configuration=None):
''' Load configuration'''
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment