dubee closed pull request #69: Add support for APIs defined with web actions 
having the require-whisk-auth annotation
URL: https://github.com/apache/incubator-openwhisk-client-go/pull/69
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/whisk/api.go b/whisk/api.go
index 64af10be..6c062e58 100644
--- a/whisk/api.go
+++ b/whisk/api.go
@@ -101,11 +101,12 @@ type ApiParameter struct {
 }
 
 type ApiAction struct {
-       Name          string `json:"name,omitempty"`
-       Namespace     string `json:"namespace,omitempty"`
-       BackendMethod string `json:"backendMethod,omitempty"`
-       BackendUrl    string `json:"backendUrl,omitempty"`
-       Auth          string `json:"authkey,omitempty"`
+       Name          string      `json:"name,omitempty"`
+       Namespace     string      `json:"namespace,omitempty"`
+       BackendMethod string      `json:"backendMethod,omitempty"`
+       BackendUrl    string      `json:"backendUrl,omitempty"`
+       Auth          string      `json:"authkey,omitempty"`
+       SecureKey     interface{} `json:"secureKey,omitempty"`
 }
 
 type ApiOptions struct {
diff --git a/whisk/keyvaluearr_test.go b/whisk/keyvaluearr_test.go
new file mode 100644
index 00000000..5b908d5f
--- /dev/null
+++ b/whisk/keyvaluearr_test.go
@@ -0,0 +1,42 @@
+// +build unit
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package whisk
+
+import (
+       "github.com/stretchr/testify/assert"
+       "testing"
+)
+
+func TestKeyValueArrReplaceOrAdd(t *testing.T) {
+       kvArr := make(KeyValueArr, 3)
+       kvArr[0] = KeyValue{"key0", "value0"}
+       kvArr[1] = KeyValue{"key1", "value1"}
+       kvArr[2] = KeyValue{"key2", "value2"}
+
+       kvNew := &KeyValue{"keyAdd", "valueAdd"}
+       kvArrNew := kvArr.AddOrReplace(kvNew)
+       assert.Equal(t, len(kvArrNew), 4)
+       assert.Equal(t, kvArrNew.GetValue(kvNew.Key), kvNew.Value)
+
+       kvAdd := &KeyValue{"key3", "valueReplace"}
+       kvArrNew = kvArr.AddOrReplace(kvAdd)
+       assert.Equal(t, len(kvArrNew), 4)
+       assert.Equal(t, kvArrNew.GetValue(kvAdd.Key), kvAdd.Value)
+}
diff --git a/whisk/shared.go b/whisk/shared.go
index 53d8ce5e..78480263 100644
--- a/whisk/shared.go
+++ b/whisk/shared.go
@@ -56,6 +56,26 @@ func (keyValueArr KeyValueArr) FindKeyValue(key string) int {
        return -1
 }
 
+/*
+ * Adds the specified KeyValue to the key value array.  If the KeyValue's key
+ * is already in the array, that entry is updated with the KeyValue's value.
+ *
+ * Returns a new key value array with the update
+ */
+func (keyValueArr KeyValueArr) AddOrReplace(kv *KeyValue) KeyValueArr {
+       var replaced = false
+       for i := 0; i < len(keyValueArr); i++ {
+               if strings.ToLower(keyValueArr[i].Key) == 
strings.ToLower(kv.Key) {
+                       keyValueArr[i].Value = kv.Value
+                       replaced = true
+               }
+       }
+       if !replaced {
+               return append(keyValueArr, *kv)
+       }
+       return keyValueArr
+}
+
 /*
 Appends items from appKeyValueArr to keyValueArr if the appKeyValueArr item 
does not exist in keyValueArr.
 */


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to