cmd/uplinkng: add register command
Change-Id: I9add258249c618e804e3b006dc1afc5325019009
This commit is contained in:
parent
75acd6109d
commit
7fba79be3f
55
cmd/uplinkng/cmd_access_register.go
Normal file
55
cmd/uplinkng/cmd_access_register.go
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright (C) 2021 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/zeebo/clingy"
|
||||
|
||||
"storj.io/storj/cmd/uplinkng/ulext"
|
||||
)
|
||||
|
||||
type cmdAccessRegister struct {
|
||||
ex ulext.External
|
||||
|
||||
accessNameOrValue *string
|
||||
authService string
|
||||
public bool
|
||||
format string
|
||||
awsProfile string
|
||||
}
|
||||
|
||||
func newCmdAccessRegister(ex ulext.External) *cmdAccessRegister {
|
||||
return &cmdAccessRegister{ex: ex}
|
||||
}
|
||||
|
||||
func (c *cmdAccessRegister) Setup(params clingy.Parameters) {
|
||||
c.accessNameOrValue = params.Arg("access", "The name or value of the access grant we're registering with the auth service", clingy.Optional).(*string)
|
||||
c.authService = params.Flag("auth-service", "The address to the service you wish to register your access with", "https://auth.us1.storjshare.io").(string)
|
||||
c.public = params.Flag("public", "If true, the access will be public", false, clingy.Transform(strconv.ParseBool)).(bool)
|
||||
c.format = params.Flag("format", "Format of the output credentials, use 'env' or 'aws' when using in scripts", "").(string)
|
||||
c.awsProfile = params.Flag("aws-profile", "If using --format=aws, output the --profile tag using this profile", "").(string)
|
||||
|
||||
params.Break()
|
||||
}
|
||||
|
||||
func (c *cmdAccessRegister) Execute(ctx clingy.Context) (err error) {
|
||||
accessNameOrValue := ""
|
||||
if c.accessNameOrValue != nil && len(*c.accessNameOrValue) > 0 {
|
||||
accessNameOrValue = *c.accessNameOrValue
|
||||
}
|
||||
|
||||
access, err := c.ex.OpenAccess(accessNameOrValue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
accessKey, secretKey, endpoint, err := RegisterAccess(ctx, access, c.authService, c.public, defaultAccessRegisterTimeout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return DisplayGatewayCredentials(ctx, accessKey, secretKey, endpoint, c.format, c.awsProfile)
|
||||
}
|
@ -45,6 +45,7 @@ func commands(cmds clingy.Commands, ex ulext.External) {
|
||||
cmds.New("use", "Set default access to use", newCmdAccessUse(ex))
|
||||
cmds.New("revoke", "Revoke an access", newCmdAccessRevoke(ex))
|
||||
cmds.New("inspect", "Inspect allows you to explode a serialized access into its constituent parts", newCmdAccessInspect(ex))
|
||||
cmds.New("register", "Register an access grant for use with a hosted S3 compatible gateway and linksharing", newCmdAccessRegister(ex))
|
||||
})
|
||||
cmds.New("share", "Shares restricted accesses to objects", newCmdShare(ex))
|
||||
cmds.New("mb", "Create a new bucket", newCmdMb(ex))
|
||||
|
Loading…
Reference in New Issue
Block a user