Skip to content

Instantly share code, notes, and snippets.

@eriknelson
Created October 11, 2017 15:22
Show Gist options
  • Save eriknelson/b40c495f9eed433195c0228c226a6924 to your computer and use it in GitHub Desktop.
Save eriknelson/b40c495f9eed433195c0228c226a6924 to your computer and use it in GitHub Desktop.
diff --git a/pkg/apb/secrets.go b/pkg/apb/secrets.go
index 8b856e9c..d4f2a627 100644
--- a/pkg/apb/secrets.go
+++ b/pkg/apb/secrets.go
@@ -103,11 +103,11 @@ func InitializeSecretsCache(config []SecretsConfig, log *logging.Logger) {
// FilterSecrets - Filters all parameters masked by a secret out of the given
// specs
-func FilterSecrets(inSpecs []*Spec) ([]*Spec, error) {
+func FilterSecrets(inSpecs []*Spec, config ClusterConfig) ([]*Spec, error) {
for _, spec := range inSpecs {
secrets.log.Debugf("Filtering secrets from spec %v", spec.FQName)
for _, secret := range GetSecrets(spec) {
- secretKeys, err := getSecretKeys(secret)
+ secretKeys, err := getSecretKeys(secret, config.Namespace)
if err != nil {
return nil, err
}
@@ -150,13 +150,13 @@ func paramInSecret(param ParameterDescriptor, secretKeys []string) bool {
return false
}
-func getSecretKeys(secretName string) ([]string, error) {
+func getSecretKeys(secretName, namespace string) ([]string, error) {
k8scli, err := clients.Kubernetes(secrets.log)
if err != nil {
return nil, err
}
- secretData, err := k8scli.CoreV1().Secrets("ansible-service-broker").Get(secretName, meta_v1.GetOptions{})
+ secretData, err := k8scli.CoreV1().Secrets(namespace).Get(secretName, meta_v1.GetOptions{})
if err != nil {
secrets.log.Warningf("Unable to load secret '%s' from namespace 'ansible-service-broker'", secretName)
return []string{}, nil
diff --git a/pkg/broker/broker.go b/pkg/broker/broker.go
index 9807f467..706a829e 100644
--- a/pkg/broker/broker.go
+++ b/pkg/broker/broker.go
@@ -429,7 +429,7 @@ func (a AnsibleBroker) Catalog() (*CatalogResponse, error) {
}
a.log.Debugf("Filtering secret parameters out of specs...")
- specs, err = apb.FilterSecrets(specs)
+ specs, err = apb.FilterSecrets(specs, a.clusterConfig)
if err != nil {
// TODO: Should we blow up or warn and continue?
a.log.Errorf("Something went real bad trying to load secrets %v", err)
@@ -539,10 +539,13 @@ func (a AnsibleBroker) Provision(instanceUUID uuid.UUID, req *ProvisionRequest,
return nil, errors.New(errMsg)
}
+ planName, _ /* err */ := extractNameFromPlanID(req.PlanID)
+ //if err != nil { return ERROR } // TODO
+
a.log.Debugf(
"Injecting PlanID as parameter: { %s: %s }",
- planParameterKey, req.PlanID)
- parameters[planParameterKey] = req.PlanID
+ planParameterKey, planName)
+ parameters[planParameterKey] = planName
// Build and persist record of service instance
serviceInstance := &apb.ServiceInstance{
@@ -707,10 +710,13 @@ func (a AnsibleBroker) Bind(instance apb.ServiceInstance, bindingUUID uuid.UUID,
return nil, errors.New(errMsg)
}
+ planName, _ /* err */ := extractNameFromPlanID(req.PlanID)
+ //if err != nil { return ERROR } // TODO
+
a.log.Debugf(
"Injecting PlanID as parameter: { %s: %s }",
- planParameterKey, req.PlanID)
- params[planParameterKey] = req.PlanID
+ planParameterKey, planName)
+ params[planParameterKey] = planName
// Create a BindingInstance with a reference to the serviceinstance.
bindingInstance := &apb.BindInstance{
@@ -959,3 +965,11 @@ func ocLogin(log *logging.Logger, args ...string) error {
}
return nil
}
+
+func extractNameFromPlanID(planID string) (string, error) {
+ splitPlan := strings.Split(planID, "-")
+
+ // TOOD: Error Handling
+ planName := splitPlan[len(splitPlan)-1]
+ return planName, nil
+}
diff --git a/pkg/broker/util.go b/pkg/broker/util.go
index 9af48dbd..84c79225 100644
--- a/pkg/broker/util.go
+++ b/pkg/broker/util.go
@@ -46,7 +46,7 @@ func SpecToService(spec *apb.Spec) Service {
Description: spec.Description,
Tags: make([]string, len(spec.Tags)),
Bindable: spec.Bindable,
- Plans: toBrokerPlans(spec.Plans),
+ Plans: toBrokerPlans(spec.FQName, spec.Plans),
Metadata: spec.Metadata,
}
@@ -54,12 +54,13 @@ func SpecToService(spec *apb.Spec) Service {
return retSvc
}
-func toBrokerPlans(apbPlans []apb.Plan) []Plan {
+func toBrokerPlans(fqname string, apbPlans []apb.Plan) []Plan {
brokerPlans := make([]Plan, len(apbPlans))
i := 0
for _, plan := range apbPlans {
+ genID := fmt.Sprintf("%v-%v", fqname, plan.Name)
brokerPlans[i] = Plan{
- ID: plan.Name,
+ ID: genID,
Name: plan.Name,
Description: plan.Description,
Metadata: extractBrokerPlanMetadata(plan),
diff --git a/pkg/broker/util_test.go b/pkg/broker/util_test.go
index aa81d0d3..ecd6baf2 100644
--- a/pkg/broker/util_test.go
+++ b/pkg/broker/util_test.go
@@ -22,6 +22,7 @@ package broker
import (
"encoding/base64"
+ "fmt"
"testing"
"strings"
@@ -149,10 +150,14 @@ func TestSpecToService(t *testing.T) {
Plans: nil,
Metadata: descriptors,
}
+ expectedplanname := fmt.Sprintf("%v-%v", spec.FQName, p.Name)
+
svc := SpecToService(&spec)
+
ft.AssertEqual(t, svc.Name, expectedsvc.Name, "name is not equal")
ft.AssertEqual(t, svc.Description, expectedsvc.Description, "description is not equal")
ft.AssertEqual(t, svc.Bindable, expectedsvc.Bindable, "bindable wrong")
+ ft.AssertEqual(t, svc.Plans[0].ID, expectedplanname, "plan name didn't match")
}
func TestUpdateMetadata(t *testing.T) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment