Skip to content

Commit

Permalink
remove excludedservices
Browse files Browse the repository at this point in the history
  • Loading branch information
philbrookes committed Apr 17, 2018
1 parent 8b6de4c commit fc8d253
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 152 deletions.
13 changes: 3 additions & 10 deletions artifacts/mobileclient_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ spec:
shortNames:
- mc
validation:
# openAPIV3Schema is the schema for validating custom objects. k8s 1.9
# openAPIV3Schema is the schema for validating custom objects.
openAPIV3Schema:
required:
- clientType
- name
- appIdentifier
properties:
spec:
properties:
Expand All @@ -30,10 +26,7 @@ spec:
pattern: '(\w{8}-\w{4}-\w{4}-\w{4}-\w{11})'
name:
type: string
pattern: '(\w-)'
pattern: '([\w-])'
appIdentifier:
type: string
excludedServices:
type: array
items:
type: string
pattern: '([\w-])'
9 changes: 4 additions & 5 deletions pkg/apis/mobile/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ type MobileClientList struct {
}

type MobileClientSpec struct {
Name string `json:"name"`
ApiKey string `json:"apiKey"`
ClientType string `json:"clientType"`
AppIdentifier string `json:"appIdentifier"`
ExcludedServices []string `json:"excludedServices"`
Name string `json:"name"`
ApiKey string `json:"apiKey"`
ClientType string `json:"clientType"`
AppIdentifier string `json:"appIdentifier"`
}

// +genclient
Expand Down
19 changes: 0 additions & 19 deletions pkg/cmd/clientConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package cmd
import (
"fmt"
"io"
"strings"

mobile "github.com/aerogear/mobile-cli/pkg/client/mobile/clientset/versioned"
sc "github.com/aerogear/mobile-cli/pkg/client/servicecatalog/clientset/versioned"
Expand All @@ -27,7 +26,6 @@ import (
"github.com/spf13/cobra"
kerror "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)

Expand Down Expand Up @@ -79,28 +77,11 @@ kubectl plugin mobile get clientconfig`,
return err
}

client, err := ccc.mobileClient.MobileV1alpha1().MobileClients(ns).Get(clientID, metav1.GetOptions{})
if err != nil {
return errors.Wrap(err, "failed to get mobile client with clientID "+clientID)
}

ms := listServices(ns, ccc.k8Client)
for _, svc := range ms {
var svcConfig *ServiceConfig
var err error
includedService := true
for _, excluded := range client.Spec.ExcludedServices {
catalogService, err := ccc.scClient.ServicecatalogV1beta1().ServiceInstances(ns).Get(excluded, v1.GetOptions{})
if kerror.IsNotFound(err) {
continue
} else if err != nil {
return err
}
if strings.TrimSpace(catalogService.Labels["serviceName"]) == strings.TrimSpace(svc.Name) {
includedService = false
break
}
}
configMap, err := ccc.k8Client.CoreV1().ConfigMaps(ns).Get(svc.Name, v1.GetOptions{})
// ignoring not found as some services will not have this public configmap
if err != nil {
Expand Down
114 changes: 0 additions & 114 deletions pkg/cmd/clientConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (

"regexp"

"github.com/aerogear/mobile-cli/pkg/apis/mobile/v1alpha1"
"github.com/aerogear/mobile-cli/pkg/apis/servicecatalog/v1beta1"
mobile "github.com/aerogear/mobile-cli/pkg/client/mobile/clientset/versioned"
mcFake "github.com/aerogear/mobile-cli/pkg/client/mobile/clientset/versioned/fake"
"github.com/aerogear/mobile-cli/pkg/client/servicecatalog/clientset/versioned"
Expand All @@ -34,7 +32,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
kFake "k8s.io/client-go/kubernetes/fake"
kt "k8s.io/client-go/testing"
ktesting "k8s.io/client-go/testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -213,117 +210,6 @@ func TestClientConfigCmd_GetClientConfigCmd(t *testing.T) {
"config": {}
}
]
}`
if strings.TrimSpace(out.String()) != expected {
return errors.New(fmt.Sprintf("expected: '%v', got: '%v'", expected, strings.TrimSpace(out.String())))
}
return nil
},
},
{
name: "get client config command with excluded services",
k8Client: func() kubernetes.Interface {
fakeclient := &kFake.Clientset{}
fakeclient.AddReactor("list", "secrets", func(action ktesting.Action) (handled bool, ret runtime.Object, err error) {
secrets := []v1.Secret{
{
ObjectMeta: metav1.ObjectMeta{
Name: "test-service",
Labels: map[string]string{
"mobile": "enabled",
},
},
Data: map[string][]byte{
"name": []byte("test-service"),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "keycloak",
Labels: map[string]string{
"mobile": "enabled",
},
},
Data: map[string][]byte{
"name": []byte("keycloak"),
},
},
}
secretList := &v1.SecretList{
Items: secrets,
}
return true, secretList, nil
})
fakeclient.AddReactor("get", "configmaps", func(action ktesting.Action) (handled bool, ret runtime.Object, err error) {
var config *v1.ConfigMap
name := action.(ktesting.GetAction).GetName()
if name == "keycloak" {
config = &v1.ConfigMap{
Data: map[string]string{
"public_installation": "{}",
"name": "keycloak",
},
}
}
if name == "test-service" {
config = &v1.ConfigMap{
Data: map[string]string{
"name": "test-service",
},
}
}
return true, config, nil
})
return fakeclient
},
mobileClient: func() mobile.Interface {
mf := &mcFake.Clientset{}
mf.AddReactor("get", "mobileclients", func(action kt.Action) (handled bool, ret runtime.Object, err error) {
return true, &v1alpha1.MobileClient{
Spec: v1alpha1.MobileClientSpec{
Name: "test",
ApiKey: "testkey",
ClientType: "cordova",
ExcludedServices: []string{"dh-keycloak-fsdfsdfs"},
},
}, nil
})
return mf
},
SvcCatalogClient: func() versioned.Interface {
fake := &scFake.Clientset{}
fake.AddReactor("get", "serviceinstances", func(action kt.Action) (handled bool, ret runtime.Object, err error) {
return true, &v1beta1.ServiceInstance{
ObjectMeta: metav1.ObjectMeta{
Name: "dh-keycloak-fsdfsdfs",
Labels: map[string]string{
"serviceName": "keycloak",
},
},
}, nil
})
return fake
},
namespace: "testing-ns",
ClusterHost: "test",
args: []string{"client-id"},
cobraCmd: getFakeCbrCmd(),
ExpectError: false,
ValidateOut: func(out bytes.Buffer) error {
expected := `{
"version": 1,
"clusterName": "test",
"namespace": "testing-ns",
"clientId": "client-id",
"services": [
{
"id": "test-service",
"name": "test-service",
"type": "",
"url": "",
"config": {}
}
]
}`
if strings.TrimSpace(out.String()) != expected {
return errors.New(fmt.Sprintf("expected: '%v', got: '%v'", expected, strings.TrimSpace(out.String())))
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (cc *ClientCmd) ListClientsCmd() *cobra.Command {
mClients := mobileClientList.(*v1alpha1.MobileClientList)
var data [][]string
for _, mClient := range mClients.Items {
data = append(data, []string{mClient.Name, mClient.Spec.Name, mClient.Spec.ClientType, mClient.Spec.AppIdentifier, strings.Join(mClient.Spec.ExcludedServices, ", ")})
data = append(data, []string{mClient.Name, mClient.Spec.Name, mClient.Spec.ClientType, mClient.Spec.AppIdentifier})
}
table := tablewriter.NewWriter(out)
table.AppendBulk(data)
Expand Down Expand Up @@ -113,7 +113,7 @@ Run the "mobile get clients" command from this tool to get the client ID.`,
cc.Out.AddRenderer(command.Name(), "table", func(out io.Writer, mobileClient interface{}) error {
mClient := mobileClient.(*v1alpha1.MobileClient)
var data [][]string
data = append(data, []string{mClient.Name, mClient.Namespace, mClient.Spec.Name, mClient.Spec.ClientType, mClient.Spec.ApiKey, mClient.Spec.AppIdentifier, strings.Join(mClient.Spec.ExcludedServices, ", ")})
data = append(data, []string{mClient.Name, mClient.Namespace, mClient.Spec.Name, mClient.Spec.ClientType, mClient.Spec.ApiKey, mClient.Spec.AppIdentifier})
table := tablewriter.NewWriter(out)
table.AppendBulk(data)
table.SetHeader([]string{"ID", "Namespace", "Name", "ClientType", "ApiKey", "AppIdentifier", "Excluded Services"})
Expand Down Expand Up @@ -180,7 +180,7 @@ When used standalone, a namespace must be specified by providing the --namespace
}
app.Name = name + "-" + strings.ToLower(app.Spec.ClientType)
if err := input.ValidateMobileClient(app); err != nil {
return errors.Wrap(err, "Failed validation while creating new mobile client")
return errors.Wrap(err, "failed validation while creating new mobile client")
}
createdClient, err := cc.mobileClient.MobileV1alpha1().MobileClients(namespace).Create(app)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ func TestMobileClientsCmd_TestCreateClient(t *testing.T) {
Name: "test create mobile client fails when there is no appIdentifier",
Args: []string{"test", "android", ""},
ExpectError: true,
ErrorPattern: "^Failed validation while creating new mobile client: .*",
ErrorPattern: "^failed validation while creating new mobile client: .*",
MobileClient: func() mc.Interface {
fkMc := &mcFake.Clientset{}
fkMc.AddReactor("create", "mobileclients", func(action kt.Action) (handled bool, ret runtime.Object, err error) {
Expand Down

0 comments on commit fc8d253

Please sign in to comment.