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

fix: Workflow import did not insert AccessToken information #1900

Merged
merged 1 commit into from
Dec 24, 2024

Conversation

shaohuzhang1
Copy link
Contributor

fix: Workflow import did not insert AccessToken information

Copy link

f2c-ci-robot bot commented Dec 24, 2024

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

f2c-ci-robot bot commented Dec 24, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@shaohuzhang1 shaohuzhang1 merged commit af3266b into main Dec 24, 2024
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_workflow_import branch December 24, 2024 09:14
@@ -697,6 +697,9 @@ def import_(self, with_valid=True):
application_model = self.to_application(application, user_id)
function_lib_model_list = [self.to_function_lib(f, user_id) for f in function_lib_list]
application_model.save()
# 插入认证信息
ApplicationAccessToken(application_id=application_model.id,
access_token=hashlib.md5(str(uuid.uuid1()).encode()).hexdigest()[8:24]).save()
QuerySet(FunctionLib).bulk_create(function_lib_model_list) if len(function_lib_model_list) > 0 else None
return True

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code snippet has a few issues:

Issues Identified:

  1. Import Statement Missing: The import statement for uuid is missing at the top of the file, which could lead to errors at runtime.
  2. Variable Naming Convention: Variable names should be descriptive but concise (e.g., use camelCase instead of snake_case).
  3. String Formatting: The string formatting used inside the MD5 function may not behave as expected due to the incorrect usage of brackets.

Suggestions for Optimization and Fixes:

  1. Add Import Statement:

    import uuid
  2. Refactor Function Name and Parameter Names:

    def importApplication(self, with_valid=True):
        application_model = self.to_application(application, user_id)
        function_lib_models = [self.to_function_lib(f, user_id) for f in function_lib_list]
        
        # Save application model first
        application_model.save()
       
        # Insert authentication information
        ApplicationAccessToken.objects.create(
            application_id=application_model.id,
            access_token=hashlib.md5(str(uuid.uuid4()).encode()).hexdigest()[:24]  # Use uuid.uuid4 directly without hashing manually
        )
        
        # Bulk create function library models
        QuerySet(FunctionLib).bulk_create(function_lib_models) if len(function_lib_models) > 0 else None
        
        return True

Additional Notes:

  • Ensure that the to_application and to_function_lib methods exist and are appropriately implemented within your class.
  • Adjust the UUID generation method according to your needs, especially if you want more control over the token length.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant