forked from TrueCloudLab/frostfs-s3-gw
[#339] Fix logging in authmate [pre]sign command
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
7bf31bea18
commit
ea714c2e9e
6 changed files with 54 additions and 31 deletions
|
@ -1,6 +1,7 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -49,22 +50,25 @@ func initSignCmd() {
|
|||
}
|
||||
|
||||
func runSignCmd(cmd *cobra.Command, _ []string) error {
|
||||
ctx, cancel := context.WithTimeout(cmd.Context(), viper.GetDuration(timeoutFlag))
|
||||
defer cancel()
|
||||
|
||||
var (
|
||||
region string
|
||||
creds aws.Credentials
|
||||
)
|
||||
|
||||
if profile := viper.GetString(profileFlag); profile == "" {
|
||||
cfg, err := config.LoadDefaultConfig(cmd.Context())
|
||||
cfg, err := config.LoadDefaultConfig(ctx)
|
||||
if err != nil {
|
||||
return wrapPreparationError(err)
|
||||
}
|
||||
region = cfg.Region
|
||||
if creds, err = cfg.Credentials.Retrieve(cmd.Context()); err != nil {
|
||||
if creds, err = cfg.Credentials.Retrieve(ctx); err != nil {
|
||||
return wrapPreparationError(fmt.Errorf("couldn't get default aws credentials: %w", err))
|
||||
}
|
||||
} else {
|
||||
cfg, err := config.LoadSharedConfigProfile(cmd.Context(), profile)
|
||||
cfg, err := config.LoadSharedConfigProfile(ctx, profile)
|
||||
if err != nil {
|
||||
return wrapPreparationError(fmt.Errorf("couldn't get '%s' aws credentials: %w", profile, err))
|
||||
}
|
||||
|
@ -106,8 +110,8 @@ func runSignCmd(cmd *cobra.Command, _ []string) error {
|
|||
sigv4a := viper.GetBool(sigV4AFlag)
|
||||
if sigv4a {
|
||||
var err error
|
||||
if signature, err = auth.SignStrV4A(creds, data); err != nil {
|
||||
return wrapPreparationError(fmt.Errorf("sign v4a: %w", err))
|
||||
if signature, err = auth.SignStrV4A(ctx, creds, data); err != nil {
|
||||
return wrapPreparationError(fmt.Errorf("sign str v4a: %w", err))
|
||||
}
|
||||
} else {
|
||||
signature = auth.SignStr(creds.SecretAccessKey, service, region, signTime, data)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue