Merge branch 'master' into XAPID-668
diff --git a/.gitignore b/.gitignore
index dd76eab..9d01395 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,5 @@
coverage.txt
vendor
cmd/apidGatewayDeploy/apidGatewayDeploy
-*.lock
\ No newline at end of file
+*.lock
+/apidGatewayDeploy.iml
diff --git a/api.go b/api.go
index fec8239..2fc41f4 100644
--- a/api.go
+++ b/api.go
@@ -287,18 +287,23 @@
w.Write([]byte("OK"))
}
+func addHeaders(req *http.Request) {
+ var token = services.Config().GetString("apigeesync_bearer_token")
+ req.Header.Add("Authorization", "Bearer "+token)
+}
+
func transmitDeploymentResultsToServer(validResults apiDeploymentResults) error {
retryIn := bundleRetryDelay
maxBackOff := 5 * time.Minute
backOffFunc := createBackoff(retryIn, maxBackOff)
- uri, err := url.Parse(apiServerBaseURI.String())
+ _, err := url.Parse(apiServerBaseURI.String())
if err != nil {
log.Errorf("unable to parse apiServerBaseURI %s: %v", apiServerBaseURI.String(), err)
return err
}
- uri.Path = fmt.Sprintf("/clusters/%s/apids/%s/deployments", apidClusterID, apidInstanceID)
+ apiPath := fmt.Sprintf("%s/clusters/%s/apids/%s/deployments", apiServerBaseURI.String(), apidClusterID, apidInstanceID)
resultJSON, err := json.Marshal(validResults)
if err != nil {
@@ -307,24 +312,27 @@
}
for {
- log.Debugf("transmitting deployment results to tracker: %s", string(resultJSON))
- req, err := http.NewRequest("PUT", uri.String(), bytes.NewReader(resultJSON))
+ log.Debugf("transmitting deployment results to tracker by URL=%s data=%s", apiPath, string(resultJSON))
+ req, err := http.NewRequest("PUT", apiPath, bytes.NewReader(resultJSON))
+ if err != nil {
+ log.Errorf("unable to create PUT request", err)
+ return err
+ }
req.Header.Add("Content-Type", "application/json")
+ addHeaders(req)
resp, err := http.DefaultClient.Do(req)
+ defer resp.Body.Close()
if err != nil || resp.StatusCode != http.StatusOK {
if err != nil {
log.Errorf("failed to communicate with tracking service: %v", err)
} else {
b, _ := ioutil.ReadAll(resp.Body)
- log.Errorf("tracking service call failed. code: %d, body: %s", resp.StatusCode, string(b))
+ log.Errorf("tracking service call failed to %s , code: %d, body: %s", apiPath, resp.StatusCode, string(b))
}
backOffFunc()
- resp.Body.Close()
continue
}
-
- resp.Body.Close()
return nil
}
}
diff --git a/api_test.go b/api_test.go
index 1f35233..c95369f 100644
--- a/api_test.go
+++ b/api_test.go
@@ -1,15 +1,15 @@
package apiGatewayDeploy
import (
+ "bytes"
+ "encoding/json"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
+ "io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
- "encoding/json"
- "io/ioutil"
"time"
- "bytes"
)
var _ = Describe("api", func() {
@@ -155,7 +155,7 @@
time.Sleep(250 * time.Millisecond) // give api call above time to block
insertTestDeployment(testServer, deploymentID)
- deploymentsChanged<- deploymentID
+ deploymentsChanged <- deploymentID
})
It("should get 304 after blocking if no new deployment", func() {
@@ -190,8 +190,7 @@
uri.Path = deploymentsEndpoint
deploymentResult := apiDeploymentResults{
- apiDeploymentResult{
- },
+ apiDeploymentResult{},
}
payload, err := json.Marshal(deploymentResult)
Expect(err).ShouldNot(HaveOccurred())
@@ -214,7 +213,7 @@
deploymentResult := apiDeploymentResults{
apiDeploymentResult{
- ID: deploymentID,
+ ID: deploymentID,
Status: RESPONSE_STATUS_SUCCESS,
},
}
@@ -241,7 +240,7 @@
deploymentResult := apiDeploymentResults{
apiDeploymentResult{
- ID: deploymentID,
+ ID: deploymentID,
Status: RESPONSE_STATUS_SUCCESS,
},
}
@@ -273,10 +272,10 @@
deploymentResults := apiDeploymentResults{
apiDeploymentResult{
- ID: deploymentID,
- Status: RESPONSE_STATUS_FAIL,
+ ID: deploymentID,
+ Status: RESPONSE_STATUS_FAIL,
ErrorCode: 100,
- Message: "Some error message",
+ Message: "Some error message",
},
}
payload, err := json.Marshal(deploymentResults)
@@ -304,10 +303,10 @@
It("should communicate status to tracking server", func() {
deploymentResults := apiDeploymentResults{
apiDeploymentResult{
- ID: "deploymentID",
- Status: RESPONSE_STATUS_FAIL,
+ ID: "deploymentID",
+ Status: RESPONSE_STATUS_FAIL,
ErrorCode: 100,
- Message: "Some error message",
+ Message: "Some error message",
},
}
@@ -334,8 +333,8 @@
uri.Path = "/bundles/1"
bundleUri := uri.String()
bundle := bundleConfigJson{
- Name: uri.Path,
- URI: bundleUri,
+ Name: uri.Path,
+ URI: bundleUri,
ChecksumType: "crc-32",
}
bundle.Checksum = testGetChecksum(bundle.ChecksumType, bundleUri)
@@ -346,23 +345,23 @@
Expect(err).ShouldNot(HaveOccurred())
dep := DataDeployment{
- ID: deploymentID,
- BundleConfigID: deploymentID,
- ApidClusterID: deploymentID,
- DataScopeID: deploymentID,
- BundleConfigJSON: string(bundleJson),
- ConfigJSON: string(bundleJson),
- Created: "",
- CreatedBy: "",
- Updated: "",
- UpdatedBy: "",
- BundleName: deploymentID,
- BundleURI: bundle.URI,
- BundleChecksum: bundle.Checksum,
+ ID: deploymentID,
+ BundleConfigID: deploymentID,
+ ApidClusterID: deploymentID,
+ DataScopeID: deploymentID,
+ BundleConfigJSON: string(bundleJson),
+ ConfigJSON: string(bundleJson),
+ Created: "",
+ CreatedBy: "",
+ Updated: "",
+ UpdatedBy: "",
+ BundleName: deploymentID,
+ BundleURI: bundle.URI,
+ BundleChecksum: bundle.Checksum,
BundleChecksumType: bundle.ChecksumType,
- LocalBundleURI: "x",
- DeployStatus: "",
- DeployErrorCode: 0,
+ LocalBundleURI: "x",
+ DeployStatus: "",
+ DeployErrorCode: 0,
DeployErrorMessage: "",
}
diff --git a/apidGatewayDeploy_suite_test.go b/apidGatewayDeploy_suite_test.go
index 4604588..ad253e0 100644
--- a/apidGatewayDeploy_suite_test.go
+++ b/apidGatewayDeploy_suite_test.go
@@ -5,16 +5,17 @@
. "github.com/onsi/gomega"
"encoding/hex"
- "io/ioutil"
+
+ "github.com/30x/apid-core"
+ "github.com/30x/apid-core/factory"
+
+ "io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"
"time"
-
- "github.com/30x/apid-core"
- "github.com/30x/apid-core/factory"
)
var (
diff --git a/listener_test.go b/listener_test.go
index 452879e..aeddbf9 100644
--- a/listener_test.go
+++ b/listener_test.go
@@ -3,10 +3,10 @@
import (
"encoding/json"
"github.com/30x/apid-core"
+ "github.com/apigee-labs/transicator/common"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"net/url"
- "github.com/apigee-labs/transicator/common"
)
var _ = Describe("listener", func() {
@@ -23,8 +23,8 @@
uri.Path = "/bundles/1"
bundleUri := uri.String()
bundle1 := bundleConfigJson{
- Name: uri.Path,
- URI: bundleUri,
+ Name: uri.Path,
+ URI: bundleUri,
ChecksumType: "crc-32",
}
bundle1.Checksum = testGetChecksum(bundle1.ChecksumType, bundleUri)
@@ -79,8 +79,8 @@
uri.Path = "/bundles/1"
bundleUri := uri.String()
bundle := bundleConfigJson{
- Name: uri.Path,
- URI: bundleUri,
+ Name: uri.Path,
+ URI: bundleUri,
ChecksumType: "crc-32",
}
bundle.Checksum = testGetChecksum(bundle.ChecksumType, bundleUri)
@@ -95,8 +95,8 @@
Changes: []common.Change{
{
Operation: common.Insert,
- Table: DEPLOYMENT_TABLE,
- NewRow: row,
+ Table: DEPLOYMENT_TABLE,
+ NewRow: row,
},
},
}
@@ -130,7 +130,7 @@
tx, err := getDB().Begin()
Expect(err).ShouldNot(HaveOccurred())
dep := DataDeployment{
- ID: deploymentID,
+ ID: deploymentID,
LocalBundleURI: "whatever",
}
err = InsertDeployment(tx, dep)
@@ -145,8 +145,8 @@
Changes: []common.Change{
{
Operation: common.Delete,
- Table: DEPLOYMENT_TABLE,
- OldRow: row,
+ Table: DEPLOYMENT_TABLE,
+ OldRow: row,
},
},
}
diff --git a/pluginData.go b/pluginData.go
index e437d71..9625ee6 100644
--- a/pluginData.go
+++ b/pluginData.go
@@ -3,7 +3,7 @@
import "github.com/30x/apid-core"
var pluginData = apid.PluginData{
- Name: "apidGatewayDeploy",
+ Name: "apidGatewayDeploy",
Version: "0.0.1",
ExtraData: map[string]interface{}{
"schemaVersion": "0.0.1",