Exemplo n.º 1
0
 def pull(self,
          api_name,
          dependencies=[],
          force=False,
          prefix=None,
          basepath=None):
     dependencies.append(api_name)
     make_dirs(self._work_tree)
     self.apiproxy_dir = api_name
     if not force:
         paths_exist((os.path.relpath(self._zip_file),
                      os.path.relpath(self._apiproxy_dir)))
     export = self.export_api_proxy(api_name,
                                    self._revision_number,
                                    fs_write=True,
                                    output_file=self._zip_file)
     make_dirs(self._apiproxy_dir)
     extract_zip(self._zip_file, self._apiproxy_dir)
     os.remove(self._zip_file)
     files = self.get_apiproxy_files(self._apiproxy_dir)
     for resource_type in ('keyvaluemap', 'targetserver', 'cache'):
         self._Apis__get_and_export(resource_type,
                                    files,
                                    self._environment,
                                    dependencies=dependencies,
                                    force=force)
     return export, dependencies
Exemplo n.º 2
0
def set_header(auth_obj, headers={}):
    if auth_obj.mfa_secret or auth_obj.token or auth_obj.zonename:
        access_token = ""
        make_dirs(APIGEE_CLI_DIRECTORY)
        try:
            with open(APIGEE_CLI_ACCESS_TOKEN_FILE, 'r') as f:
                access_token = f.read().strip()
        except (IOError, OSError) as e:
            pass
        finally:
            if access_token:
                decoded = jwt.decode(access_token,
                                     options={"verify_signature": False})
                if (decoded['exp'] < int(time.time()) or
                        decoded['email'].lower() != auth_obj.username.lower()):
                    access_token = ""
        if not access_token:
            access_token = get_access_token(auth_obj)
            with open(APIGEE_CLI_ACCESS_TOKEN_FILE, 'w') as f:
                f.write(access_token)
        headers['Authorization'] = f'Bearer {access_token}'
    else:
        headers['Authorization'] = ('Basic ' + base64.b64encode(
            (f'{auth_obj.username}:{auth_obj.password}').encode()).decode())
    return headers
Exemplo n.º 3
0
def configure(username, password, mfa_secret, token, zonename, org, prefix,
              profile):
    if isinstance(password, HiddenSecret):
        password = password.secret
    if isinstance(mfa_secret, HiddenSecret):
        mfa_secret = mfa_secret.secret
    profile_dict['username'] = username
    profile_dict['password'] = password
    profile_dict['mfa_secret'] = mfa_secret
    profile_dict['is_token'] = token
    profile_dict['zonename'] = zonename
    profile_dict['org'] = org
    profile_dict['prefix'] = prefix
    config[profile] = {k: v for k, v in profile_dict.items() if v}
    make_dirs(APIGEE_CLI_DIRECTORY)
    with open(APIGEE_CLI_CREDENTIALS_FILE, 'w') as cf:
        config.write(cf)
Exemplo n.º 4
0
    def export_targetserver_dependencies(self,
                                         environment,
                                         targetservers,
                                         force=False,
                                         expc_verbosity=1):
        make_dirs(self._targetservers_dir)

        def _func(ts):
            ts_file = str(Path(self._targetservers_dir) / ts)
            if not force:
                path_exists(os.path.relpath(ts_file))
            resp = Targetservers(self._auth, self._org_name,
                                 ts).get_targetserver(environment).text
            console.echo(resp, expc_verbosity=1)
            with open(ts_file, 'w') as f:
                f.write(resp)

        return run_func_on_iterable(targetservers, _func)
Exemplo n.º 5
0
    def export_cache_dependencies(self,
                                  environment,
                                  caches,
                                  force=False,
                                  expc_verbosity=1):
        make_dirs(self._caches_dir)

        def _func(cache):
            cache_file = str(Path(self._caches_dir) / cache)
            if not force:
                path_exists(os.path.relpath(cache_file))
            resp = (Caches(
                self._auth, self._org_name,
                cache).get_information_about_a_cache(environment).text)
            console.echo(resp, expc_verbosity=1)
            with open(cache_file, 'w') as f:
                f.write(resp)

        return run_func_on_iterable(caches, _func)
Exemplo n.º 6
0
    def export_keyvaluemap_dependencies(self,
                                        environment,
                                        keyvaluemaps,
                                        force=False,
                                        expc_verbosity=1):
        make_dirs(self._keyvaluemaps_dir)

        def _func(kvm):
            kvm_file = str(Path(self._keyvaluemaps_dir) / kvm)
            if not force:
                path_exists(os.path.relpath(kvm_file))
            resp = (Keyvaluemaps(
                self._auth, self._org_name,
                kvm).get_keyvaluemap_in_an_environment(environment).text)
            console.echo(resp, expc_verbosity=1)
            with open(kvm_file, 'w') as f:
                f.write(resp)

        return run_func_on_iterable(keyvaluemaps, _func)
Exemplo n.º 7
0
def init():
    make_dirs(APIGEE_CLI_PLUGINS_DIRECTORY)
    touch(APIGEE_CLI_PLUGINS_PATH)
    touch(APIGEE_CLI_PLUGINS_CONFIG_FILE)