[ISSUE-67600349] use uuid utils provided in apid-core (#66)
diff --git a/apigee_sync_test.go b/apigee_sync_test.go index 9a6bf6b..b0fead6 100644 --- a/apigee_sync_test.go +++ b/apigee_sync_test.go
@@ -16,6 +16,7 @@ import ( "github.com/apid/apid-core" + "github.com/apid/apid-core/util" "github.com/apigee-labs/transicator/common" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -26,7 +27,7 @@ var _ = Describe("Sync", func() { Context("offline mode", func() { var ( - testInstanceID = GenerateUUID() + testInstanceID = util.GenerateUUID() testInstanceName = "offline-instance-name" testClusterID = "offline-cluster-id" testLastSnapshot = "offline-last-snapshot"
diff --git a/data.go b/data.go index 3f50df4..c77fc10 100644 --- a/data.go +++ b/data.go
@@ -15,10 +15,10 @@ package apidApigeeSync import ( - "crypto/rand" "database/sql" "errors" "fmt" + "github.com/apid/apid-core/util" "sync" "github.com/apid/apid-core" @@ -482,7 +482,7 @@ // first start - no row, generate a UUID and store it err = nil newInstanceID = true - info.InstanceID = GenerateUUID() + info.InstanceID = util.GenerateUUID() log.Debugf("Inserting new apid instance id %s", info.InstanceID) _, err = tx.Exec("INSERT INTO APID (instance_id, apid_cluster_id, last_snapshot_info) VALUES (?,?,?)", @@ -492,7 +492,7 @@ log.Debug("Detected apid cluster id change in config. Apid will start clean") err = nil newInstanceID = true - info.InstanceID = GenerateUUID() + info.InstanceID = util.GenerateUUID() _, err = tx.Exec("REPLACE INTO APID (instance_id, apid_cluster_id, last_snapshot_info) VALUES (?,?,?)", info.InstanceID, info.ClusterID, "") @@ -536,21 +536,3 @@ return err } - -/* - * generates a random uuid (mix of timestamp & crypto random string) - */ - -//TODO: Change to https://tools.ietf.org/html/rfc4122 based implementation such as https://github.com/google/uuid -func GenerateUUID() string { - - buff := make([]byte, 16) - numRead, err := rand.Read(buff) - if numRead != len(buff) || err != nil { - panic(err) - } - /* uuid v4 spec */ - buff[6] = (buff[6] | 0x40) & 0x4F - buff[8] = (buff[8] | 0x80) & 0xBF - return fmt.Sprintf("%x-%x-%x-%x-%x", buff[0:4], buff[4:6], buff[6:8], buff[8:10], buff[10:]) -}
diff --git a/dockertests/mockAuthServer.go b/dockertests/mockAuthServer.go index 68520d9..689758d 100644 --- a/dockertests/mockAuthServer.go +++ b/dockertests/mockAuthServer.go
@@ -17,6 +17,7 @@ import ( "encoding/json" "github.com/apid/apid-core" + "github.com/apid/apid-core/util" "github.com/apid/apidApigeeSync" "net/http" ) @@ -27,7 +28,7 @@ } func (m *MockAuthServer) sendToken(w http.ResponseWriter, req *http.Request) { - oauthToken := apidApigeeSync.GenerateUUID() + oauthToken := util.GenerateUUID() res := apidApigeeSync.OauthToken{ AccessToken: oauthToken, ExpiresIn: oauthExpiresIn,
diff --git a/mock_server.go b/mock_server.go index 0100ef5..f39adb7 100644 --- a/mock_server.go +++ b/mock_server.go
@@ -29,6 +29,7 @@ "database/sql" "github.com/apid/apid-core" + "github.com/apid/apid-core/util" "github.com/apigee-labs/transicator/common" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -248,7 +249,7 @@ err = json.Unmarshal(plInfo, &plugInfo) Expect(err).NotTo(HaveOccurred()) - m.oauthToken = GenerateUUID() + m.oauthToken = util.GenerateUUID() res := OauthToken{ AccessToken: m.oauthToken, ExpiresIn: oauthExpiresIn, @@ -266,7 +267,7 @@ Expect(scopes).To(ContainElement(m.params.ClusterID)) - w.Header().Set("Transicator-Snapshot-TXID", GenerateUUID()) + w.Header().Set("Transicator-Snapshot-TXID", util.GenerateUUID()) if len(scopes) == 1 { //send bootstrap db @@ -405,7 +406,7 @@ func (m *MockServer) createDeployment() tableRowMap { deploymentID := m.nextDeploymentID() - bundleID := GenerateUUID() + bundleID := util.GenerateUUID() listen := apid.Config().GetString("api_listen") _, port, err := net.SplitHostPort(listen)
diff --git a/token_test.go b/token_test.go index a3c7d51..1dfaabb 100644 --- a/token_test.go +++ b/token_test.go
@@ -24,7 +24,7 @@ "net/http/httptest" "encoding/json" - + "github.com/apid/apid-core/util" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -114,7 +114,7 @@ defer GinkgoRecover() res := OauthToken{ - AccessToken: GenerateUUID(), + AccessToken: util.GenerateUUID(), ExpiresIn: 1, } body, err := json.Marshal(res)