示例#1
0
    def list(self):
        container = self.util.get_container(self.container,
                                            self.container_type)
        container_id = container.get('id')
        data = {
            'filter': self.filter,
            'page': self.page,
            'pagesize': self.pagesize
        }

        handlers = {
            'actualState':
            lambda x: click.style(x, fg='red')
            if x not in ['running'] else click.style(x, fg='green')
        }

        resp = self.util.cli_request(
            'GET',
            self.util.build_url(
                '{experienceCloudUri}/iot/v1/containers/{container_id}/versions?page={page}&pagesize={pagesize}&{filter}',
                {
                    'container_id': container_id,
                    **data
                }))

        if self.json:
            click.echo(json.dumps(resp))
            return

        pyke.Menu().print_menu(resp['payload']['data'],
                               self.format,
                               handlers=handlers)
        self.util.print_record_count(resp)
示例#2
0
    def create(self):
        # Replace with os.walk()
        if not self.icon_file:
            self.icon_file = self.util.resolve_default_icon_path()

        post_data = {
            'name':
            self.name,
            'urlRef':
            self.url_ref,
            'type':
            self.container_type,
            'ephemeralKey':
            self.util.upload_ephemeral(self.icon_file, 'image/svg+xml'),
            'publisherName':
            self.util.ctx['orgName'],
        }

        resp = self.util.cli_request(
            'POST',
            self.util.build_url('{experienceCloudUri}/iot/v1/containers'),
            data=json.dumps(post_data))

        if self.json:
            click.echo(json.dumps(resp))
            return

        pyke.Menu().print_menu([resp['payload']['data']], self.format)
示例#3
0
    def create(self):
        if not self.util.ctx.get('instanceType'):
            raise click.ClickException(
                click.style(
                    "This profile looks old. Run 'luma profile refresh-token' to migrate this profile to the new format.",
                    fg='red'))
        if self.util.ctx.get('instanceType') == 'cc':
            raise click.ClickException(
                click.style("This command must be run with a studio profile",
                            fg='red'))

        xp_data = {}
        xp_data['label'] = self.name
        xp_data['code'] = self.activation_code
        xp_data['description'] = self.description
        xp_data['device'] = self.device_type
        xp_data['type'] = self.type
        if self.redirect_url:
            xp_data['redirectUrl'] = self.redirect_url

        if self.collection:
            collection = self.util.get_collection(self.collection)
            xp_data['experienceCollectionId'] = collection.get('id')
        else:
            titles = titles = {'name': 'Name', 'id': 'Collection ID'}
            collection = pyke.Menu().get_user_select(
                self.util.get_all_collections(), '{name} {id}', titles=titles)
            xp_data['experienceCollectionId'] = collection.get('id')

        resp = self.util.cli_request(
            'POST',
            self.util.build_url('{experienceCloudUri}/iot/v1/experiences'),
            json=xp_data)
        if self.json:
            click.echo(resp)
            return

        titles = titles = {
            'label': 'Label',
            'name': 'Namespace',
            'code': 'Code',
            'device': 'Device'
        }
        pyke.Menu().print_menu([resp['payload']['data']],
                               '{label} {name} {code} {device}',
                               titles=titles)
示例#4
0
def list(env, format, filter, json_flag):
    handlers = {'instanceType': lambda x: 'dev' if x == 'cc' else x}

    if 'instanceType=dev' in filter:
        filter = filter.replace('instanceType=dev', 'instanceType=cc')

    if 'isTest=None' in filter:
        filter = filter.replace('isTest=None', 'instanceType=cc')

    env_format = '{envName} {app}'
    titles = {'envName': 'Env Name', 'app': 'App'}

    if not env:
        envs = pyke.auth.list_envs()
        env_data = pyke.Menu().get_user_select(envs, env_format, titles=titles)
    else:
        env_data = pyke.auth.get_env_data(env)

    util = pyke.Util(ctx=env_data)

    access_token = util.login_without_context()
    util.ctx.update({'accessToken': access_token})

    headers = {
        'Authorization': 'Bearer ' + access_token,
        'Content-Type': 'application/json'
    }

    app_name = env_data.get('app')
    if not app_name:
        raise click.ClickException(click.style("Env not configured", fg='red'))

    resp = requests.get('{}/auth/v1/me/companies?sort=name&{}'.format(
        app_name, filter),
                        headers=headers,
                        verify=verify_tls)

    if json_flag:
        click.echo(resp.text)
        return

    pyke.Menu().print_menu(resp.json()['payload']['data'],
                           format,
                           handlers=handlers)
示例#5
0
def list(format, json_flag):
    profile_data = pyke.auth.list_profiles()
    if json_flag:
        click.echo(json.dumps(profile_data))
        return

    titles = {
        "profileName": "Profile Name",
        "env": "Env",
        "orgName": "Org Name",
        "orgId": "Org ID"
    }
    pyke.Menu().print_menu(profile_data, format, titles=titles)
示例#6
0
  def delete(self):
    component_set = self.util.get_component_set(self.component_set)
    component_set_id = component_set.get('id')
    versions = self.util.get_all_component_set_versions(component_set_id)
    if versions:
      raise click.ClickException(click.style("You cannont delete a component set with versions", fg='red'))

    resp = self.util.cli_request('DELETE',
        self.util.build_url('{experienceCloudUri}/iot/v1/component-sets/{component_set_id}', {'component_set_id': component_set_id}))

    if self.json:
      click.echo(json.dumps(resp))
      return

    pyke.Menu().print_menu([resp['payload']['data']], self.format)
示例#7
0
def add(profile_name, env, format):
    if not profile_name:
        profile_name = click.prompt(click.style("Profile Name", fg="white"),
                                    type=str)

    click.echo(' ')

    titles = {
        'envName': 'Env Name',
        'app': 'App',
        'audience': 'Audience',
        'token': 'Token'
    }

    headers = '{envName} {app} {audience} {token}'

    if env:
        env_data = pyke.auth.get_env_data(env)
    else:
        envs = pyke.auth.list_envs()
        env_data = pyke.Menu().get_user_select(envs,
                                               headers,
                                               sort='envName',
                                               titles=titles)

    util = pyke.Util(ctx=env_data)

    titles = {
        'name': 'Org Name',
        'instanceType': 'Org Type',
        'isTest': 'Test Org'
    }
    headers = "{name} {instanceType} {isTest}"
    company = pyke.Menu().get_user_select(util.get_companies(),
                                          headers,
                                          sort='orgName',
                                          titles=titles)

    profile_data = {}
    profile_data["orgId"] = company.get('id')
    profile_data["orgName"] = company.get('name')
    profile_data["env"] = util.ctx.get('envName')
    profile_data["instanceType"] = company.get('instanceType')
    profile_data["profileName"] = profile_name

    pyke.auth.update_profile(profile_name, profile_data)
    util.ctx.update(profile_data)

    company_context = get_company_context(util.ctx).get('company')

    if company_context:
        profile_data = pyke.auth.get_profile_data(profile_name)
        profile_data['experienceCloudUri'] = company_context[
            'experienceCloudUri']
        pyke.auth.update_profile(profile_name, profile_data)

    else:
        raise click.ClickException(
            click.style('Error getting company context', fg='red'))

    titles = {
        'profileName': 'Profile',
        'env': 'Environment',
        'orgName': 'Org Name',
        'orgId': 'Org ID'
    }

    pyke.Menu().print_menu([profile_data], format, titles=titles)
示例#8
0
    def import_(self):
        if not self.util.ctx.get('instanceType'):
            raise click.ClickException(
                click.style(
                    "This profile looks old. Run 'luma profile refresh-token' to migrate this profile to the new format.",
                    fg='red'))
        if self.util.ctx.get('instanceType') == 'cc':
            raise click.ClickException(
                click.style("This command must be run with a studio profile",
                            fg='red'))

        if self.collection:
            collection = self.util.get_collection(self.collection)
        else:
            titles = titles = {'name': 'Name', 'id': 'Collection ID'}
            collection = pyke.Menu().get_user_select(
                self.util.get_all_collections(), '{name} {id}', titles=titles)

        collection_id = collection.get('id')

        if not self.json:
            click.echo('Uploading file...')

        # Request ephemeral token
        token_resp = self.util.cli_request(
            'GET',
            self.util.build_url(
                '{experienceCloudUri}/iot/v1/files/ephemeral?contentType=application/json'
            ))
        token_data = token_resp.get('payload', {}).get('data', {})
        token_fields = token_data.get('fields')

        aws_access_key_id = token_fields.get('AWSAccessKeyId')
        ephemeral_key = token_fields.get('key').replace(
            '${filename}', 'import.json')
        policy = token_fields.get('policy')
        signature = token_fields.get('signature')
        url = token_data.get('url')

        # Post to ephemral URL
        data = {
            'AWSAccessKeyId': aws_access_key_id,
            'key': ephemeral_key,
            'policy': policy,
            'signature': signature,
            'Content-Type': 'application/json'
        }

        aws_resp = None
        with open(self.import_file, 'rb') as f:
            aws_resp = requests.post(url,
                                     data=data,
                                     files={'file': f},
                                     verify=verify_tls)

        if not self.json:
            click.echo('File uploaded.')
            click.echo('')

        # Post to import
        import_json = {
            'name': '',
            'description': self.description,
            'type': self.type,
            'experienceCollectionId': collection_id,
            'label': self.label,
            'redirectUrl': self.redirect_url,
            'code': self.activation_code,
            'ephemeralKey': ephemeral_key,
            'device': self.device_type
        }

        import_resp = self.util.cli_request(
            'POST',
            self.util.build_url(
                '{experienceCloudUri}/iot/v1/experiences/import'),
            json=import_json)
        if self.json:
            click.echo(json.dumps(import_resp))
            return

        status_id = import_resp.get('payload', {}).get('data',
                                                       {}).get('statusId', {})
        status_resp = self.util.show_progress(status_id,
                                              label='Importing experience')

        error_msg = status_resp.get('payload', {}).get('data',
                                                       {}).get('errorMessage')
        if error_msg is not None:
            raise pyke.CliException('Import failed. {}'.format(error_msg))

        click.echo('Successfully imported experience.')