def generate_authorization_provider(tenant_id): # Creates an AuthorizationProvider instance based on the environment. if using_cloud_sim: provider = ExampleAuthorizationProvider(tenant_id) elif using_service: if principal == 'user principal': if credentials_file is None: raise IllegalArgumentException( 'Must specify the credentials file path.') provider = SignatureProvider(config_file=credentials_file) elif principal == 'instance principal': if isinstance(endpoint, str): region = Regions.from_region_id(endpoint) else: region = endpoint provider = SignatureProvider.create_with_instance_principal( region=region) elif principal == 'resource principal': provider = SignatureProvider.create_with_resource_principal() else: raise IllegalArgumentException('Must specify the principal.') elif using_on_prem: if user_name is None and password is None: provider = StoreAccessTokenProvider() else: if user_name is None or password is None: raise IllegalArgumentException( 'Please set both the user_name and password.') provider = StoreAccessTokenProvider(user_name, password) else: raise IllegalArgumentException('Please set the test server.') return provider
def generate_authorization_provider(tenant_id): if is_cloudsim(): authorization_provider = InsecureAuthorizationProvider(tenant_id) elif is_dev_pod() or is_minicloud(): authorization_provider = TestSignatureProvider(tenant_id) elif is_prod_pod(): if iam_principal() == 'user principal': if credentials_file is None: raise IllegalArgumentException( 'Must specify the credentials file path.') authorization_provider = SignatureProvider( config_file=credentials_file) elif iam_principal() == 'instance principal': if isinstance(endpoint, str): region = Regions.from_region_id(endpoint) else: region = endpoint if region is None: authorization_provider = ( SignatureProvider.create_with_instance_principal()) else: authorization_provider = ( SignatureProvider.create_with_instance_principal( region=region)) elif iam_principal() == 'resource principals': authorization_provider = ( SignatureProvider.create_with_resource_principal()) else: raise IllegalArgumentException('Must specify the principal.') elif is_onprem(): if user_name is None and password is None: authorization_provider = StoreAccessTokenProvider() else: if user_name is None or password is None: raise IllegalArgumentException( 'Please set both the user_name and password.') authorization_provider = StoreAccessTokenProvider( user_name, password) else: raise IllegalArgumentException('Please set the test server.') return authorization_provider
def testInstancePrincipalGetRegion(self): self.token_provider = ( SignatureProvider.create_with_instance_principal( region=Regions.US_ASHBURN_1)) self.assertEqual(self.token_provider.get_region(), Regions.US_ASHBURN_1)