Use Secret struct from faas-provider
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>
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/openfaas/faas-cli/proxy"
|
||||
"github.com/openfaas/faas-cli/schema"
|
||||
types "github.com/openfaas/faas-provider/types"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -68,7 +68,7 @@ func preRunSecretCreate(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func runSecretCreate(cmd *cobra.Command, args []string) error {
|
||||
secret := schema.Secret{
|
||||
secret := types.Secret{
|
||||
Name: args[0],
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/openfaas/faas-cli/proxy"
|
||||
"github.com/openfaas/faas-cli/schema"
|
||||
types "github.com/openfaas/faas-provider/types"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -61,7 +61,7 @@ func runSecretList(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func renderSecretList(secrets []schema.Secret) string {
|
||||
func renderSecretList(secrets []types.Secret) string {
|
||||
var b bytes.Buffer
|
||||
w := tabwriter.NewWriter(&b, 0, 0, 1, ' ', 0)
|
||||
fmt.Fprintln(w)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/openfaas/faas-cli/proxy"
|
||||
"github.com/openfaas/faas-cli/schema"
|
||||
types "github.com/openfaas/faas-provider/types"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -49,7 +49,7 @@ func runSecretRemove(cmd *cobra.Command, args []string) error {
|
||||
fmt.Println(msg)
|
||||
}
|
||||
|
||||
secret := schema.Secret{
|
||||
secret := types.Secret{
|
||||
Name: args[0],
|
||||
}
|
||||
err := proxy.RemoveSecretToken(gatewayAddress, secret, tlsInsecure, token)
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/openfaas/faas-cli/proxy"
|
||||
"github.com/openfaas/faas-cli/schema"
|
||||
types "github.com/openfaas/faas-provider/types"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -60,7 +60,7 @@ func runSecretUpdate(cmd *cobra.Command, args []string) error {
|
||||
fmt.Println(msg)
|
||||
}
|
||||
|
||||
secret := schema.Secret{
|
||||
secret := types.Secret{
|
||||
Name: args[0],
|
||||
}
|
||||
|
||||
|
||||
@@ -8,17 +8,17 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/openfaas/faas-cli/schema"
|
||||
types "github.com/openfaas/faas-provider/types"
|
||||
)
|
||||
|
||||
// GetSecretList get secrets list
|
||||
func GetSecretList(gateway string, tlsInsecure bool) ([]schema.Secret, error) {
|
||||
func GetSecretList(gateway string, tlsInsecure bool) ([]types.Secret, error) {
|
||||
return GetSecretListToken(gateway, tlsInsecure, "")
|
||||
}
|
||||
|
||||
// GetSecretListToken get secrets lists with taken as auth
|
||||
func GetSecretListToken(gateway string, tlsInsecure bool, token string) ([]schema.Secret, error) {
|
||||
var results []schema.Secret
|
||||
func GetSecretListToken(gateway string, tlsInsecure bool, token string) ([]types.Secret, error) {
|
||||
var results []types.Secret
|
||||
|
||||
gateway = strings.TrimRight(gateway, "/")
|
||||
client := MakeHTTPClient(&defaultCommandTimeout, tlsInsecure)
|
||||
@@ -70,12 +70,12 @@ func GetSecretListToken(gateway string, tlsInsecure bool, token string) ([]schem
|
||||
}
|
||||
|
||||
// UpdateSecret update a secret via the OpenFaaS API by name
|
||||
func UpdateSecret(gateway string, secret schema.Secret, tlsInsecure bool) (int, string) {
|
||||
func UpdateSecret(gateway string, secret types.Secret, tlsInsecure bool) (int, string) {
|
||||
return UpdateSecretToken(gateway, secret, tlsInsecure, "")
|
||||
}
|
||||
|
||||
// UpdateSecretToken update a secret with token as auth
|
||||
func UpdateSecretToken(gateway string, secret schema.Secret, tlsInsecure bool, token string) (int, string) {
|
||||
func UpdateSecretToken(gateway string, secret types.Secret, tlsInsecure bool, token string) (int, string) {
|
||||
var output string
|
||||
|
||||
gateway = strings.TrimRight(gateway, "/")
|
||||
@@ -127,12 +127,12 @@ func UpdateSecretToken(gateway string, secret schema.Secret, tlsInsecure bool, t
|
||||
}
|
||||
|
||||
// RemoveSecret remove a secret via the OpenFaaS API by name
|
||||
func RemoveSecret(gateway string, secret schema.Secret, tlsInsecure bool) error {
|
||||
func RemoveSecret(gateway string, secret types.Secret, tlsInsecure bool) error {
|
||||
return RemoveSecretToken(gateway, secret, tlsInsecure, "")
|
||||
}
|
||||
|
||||
// RemoveSecretToken remove a secret with token as auth
|
||||
func RemoveSecretToken(gateway string, secret schema.Secret, tlsInsecure bool, token string) error {
|
||||
func RemoveSecretToken(gateway string, secret types.Secret, tlsInsecure bool, token string) error {
|
||||
|
||||
gateway = strings.TrimRight(gateway, "/")
|
||||
client := MakeHTTPClient(&defaultCommandTimeout, tlsInsecure)
|
||||
@@ -179,12 +179,12 @@ func RemoveSecretToken(gateway string, secret schema.Secret, tlsInsecure bool, t
|
||||
}
|
||||
|
||||
// CreateSecret create secret
|
||||
func CreateSecret(gateway string, secret schema.Secret, tlsInsecure bool) (int, string) {
|
||||
func CreateSecret(gateway string, secret types.Secret, tlsInsecure bool) (int, string) {
|
||||
return CreateSecretToken(gateway, secret, tlsInsecure, "")
|
||||
}
|
||||
|
||||
// CreateSecretToken create secret with token as auth
|
||||
func CreateSecretToken(gateway string, secret schema.Secret, tlsInsecure bool, token string) (int, string) {
|
||||
func CreateSecretToken(gateway string, secret types.Secret, tlsInsecure bool, token string) (int, string) {
|
||||
var output string
|
||||
|
||||
gateway = strings.TrimRight(gateway, "/")
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/openfaas/faas-cli/schema"
|
||||
"github.com/openfaas/faas-cli/test"
|
||||
types "github.com/openfaas/faas-provider/types"
|
||||
)
|
||||
|
||||
func Test_GetSecretList_200OK(t *testing.T) {
|
||||
@@ -81,7 +81,7 @@ func Test_GetSecretList_Unauthorized401(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var expectedSecretList = []schema.Secret{
|
||||
var expectedSecretList = []types.Secret{
|
||||
{
|
||||
Name: "Secret1",
|
||||
},
|
||||
@@ -92,7 +92,7 @@ var expectedSecretList = []schema.Secret{
|
||||
|
||||
func Test_CreateSecret_200OK(t *testing.T) {
|
||||
s := test.MockHttpServerStatus(t, http.StatusOK)
|
||||
secret := schema.Secret{
|
||||
secret := types.Secret{
|
||||
Name: "secret-name",
|
||||
Value: "secret-value",
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func Test_CreateSecret_200OK(t *testing.T) {
|
||||
|
||||
func Test_CreateSecret_201Created(t *testing.T) {
|
||||
s := test.MockHttpServerStatus(t, http.StatusCreated)
|
||||
secret := schema.Secret{
|
||||
secret := types.Secret{
|
||||
Name: "secret-name",
|
||||
Value: "secret-value",
|
||||
}
|
||||
@@ -120,7 +120,7 @@ func Test_CreateSecret_201Created(t *testing.T) {
|
||||
|
||||
func Test_CreateSecret_202Accepted(t *testing.T) {
|
||||
s := test.MockHttpServerStatus(t, http.StatusAccepted)
|
||||
secret := schema.Secret{
|
||||
secret := types.Secret{
|
||||
Name: "secret-name",
|
||||
Value: "secret-value",
|
||||
}
|
||||
@@ -135,7 +135,7 @@ func Test_CreateSecret_202Accepted(t *testing.T) {
|
||||
func Test_CreateSecret_Not200(t *testing.T) {
|
||||
s := test.MockHttpServerStatus(t, http.StatusBadRequest)
|
||||
|
||||
secret := schema.Secret{
|
||||
secret := types.Secret{
|
||||
Name: "secret-name",
|
||||
Value: "secret-value",
|
||||
}
|
||||
@@ -154,7 +154,7 @@ func Test_CreateSecret_Not200(t *testing.T) {
|
||||
func Test_CreateSecret_Unauthorized401(t *testing.T) {
|
||||
s := test.MockHttpServerStatus(t, http.StatusUnauthorized)
|
||||
|
||||
secret := schema.Secret{
|
||||
secret := types.Secret{
|
||||
Name: "secret-name",
|
||||
Value: "secret-value",
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func Test_CreateSecret_Unauthorized401(t *testing.T) {
|
||||
func Test_CreateSecret_Conflict409(t *testing.T) {
|
||||
s := test.MockHttpServerStatus(t, http.StatusConflict)
|
||||
|
||||
secret := schema.Secret{
|
||||
secret := types.Secret{
|
||||
Name: "secret-name",
|
||||
Value: "secret-value",
|
||||
}
|
||||
|
||||
@@ -11,9 +11,3 @@ type KubernetesSecretMetadata struct {
|
||||
Name string `json:"name"`
|
||||
Namespace string `json:"namespace"`
|
||||
}
|
||||
|
||||
//Secret secret type
|
||||
type Secret struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user