Skip to content

Instantly share code, notes, and snippets.

@eriknelson
Created October 11, 2017 18:55
Show Gist options
  • Save eriknelson/0eaca1b3eb5659371bd009ce1954e7b5 to your computer and use it in GitHub Desktop.
Save eriknelson/0eaca1b3eb5659371bd009ce1954e7b5 to your computer and use it in GitHub Desktop.
diff --git a/pkg/broker/broker.go b/pkg/broker/broker.go
index 4064d314..eeb8f4d8 100644
--- a/pkg/broker/broker.go
+++ b/pkg/broker/broker.go
@@ -277,6 +277,7 @@ func (a AnsibleBroker) Bootstrap() (*BootstrapResponse, error) {
for _, p := range s.Plans {
if p.ID == "" {
a.log.Errorf("We have a plan that did not get its id generated: %v", p.Name)
+ continue
}
planNameManifest[p.ID] = p.Name
}
@@ -318,16 +319,20 @@ func addNameAndIDForSpec(specs []*apb.Spec, registryName string) {
// update the id on the plans, doing it here avoids looping through the
// specs array again
- addIDForPlan(spec.Plans)
+ addIDForPlan(spec.Plans, spec.FQName)
}
}
// addIDForPlan - for each of the plans create a new ID
-func addIDForPlan(plans []apb.Plan) {
+func addIDForPlan(plans []apb.Plan, FQSpecName string) {
// need to use the index into the array to actually update the struct.
- for i := range plans {
- plans[i].ID = uuid.New()
+ for i, plan := range plans {
+ //plans[i].ID = uuid.New()
+ FQPlanName := fmt.Sprintf("%s-%s", FQSpecName, plan.Name)
+ hasher := md5.New()
+ hasher.Write([]byte(FQPlanName))
+ plans[i].ID = hex.EncodeToString(hasher.Sum(nil))
}
}
diff --git a/pkg/broker/broker_test.go b/pkg/broker/broker_test.go
index 6be2ab78..51213c5f 100644
--- a/pkg/broker/broker_test.go
+++ b/pkg/broker/broker_test.go
@@ -65,6 +65,6 @@ func TestAddNameAndIDForSpecStripsTailingDash(t *testing.T) {
func TestAddIdForPlan(t *testing.T) {
plan1 := apb.Plan{Name: "default"}
plans := []apb.Plan{plan1}
- addIDForPlan(plans)
+ addIDForPlan(plans, "dh-sns-apb")
ft.AssertNotEqual(t, plans[0].ID, "", "plan id not updated")
}
diff --git a/pkg/broker/util_test.go b/pkg/broker/util_test.go
index d60b4ebe..2ab72cb2 100644
--- a/pkg/broker/util_test.go
+++ b/pkg/broker/util_test.go
@@ -29,7 +29,6 @@ import (
schema "github.com/lestrrat/go-jsschema"
"github.com/openshift/ansible-service-broker/pkg/apb"
ft "github.com/openshift/ansible-service-broker/pkg/fusortest"
- "github.com/pborman/uuid"
yaml "gopkg.in/yaml.v2"
)
@@ -102,7 +101,7 @@ var PlanBindParams = []apb.ParameterDescriptor{
}
var p = apb.Plan{
- ID: "50eb5637-6ffe-480d-a52e-a7e603a50fca",
+ ID: "55822a921d2c4858fe6e58f5522429c2", // md5(dh-sns-apb-dev)
Name: PlanName,
Description: PlanDescription,
Metadata: PlanMetadata,
@@ -157,8 +156,7 @@ func TestSpecToService(t *testing.T) {
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, "50eb5637-6ffe-480d-a52e-a7e603a50fca", "plan id didn't match")
- ft.AssertNotNil(t, uuid.Parse(svc.Plans[0].ID), "plan id is a valid uuid")
+ ft.AssertEqual(t, svc.Plans[0].ID, "55822a921d2c4858fe6e58f5522429c2", "plan id 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