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