-
Notifications
You must be signed in to change notification settings - Fork 40
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
Added support for upload with access and secretkey #314
Conversation
There was a problem hiding this 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.
cmd/image/upload/upload.go
Outdated
//Check if object exists or not | ||
if opt.ObjectName == "" { | ||
opt.ObjectName = filepath.Base(opt.ImageName) | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
cmd/image/upload/upload.go
Outdated
if pkg.ImageCMDOptions.AccessKey != "" && pkg.ImageCMDOptions.SecretKey != "" { | ||
s3Cli, err = client.NewS3Clientwithkeys(bxCli, opt.Region) | ||
if err != nil { | ||
fmt.Printf("err1: %+v\n", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why printf?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
cmd/image/upload/upload.go
Outdated
err = s3Cli.UploadObject(opt.ImageName, opt.ObjectName, opt.BucketName) | ||
if err != nil { | ||
return err | ||
} | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/client/s3client.go
Outdated
s3client.AccessKey = pkg.ImageCMDOptions.AccessKey | ||
s3client.SecretKey = pkg.ImageCMDOptions.SecretKey |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/client/s3client.go
Outdated
AccessKey string | ||
SecretKey string |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@KeerthanaAP lets merge #313 prior to this PR to use the changed signature for CheckIfObjectExists function |
@KeerthanaAP fix this error. |
863d84a
to
fbea935
Compare
pkg/client/s3client.go
Outdated
if pkg.Options.APIKey == "" { | ||
s3client.ApiKey = os.Getenv("IBMCLOUD_API_KEY") | ||
} else { | ||
s3client.ApiKey = pkg.Options.APIKey | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
383af39
to
1a04259
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[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 |
Fix #103