def test_get_get_provider_resource_name(self): """Test provider name getter.""" auth_id = self.aws_db_auth.id accessor = ProviderAuthDBAccessor(auth_id) self.assertEqual( self.aws_provider.authentication.provider_resource_name, accessor.get_provider_resource_name())
def test_initializer(self): """Test Initializer""" auth_id = '1' accessor = ProviderAuthDBAccessor(auth_id) self.assertIsNotNone(accessor._session) self.assertTrue(accessor.does_db_entry_exist()) accessor.close_session()
def test_get_uuid(self): """Test uuid getter.""" auth_id = '1' accessor = ProviderAuthDBAccessor(auth_id) self.assertEqual('7e4ec31b-7ced-4a17-9f7e-f77e9efa8fd6', accessor.get_uuid()) accessor.close_session()
def test_initializer_auth_id_and_provider_resource_name(self): """Test Initializer with auth_id and provider resource name.""" auth_id = self.ocp_db_auth_id provider_resource_name = self.ocp_provider_resource_name accessor = ProviderAuthDBAccessor(auth_id=auth_id, provider_resource_name=provider_resource_name) self.assertTrue(accessor.does_db_entry_exist()) self.assertEqual(int(auth_id), accessor.get_auth_id())
def test_initializer_provider_resource_name(self): """Test Initializer with provider resource name.""" provider_resource_name = self.ocp_provider_resource_name accessor = ProviderAuthDBAccessor(provider_resource_name=provider_resource_name) self.assertIsNotNone(accessor._session) self.assertTrue(accessor.does_db_entry_exist()) accessor.close_session()
def test_get_get_provider_resource_name(self): """Test provider name getter.""" auth_id = '1' accessor = ProviderAuthDBAccessor(auth_id) self.assertEqual('arn:aws:iam::111111111111:role/CostManagement', accessor.get_provider_resource_name()) accessor.close_session()
def test_initializer_auth_id_and_credentials(self): """Test Initializer with auth_id and credentials.""" auth_id = self.ocp_db_auth.id credentials = self.ocp_provider.authentication.credentials accessor = ProviderAuthDBAccessor(auth_id=auth_id, credentials=credentials) self.assertTrue(accessor.does_db_entry_exist()) self.assertEqual(int(auth_id), accessor.get_auth_id())
def get_authentication(self): """ Return the authentication name information. Args: None Returns: (String): "Provider Resource Name. i.e. AWS: RoleARN", example: "arn:aws:iam::111111111111:role/CostManagement" """ obj = self._get_db_obj_query().first() authentication_id = obj.authentication_id auth_accessor = ProviderAuthDBAccessor(authentication_id) return auth_accessor.get_provider_resource_name()
def get_provider_uuid_from_cluster_id(cluster_id): """ Return the provider UUID given the cluster ID. Args: cluster_id (String): OpenShift Cluster ID Returns: (String): provider UUID """ provider_uuid = None auth_id = None credentials = {"cluster_id": cluster_id} with ProviderAuthDBAccessor(credentials=credentials) as auth_accessor: auth_id = auth_accessor.get_auth_id() LOG.info( f"Found Authentication ID {str(auth_id)} for Cluster ID: {str(cluster_id)}" ) if auth_id: with ProviderDBAccessor(auth_id=auth_id) as provider_accessor: provider_uuid = provider_accessor.get_uuid() LOG.info( f"Found provider: {str(provider_uuid)} for Cluster ID: {str(cluster_id)}" ) return provider_uuid
def test_initializer(self): """Test Initializer""" auth_id = self.aws_db_auth_id accessor = ProviderAuthDBAccessor(auth_id) self.assertIsNotNone(accessor._session) self.assertTrue(accessor.does_db_entry_exist()) self.assertEqual(int(auth_id), accessor.get_auth_id()) accessor.close_session()
def get_provider_uuid_from_cluster_id(cluster_id): """ Return the provider UUID given the cluster ID. Args: cluster_id (String): OpenShift Cluster ID Returns: (String): provider UUID """ provider_uuid = None auth_id = None with ProviderAuthDBAccessor(provider_resource_name=cluster_id) as auth_accessor: auth_id = auth_accessor.get_auth_id() if auth_id: with ProviderDBAccessor(auth_id=auth_id) as provider_accessor: provider_uuid = provider_accessor.get_uuid() return provider_uuid
def get_provider_uuid_from_cluster_id(cluster_id): """ Return the provider UUID given the cluster ID. Args: cluster_id (String): OpenShift Cluster ID Returns: (String): provider UUID """ provider_uuid = None auth_id = None credentials = {"cluster_id": cluster_id} with ProviderAuthDBAccessor(credentials=credentials) as auth_accessor: auth_id = auth_accessor.get_auth_id() if auth_id: with ProviderDBAccessor(auth_id=auth_id) as provider_accessor: provider_uuid = provider_accessor.get_uuid() return provider_uuid
def get_cluster_alias_from_cluster_id(cluster_id): """ Return the cluster alias of a given cluster id. Args: cluster_id (String): OpenShift Cluster ID Returns: (String): OpenShift Cluster Alias """ cluster_alias = None auth_id = None with ProviderAuthDBAccessor( provider_resource_name=cluster_id) as auth_accessor: auth_id = auth_accessor.get_auth_id() if auth_id: with ProviderDBAccessor(auth_id=auth_id) as provider_accessor: cluster_alias = provider_accessor.get_provider_name() return cluster_alias
def test_get_credentials(self): """Test provider name getter.""" auth_id = self.aws_db_auth.id accessor = ProviderAuthDBAccessor(auth_id) self.assertEqual(self.aws_provider.authentication.credentials, accessor.get_credentials())
def test_get_get_provider_resource_name(self): """Test provider name getter.""" auth_id = self.aws_db_auth_id accessor = ProviderAuthDBAccessor(auth_id) self.assertEqual(self.aws_provider_resource_name, accessor.get_provider_resource_name()) accessor.close_session()
def test_get_uuid(self): """Test uuid getter.""" auth_id = self.aws_db_auth_id accessor = ProviderAuthDBAccessor(auth_id) self.assertEqual(uuid.UUID(self.aws_auth_provider_uuid), accessor.get_uuid())
def test_get_uuid(self): """Test uuid getter.""" auth_id = self.aws_db_auth.id accessor = ProviderAuthDBAccessor(auth_id) self.assertEqual(self.aws_provider.authentication.uuid, accessor.get_uuid())
def test_initializer_no_args(self): """Test Initializer with no arguments.""" accessor = ProviderAuthDBAccessor() self.assertTrue(accessor.does_db_entry_exist())
def test_initializer(self): """Test Initializer.""" auth_id = self.aws_db_auth.id accessor = ProviderAuthDBAccessor(auth_id) self.assertTrue(accessor.does_db_entry_exist()) self.assertEqual(int(auth_id), accessor.get_auth_id())
def test_initializer_credentials(self): """Test Initializer with credentials.""" credentials = self.ocp_provider.authentication.credentials accessor = ProviderAuthDBAccessor(credentials=credentials) self.assertTrue(accessor.does_db_entry_exist())