This commit updates the secret commands to use `Secret` struct from the faas-provider rather than using it's own struct. Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
// Copyright (c) OpenFaaS Author(s) 2019. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/openfaas/faas-cli/proxy"
|
|
types "github.com/openfaas/faas-provider/types"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var secretRemoveCmd = &cobra.Command{
|
|
Use: "remove [--tls-no-verify]",
|
|
Aliases: []string{"rm"},
|
|
Short: "remove a secret",
|
|
Long: `Remove a secret by name`,
|
|
Example: `faas-cli secret remove NAME
|
|
faas-cli secret remove NAME --gateway=http://127.0.0.1:8080`,
|
|
RunE: runSecretRemove,
|
|
PreRunE: preRunSecretRemoveCmd,
|
|
}
|
|
|
|
func init() {
|
|
secretRemoveCmd.Flags().StringVarP(&gateway, "gateway", "g", defaultGateway, "Gateway URL starting with http(s)://")
|
|
secretRemoveCmd.Flags().BoolVar(&tlsInsecure, "tls-no-verify", false, "Disable TLS validation")
|
|
secretRemoveCmd.Flags().StringVarP(&token, "token", "k", "", "Pass a JWT token to use instead of basic auth")
|
|
secretCmd.AddCommand(secretRemoveCmd)
|
|
}
|
|
|
|
func preRunSecretRemoveCmd(cmd *cobra.Command, args []string) error {
|
|
if len(args) == 0 {
|
|
return fmt.Errorf("secret name required")
|
|
}
|
|
|
|
if len(args) > 1 {
|
|
return fmt.Errorf("too many values for secret name")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func runSecretRemove(cmd *cobra.Command, args []string) error {
|
|
var gatewayAddress string
|
|
gatewayAddress = getGatewayURL(gateway, defaultGateway, "", os.Getenv(openFaaSURLEnvironment))
|
|
|
|
if msg := checkTLSInsecure(gatewayAddress, tlsInsecure); len(msg) > 0 {
|
|
fmt.Println(msg)
|
|
}
|
|
|
|
secret := types.Secret{
|
|
Name: args[0],
|
|
}
|
|
err := proxy.RemoveSecretToken(gatewayAddress, secret, tlsInsecure, token)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Print("Removed.. OK.\n")
|
|
|
|
return nil
|
|
}
|