Пример #1
0
def get_api(conf):
    username = conf.get_go_username()
    if username is None:
        print('Globus Id: ', end=' ', flush=True)
        username = sys.stdin.readline().strip()
        atglobusidorg = username.rfind("@globusid.org")
        if atglobusidorg != -1:
            username = username[:atglobusidorg]
    password = conf.get_go_password()
    if password is None:
        password = getpass.getpass("Globus Password: "******"/goauth/token?grant_type=client_credentials"

    for tries in range(0, 10):
        try:
            authorizer = BasicAuthorizer(username, password)
            nexus_client = BaseClient('nexus', authorizer=authorizer)

            response = nexus_client.get(GOAUTH_PATH)
            access_token = response.data['access_token']
        except GlobusAPIError as e:
            if e.http_status == 403:
                print('{}\nRetrying'.format(e.message))
                print('Globus Id: ', end=' ', flush=True)
                username = sys.stdin.readline().strip()
                password = getpass.getpass("Globus Password: "******"timed out" not in str(e):
                raise e
            time.sleep(30)

    if go_instance == 'Production':
        go_instance = 'default'

    class TransferClientWithUserNameAndPassword(TransferClient):
        def __init__(self, username=None, password=None, **kwargs):
            self.username = username
            self.password = password
            super(TransferClientWithUserNameAndPassword,
                  self).__init__(**kwargs)

    api = TransferClientWithUserNameAndPassword(
        username=username,
        password=password,
        authorizer=AccessTokenAuthorizer(access_token),
        environment=go_instance,
        timeout=300.0)

    return api
Пример #2
0
 def setUpClass(self):
     """
     Creates a BaseClient object for testing
     """
     ac = globus_sdk.NativeAppAuthClient(
         client_id=get_client_data()["native_app_client1"]["id"])
     authorizer = globus_sdk.RefreshTokenAuthorizer(
         SDKTESTER1A_NATIVE1_TRANSFER_RT, ac)
     self.bc = BaseClient("transfer",
                          base_path="/v0.10/",
                          authorizer=authorizer)
def base_client():
    return BaseClient("transfer", base_path="/v0.10/")