Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5623] feat(python): supports credential API in python client #5777

Merged
merged 17 commits into from
Dec 12, 2024

Conversation

FANNG1
Copy link
Contributor

@FANNG1 FANNG1 commented Dec 6, 2024

What changes were proposed in this pull request?

supports credential API in python client

        catalog = gravitino_client.load_catalog(catalog_name)
        catalog.as_fileset_catalog().support_credentials().get_credentials()
        
        fileset = catalog.as_fileset_catalog().load_fileset(
            NameIdentifier.of("schema", "fileset")
        )
        credentials = fileset.support_credentials().get_credentials()

Why are the changes needed?

Fix: #5623

Does this PR introduce any user-facing change?

no

How was this patch tested?

  1. add UT
  2. setup a Gravitino server which returns credential, test with python client

@FANNG1 FANNG1 marked this pull request as draft December 6, 2024 01:06
@FANNG1 FANNG1 force-pushed the credential-python branch from 5f02995 to 020bca1 Compare December 6, 2024 09:04
@FANNG1 FANNG1 force-pushed the credential-python branch from 85f8540 to e9b21b3 Compare December 9, 2024 06:21
@FANNG1 FANNG1 changed the title [SIP] Credential python client [#5623] feat(python): supports credential API in python client Dec 9, 2024
@FANNG1 FANNG1 marked this pull request as ready for review December 9, 2024 13:18
@FANNG1
Copy link
Contributor Author

FANNG1 commented Dec 9, 2024

It's ready to review now, @jerryshao @yuqi1129 please help to review, thanks

@jerryshao jerryshao requested review from noidname01, xunliu, xloya and yuqi1129 and removed request for xunliu December 10, 2024 02:32
@FANNG1
Copy link
Contributor Author

FANNG1 commented Dec 11, 2024

@jerryshao @xloya , all comments are addressed, please help to review again

)
Precondition.check_argument(
self.expire_time_in_ms,
"The expiration time of S3 token credential should greater than 0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be,
Please check other similar problems like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"""The s3 session token.

Returns:
The S3 session token.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd better use s3 or S3 in the whole class or in this PR uniformly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

self._session_token, "The S3 session token should not be empty"
)
Precondition.check_argument(
self.expire_time_in_ms,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not a boolean expression, it should be a problem here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

"""Retrieves an array of Credential objects.

Returns:
An array of Credential objects. In most cases the array only contains
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array or List? Please describe it correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

a catalog but the credential provider couldn't generate the credential
for the catalog, like S3 token credential provider only generate
credential for the specific object like Fileset,Table. There will be at
most one credential for one credential type.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the prefix whitespace in this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@jerryshao
Copy link
Contributor

Generally LGTM from the logic, @xunliu @noidname01 would you please help to review this PR, to see if it follows Python's convention.

@noidname01
Copy link
Collaborator

LGTM!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look like lose two java function in the Python side

  1. void initialize(Map<String, String> credentialInfo, long expireTimeInMs);
  2. default Map<String, String> toProperties()
    Don't we need these two function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, toProperties is used to serialize credential objects in server side, initialize is something like deserialize in client side, for python implementation, we only focus on the deserialize part, so create the credential with credentialInfo and expireTimeInMs.

Comment on lines 28 to 31
GCS_TOKEN_CREDENTIAL_TYPE = "gcs-token"
_GCS_TOKEN_NAME = "token"

_expire_time_in_ms = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add variable types for these variables

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 28 to 31
OSS_TOKEN_CREDENTIAL_TYPE = "oss-token"
_GRAVITINO_OSS_SESSION_ACCESS_KEY_ID = "oss-access-key-id"
_GRAVITINO_OSS_SESSION_SECRET_ACCESS_KEY = "oss-secret-access-key"
_GRAVITINO_OSS_TOKEN = "oss-security-token"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add variable types for these variables

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 28 to 30
S3_SECRET_KEY_CREDENTIAL_TYPE = "s3-secret-key"
_GRAVITINO_S3_STATIC_ACCESS_KEY_ID = "s3-access-key-id"
_GRAVITINO_S3_STATIC_SECRET_ACCESS_KEY = "s3-secret-access-key"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add variable types for these variables

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can keep the consistent Java class name CredentialFactory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -74,6 +79,11 @@ def __init__(
self.rest_client = rest_client
self._catalog_namespace = catalog_namespace

metadata_object = MetadataObjectImpl([name], MetadataObject.Type.CATALOG)
self._credential_operations = MetadataObjectCredentialOperations(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better to change _credential_operations to _objectCredentialOperations, keep consistent Java side.
and add _objectCredentialOperations into BaseSchemaCatalog member variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

def __init__(
self, fileset: FilesetDTO, rest_client: HTTPClient, full_namespace: Namespace
):
self._fileset = fileset
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add _fileset into GenericFileset member variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +41 to +47
self._rest_client = rest_client
metadata_object_type = metadata_object.type().value
metadata_object_name = metadata_object.name()
self._request_path = (
f"api/metalakes/{metalake_name}objects/{metadata_object_type}/"
f"{metadata_object_name}/credentials"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add _rest_client and _request_path into MetadataObjectCredentialOperations member variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@xunliu xunliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@xunliu xunliu merged commit c98c151 into apache:main Dec 12, 2024
23 checks passed
Abyss-lord pushed a commit to Abyss-lord/gravitino that referenced this pull request Dec 13, 2024
…pache#5777)

### What changes were proposed in this pull request?
supports credential API in python client 

```python
        catalog = gravitino_client.load_catalog(catalog_name)
        catalog.as_fileset_catalog().support_credentials().get_credentials()
        
        fileset = catalog.as_fileset_catalog().load_fileset(
            NameIdentifier.of("schema", "fileset")
        )
        credentials = fileset.support_credentials().get_credentials()
```

### Why are the changes needed?

Fix: apache#5623 

### Does this PR introduce _any_ user-facing change?
no

### How was this patch tested?
1. add UT
2. setup a Gravitino server which returns credential, test with python
client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Subtask] support credential python client for Gravitino
6 participants