/
secret_remove.go
executable file
·70 lines (57 loc) · 2.04 KB
/
secret_remove.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// 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 (
"context"
"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")
secretRemoveCmd.Flags().StringVarP(&functionNamespace, "namespace", "n", "", "Namespace of the function")
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],
Namespace: functionNamespace,
}
cliAuth := NewCLIAuth(token, gatewayAddress)
transport := GetDefaultCLITransport(tlsInsecure, &commandTimeout)
client := proxy.NewClient(cliAuth, gatewayAddress, transport, &commandTimeout)
err := client.RemoveSecret(context.Background(), secret)
if err != nil {
return err
}
fmt.Print("Removed.. OK.\n")
return nil
}