You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by md...@apache.org on 2019/01/11 14:30:57 UTC

[incubator-openwhisk-wskdeploy] branch master updated: Enable programatic support for additional request headers (#1023)

This is an automated email from the ASF dual-hosted git repository.

mdeuser pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-wskdeploy.git


The following commit(s) were added to refs/heads/master by this push:
     new fc8de64  Enable programatic support for additional request headers (#1023)
fc8de64 is described below

commit fc8de6454cc83ecd24b1fa2f8685f1512e6d5de5
Author: Mark Deuser <md...@us.ibm.com>
AuthorDate: Fri Jan 11 09:30:52 2019 -0500

    Enable programatic support for additional request headers (#1023)
    
    * enable programatic support for additional request headers
    
    * gofmt
    
    * add unit test
    
    * use correct gofmt command
    
    * remove gofmt added import
---
 deployers/whiskclient.go      | 34 ++++++++++++++++++++--------------
 deployers/whiskclient_test.go | 11 +++++++++++
 2 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/deployers/whiskclient.go b/deployers/whiskclient.go
index 7d01bda..2f5aa28 100644
--- a/deployers/whiskclient.go
+++ b/deployers/whiskclient.go
@@ -40,12 +40,13 @@ const (
 )
 
 var (
-	credential       = PropertyValue{}
-	namespace        = PropertyValue{}
-	apiHost          = PropertyValue{}
-	key              = PropertyValue{}
-	cert             = PropertyValue{}
-	apigwAccessToken = PropertyValue{}
+	credential        = PropertyValue{}
+	namespace         = PropertyValue{}
+	apiHost           = PropertyValue{}
+	key               = PropertyValue{}
+	cert              = PropertyValue{}
+	apigwAccessToken  = PropertyValue{}
+	additionalHeaders = make(http.Header)
 )
 
 type PropertyValue struct {
@@ -80,6 +81,10 @@ var CreateNewClient = func(config_input *whisk.Config) (*whisk.Client, error) {
 	return whisk.NewClient(netClient, config_input)
 }
 
+func AddAdditionalHeader(hdrName string, hdrValue string) {
+	additionalHeaders.Add(hdrName, hdrValue)
+}
+
 func resetWhiskConfig() {
 	credential = PropertyValue{}
 	namespace = PropertyValue{}
@@ -223,14 +228,15 @@ func NewWhiskConfig(proppath string, deploymentPath string, manifestPath string)
 	}
 
 	clientConfig = &whisk.Config{
-		AuthToken:        credential.Value, //Authtoken
-		Namespace:        namespace.Value,  //Namespace
-		Host:             apiHost.Value,
-		Version:          "v1", // TODO() should not be hardcoded, should warn user of default
-		Cert:             cert.Value,
-		Key:              key.Value,
-		Insecure:         mode, // true if you want to ignore certificate signing
-		ApigwAccessToken: apigwAccessToken.Value,
+		AuthToken:         credential.Value, //Authtoken
+		Namespace:         namespace.Value,  //Namespace
+		Host:              apiHost.Value,
+		Version:           "v1", // TODO() should not be hardcoded, should warn user of default
+		Cert:              cert.Value,
+		Key:               key.Value,
+		Insecure:          mode, // true if you want to ignore certificate signing
+		ApigwAccessToken:  apigwAccessToken.Value,
+		AdditionalHeaders: additionalHeaders,
 	}
 
 	// validate we have credential, apihost and namespace
diff --git a/deployers/whiskclient_test.go b/deployers/whiskclient_test.go
index 7f23378..4e7477f 100644
--- a/deployers/whiskclient_test.go
+++ b/deployers/whiskclient_test.go
@@ -273,3 +273,14 @@ func TestValidateClientConfig(t *testing.T) {
 
 	// TODO() test remainder of validateClientConfig() processing
 }
+
+func TestNewWhiskConfigWithAdditionalHeaders(t *testing.T) {
+	propPath := ""
+	manifestPath := ""
+	deploymentPath := ""
+	newHeader := "NewHeader"
+	newHeaderValue := "NewValue"
+	AddAdditionalHeader(newHeader, newHeaderValue)
+	config, _ := NewWhiskConfig(propPath, deploymentPath, manifestPath)
+	assert.Equal(t, newHeaderValue, config.AdditionalHeaders.Get(newHeader), "Failed to set an addtional header")
+}