Add login command to log in to a Portainer instance

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-07-23 22:12:45 -04:00
parent 53d26a8ac3
commit 6200b6c667
2 changed files with 35 additions and 0 deletions

View File

@ -10,6 +10,7 @@ ENV PSU_AUTHENTICATION_PASSWORD="" \
PSU_CONNECTION_URL="" \ PSU_CONNECTION_URL="" \
PSU_DEBUG="" \ PSU_DEBUG="" \
PSU_ENDPOINT_LIST_FORMAT="" \ PSU_ENDPOINT_LIST_FORMAT="" \
PSU_LOGIN_PRINT="" \
PSU_STACK_DEPLOY_ENDPOINT="" \ PSU_STACK_DEPLOY_ENDPOINT="" \
PSU_STACK_DEPLOY_ENV_FILE="" \ PSU_STACK_DEPLOY_ENV_FILE="" \
PSU_STACK_DEPLOY_REPLACE_ENV="" \ PSU_STACK_DEPLOY_REPLACE_ENV="" \

34
cmd/login.go Normal file
View File

@ -0,0 +1,34 @@
package cmd
import (
"fmt"
"github.com/greenled/portainer-stack-utils/common"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// loginCmd represents the login command
var loginCmd = &cobra.Command{
Use: "login",
Short: "Log in to a Portainer instance",
Run: func(cmd *cobra.Command, args []string) {
// Get auth token
authToken, authenticationTokenRetrievalError := common.GetNewAuthenticationToken()
common.CheckError(authenticationTokenRetrievalError)
if viper.GetBool("login.print") {
fmt.Println(authToken)
}
// Save auth token
configSettingErr := setConfig("auth-token", authToken)
common.CheckError(configSettingErr)
},
}
func init() {
rootCmd.AddCommand(loginCmd)
loginCmd.Flags().Bool("print", false, "prints retrieved auth token")
viper.BindPFlag("login.print", loginCmd.Flags().Lookup("print"))
}