2021-11-25 12:53:52 +00:00
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"strconv"
"github.com/zeebo/clingy"
2022-01-06 19:55:46 +00:00
"storj.io/storj/cmd/uplink/ulext"
2021-11-25 12:53:52 +00:00
)
type cmdAccessRegister struct {
ex ulext . External
accessNameOrValue * string
authService string
2022-01-27 15:57:46 +00:00
caCert string
2021-11-25 12:53:52 +00:00
public bool
format string
awsProfile string
}
func newCmdAccessRegister ( ex ulext . External ) * cmdAccessRegister {
return & cmdAccessRegister { ex : ex }
}
func ( c * cmdAccessRegister ) Setup ( params clingy . Parameters ) {
2022-05-16 17:04:25 +01:00
c . authService = params . Flag ( "auth-service" , "The address to the service you wish to register your access with" , "auth.storjshare.io:7777" ) . ( string )
2022-01-27 15:57:46 +00:00
c . caCert = params . Flag ( "ca-cert" , "path to a file in PEM format with certificate(s) or certificate chain(s) to validate the auth service against" , "" ) . ( string )
2021-11-25 12:53:52 +00:00
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 )
2022-01-10 22:07:15 +00:00
c . accessNameOrValue = params . Arg ( "access" , "The name or value of the access grant we're registering with the auth service" , clingy . Optional ) . ( * string )
2021-11-25 12:53:52 +00:00
}
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
}
2022-01-27 15:57:46 +00:00
credentials , err := RegisterAccess ( ctx , access , c . authService , c . public , c . caCert )
2021-11-25 12:53:52 +00:00
if err != nil {
return err
}
2022-01-27 15:57:46 +00:00
return DisplayGatewayCredentials ( ctx , * credentials , c . format , c . awsProfile )
2021-11-25 12:53:52 +00:00
}