mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Add login command to log in to a Portainer instance
This commit is contained in:
parent
53d26a8ac3
commit
6200b6c667
@ -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
34
cmd/login.go
Normal 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"))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user