Skip to content

Commit

Permalink
authmate: Make ObtainingResult structure public
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
  • Loading branch information
smallhive committed Jan 28, 2025
1 parent def97c0 commit 4a5f90b
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 7 additions & 10 deletions authmate/authmate.go
Original file line number Diff line number Diff line change
@@ -143,7 +143,8 @@ type (
ContainerID string `json:"container_id"`
}

obtainingResult struct {
// ObtainingResult contains payload for obtainingSecret command.
ObtainingResult struct {
BearerToken *bearer.Token `json:"-"`
SecretAccessKey string `json:"secret_access_key"`
}
@@ -299,27 +300,23 @@ func (a *Agent) IssueSecret(ctx context.Context, w io.Writer, options *IssueSecr

// ObtainSecret receives an existing secret access key from NeoFS and
// writes to io.Writer the secret access key.
func (a *Agent) ObtainSecret(ctx context.Context, w io.Writer, options *ObtainSecretOptions) error {
func (a *Agent) ObtainSecret(ctx context.Context, options *ObtainSecretOptions) (*ObtainingResult, error) {
bearerCreds := tokens.New(a.neoFS, options.GatePrivateKey, cache.DefaultAccessBoxConfig(a.log))

var addr oid.Address
if err := addr.DecodeString(options.SecretAddress); err != nil {
return fmt.Errorf("failed to parse secret address: %w", err)
return nil, fmt.Errorf("failed to parse secret address: %w", err)
}

box, err := bearerCreds.GetBox(ctx, addr)
if err != nil {
return fmt.Errorf("failed to get tokens: %w", err)
return nil, fmt.Errorf("failed to get tokens: %w", err)
}

or := &obtainingResult{
return &ObtainingResult{
BearerToken: box.Gate.BearerToken,
SecretAccessKey: box.Gate.AccessKey,
}

enc := json.NewEncoder(w)
enc.SetIndent("", " ")
return enc.Encode(or)
}, nil
}

func buildEACLTable(eaclTable []byte) (*eacl.Table, error) {
7 changes: 5 additions & 2 deletions cmd/s3-authmate/main.go
Original file line number Diff line number Diff line change
@@ -573,11 +573,14 @@ func obtainSecret() *cli.Command {
ctx, tcancel = context.WithTimeout(ctx, timeoutFlag)
defer tcancel()

if err = agent.ObtainSecret(ctx, os.Stdout, obtainSecretOptions); err != nil {
or, err := agent.ObtainSecret(ctx, obtainSecretOptions)
if err != nil {
return cli.Exit(fmt.Sprintf("failed to obtain secret: %s", err), 5)
}

return nil
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
return enc.Encode(or)
},
}
return command

0 comments on commit 4a5f90b

Please sign in to comment.