コード例 #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
ファイル: stackn_cmd.py プロジェクト: cawik/stackn
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
ファイル: studioclient.py プロジェクト: hamzaimran08/stackn
    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
ファイル: studioclient.py プロジェクト: hamzaimran08/stackn
 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
ファイル: set_cmd.py プロジェクト: hamzaimran08/stackn
def secure_cmd(ctx, secure):
    stackn_config, load_status = sauth.get_stackn_config()
    stackn_config['secure'] = secure
    sauth.write_stackn_config(stackn_config)