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

Added support for upload with access and secretkey #314

Merged
merged 3 commits into from
Aug 2, 2022

Conversation

KeerthanaAP
Copy link
Contributor

Fix #103

@ppc64le-cloud-bot ppc64le-cloud-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 28, 2022
Copy link
Member

@mkumatag mkumatag left a comment

Choose a reason for hiding this comment

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

I see lot of code repetition which can avoid with proper refactoring, lets take that part of a different exercise. Have some minor comments to fix.

Comment on lines 92 to 101
//Check if object exists or not
if opt.ObjectName == "" {
opt.ObjectName = filepath.Base(opt.ImageName)
}
Copy link
Member

Choose a reason for hiding this comment

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

This can be moved outside in the beginning to avoid repeating in the block as well

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.

if pkg.ImageCMDOptions.AccessKey != "" && pkg.ImageCMDOptions.SecretKey != "" {
s3Cli, err = client.NewS3Clientwithkeys(bxCli, opt.Region)
if err != nil {
fmt.Printf("err1: %+v\n", err)
Copy link
Member

Choose a reason for hiding this comment

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

why printf?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

Comment on lines 102 to 106
err = s3Cli.UploadObject(opt.ImageName, opt.ObjectName, opt.BucketName)
if err != nil {
return err
}
return nil
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err = s3Cli.UploadObject(opt.ImageName, opt.ObjectName, opt.BucketName)
if err != nil {
return err
}
return nil
return s3Cli.UploadObject(opt.ImageName, opt.ObjectName, opt.BucketName)

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 63 to 64
s3client.AccessKey = pkg.ImageCMDOptions.AccessKey
s3client.SecretKey = pkg.ImageCMDOptions.SecretKey
Copy link
Member

Choose a reason for hiding this comment

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

Lets not access these variables directly, lets pass them to the NewS3Clientwithkeys function to avoid direct deps on the pkg.ImageCMDOptions

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 43 to 44
AccessKey string
SecretKey string
Copy link
Member

Choose a reason for hiding this comment

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

if these aren't used anywhere else then I don't see a point in using them 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.

Removed

@@ -204,6 +239,8 @@ func init() {
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.ImageName, "file", "f", "", "The PATH to the file to upload.")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.ObjectName, "cos-object-name", "o", "", "Cloud Object Storage Object Name(Default: filename from --file|-f option)")
Cmd.Flags().StringVarP(&pkg.ImageCMDOptions.Region, "bucket-region", "r", "us-south", "Cloud Object Storage bucket region.")
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.AccessKey, "accesskey", "", "Cloud Object Storage HMAC 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.

Add an example with these params

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added example for this workflow

@mkumatag
Copy link
Member

@KeerthanaAP lets merge #313 prior to this PR to use the changed signature for CheckIfObjectExists function

@mkumatag
Copy link
Member

@KeerthanaAP: Adding label do-not-merge/contains-merge-commits because PR contains merge commits, which are not allowed in this repository.
Use git rebase to reapply your commits on top of the target branch. Detailed instructions for doing so can be found here.

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.

@KeerthanaAP fix this error.

Comment on lines 55 to 59
if pkg.Options.APIKey == "" {
s3client.ApiKey = os.Getenv("IBMCLOUD_API_KEY")
} else {
s3client.ApiKey = pkg.Options.APIKey
}
Copy link
Member

Choose a reason for hiding this comment

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

If access key and secret passed, do we still need API key?

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, its not needed. Bluemix client is also not needed. Will remove both from this function

Copy link
Member

@mkumatag mkumatag left a comment

Choose a reason for hiding this comment

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

/lgtm

@ppc64le-cloud-bot ppc64le-cloud-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 2, 2022
@ppc64le-cloud-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: KeerthanaAP, mkumatag

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

The pull request process is described 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

@ppc64le-cloud-bot ppc64le-cloud-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 2, 2022
@mkumatag mkumatag added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Aug 2, 2022
@ppc64le-cloud-bot ppc64le-cloud-bot merged commit 993e2b0 into ppc64le-cloud:main Aug 2, 2022
@KeerthanaAP KeerthanaAP deleted the upload_with_keys branch August 3, 2022 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a image upload flow via access-key and secret-key
3 participants