Пример #1
0
def status_cmd(ctx):
    stackn_config, load_status = get_stackn_config()
    if not load_status:
        print('Failed to load STACKn config.')
    else:
        print('Context: '+stackn_config['active'])
        if 'active_project' in stackn_config:
            print('Project: '+stackn_config['active_project'])
        else:
            print('No active project; create a new project or set an existing project.')
Пример #2
0
def login_cmd(ctx, secure):
    stackn_config, load_status = get_stackn_config(secure=secure)
    if not load_status:
        print('Failed to load STACKn config.')
        return

    remote_config, load_status = get_remote_config()
    if remote_config:
        login(deployment=stackn_config['active'],
              keycloak_host=remote_config['keycloak_url'],
              studio_host=remote_config['studio_url'])
Пример #3
0
    def __init__(self, config=None):
        self.found_project = False

        self.stackn_config, load_status = sauth.get_stackn_config()
        if not load_status:
            print('Failed to load stackn config')

        self.project = []
        self.project_slug = []
        active_dir = self.stackn_config['active']
        if 'active_project' in self.stackn_config:
            project_dir = os.path.expanduser('~/.scaleout/' + active_dir +
                                             '/projects')
            self.project, load_status = load_from_file(
                self.stackn_config['active_project'], project_dir)
            if load_status:
                self.found_project = True
                self.project_slug = self.project['slug']
                # else:
                #     print('Could not load project config for '+self.stackn_config['active_project'])
            else:
                print('You must set an active valid project.')

        self.secure_mode = True
        if 'secure' in self.stackn_config:
            self.secure_mode = self.stackn_config['secure']
        if self.secure_mode == False:
            print("WARNING: Running in insecure mode.")
            import urllib3
            urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

        # self.project = self.get_projects({'slug': self.project_slug})
        if not self.project:
            print('Did not find active project in config')
            self.project_id = -1
        else:
            self.project_id = self.project['id']
            self.project_slug = self.project['slug']

        self.access_token, self.token_config = sauth.get_token(
            secure=self.secure_mode)
        if self.token_config['studio_url'][-1] == '/':
            self.token_config['studio_url'] = self.token_config[
                'studio_url'][:-1]
        self.api_url = urljoin(self.token_config['studio_url'], '/api')
        self.auth_headers = {
            'Authorization': 'Token {}'.format(self.access_token)
        }
        # Fetch and set all active API endpoints
        self.get_endpoints()
Пример #4
0
def remote_cmd(ctx, remote):
    if not remote:
        remote = input('Remote: ')
    stackn_config, load_status = sauth.get_stackn_config()
    if not load_status:
        print('Failed to load STACKn config.')
    else:
        dirpath = os.path.expanduser('~/.scaleout/' + remote)
        if not os.path.exists(dirpath):
            print("Remote doesn't exist.")
            print("Configure remote with 'stackn setup'")
        else:
            stackn_config['active'] = remote
            sauth.write_stackn_config(stackn_config)
            print('New context: ' + remote)
Пример #5
0
 def set_project(self, project_name):
     # Set active project
     stackn_config, load_status = sauth.get_stackn_config()
     if not load_status:
         print('Failed to load STACKn config.')
         return False
     active_dir = stackn_config['active']
     project_dir = os.path.expanduser('~/.scaleout/' + active_dir +
                                      '/projects')
     proj_path = project_dir + '/' + project_name + '.json'
     # Update STACKN config
     stackn_config['active_project'] = project_name
     sauth.write_stackn_config(stackn_config)
     if not os.path.exists(proj_path):
         if not os.path.exists(project_dir):
             os.makedirs(project_dir)
         # Fetch and write project settings file
         print('Writing new project config file.')
         project = self.get_projects({'name': project_name})
         status = dump_to_file(project, project_name, project_dir)
         if not status:
             print('Failed to set project -- could not write to config.')
Пример #6
0
    def __init__(self, config=None):
        self.found_project = False
        self.access_token, self.token_config = sauth.get_token()
        self.api_url = urljoin(self.token_config['studio_url'], '/api')
        self.auth_headers = {
            'Authorization': 'Token {}'.format(self.access_token)
        }

        # Fetch and set all active API endpoints
        self.get_endpoints()

        self.stackn_config, load_status = sauth.get_stackn_config()
        if not load_status:
            print('Failed to load stackn config')

        self.project = []
        self.project_slug = []
        active_dir = self.stackn_config['active']
        if 'active_project' in self.stackn_config:
            project_dir = os.path.expanduser('~/.scaleout/' + active_dir +
                                             '/projects')
            self.project, load_status = load_from_file(
                self.stackn_config['active_project'], project_dir)
            if load_status:
                self.found_project = True
                self.project_slug = self.project['slug']
                # else:
                #     print('Could not load project config for '+self.stackn_config['active_project'])
            else:
                print('You must set an active valid project.')
        # self.project = self.get_projects({'slug': self.project_slug})
        if not self.project:
            print('Did not find existing config')
            self.project_id = -1
        else:
            self.project_id = self.project['id']
            self.project_slug = self.project['slug']
Пример #7
0
def secure_cmd(ctx, secure):
    stackn_config, load_status = sauth.get_stackn_config()
    stackn_config['secure'] = secure
    sauth.write_stackn_config(stackn_config)