This is an automated email from the ASF dual-hosted git repository. dubeejw pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-client-go.git
The following commit(s) were added to refs/heads/master by this push: new 1759868 Add support for APIs defined with web actions having the require-whisk-auth annotation (#69) 1759868 is described below commit 1759868a61729708a8ab1a6de1b409d6e2aea00a Author: Mark Deuser <mdeu...@us.ibm.com> AuthorDate: Thu Mar 15 16:38:27 2018 -0400 Add support for APIs defined with web actions having the require-whisk-auth annotation (#69) * Add support for APIs defined with web actions having the require-whisk-auth annotation * support secure values of numbers and strings --- whisk/api.go | 11 ++++++----- whisk/keyvaluearr_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ whisk/shared.go | 20 ++++++++++++++++++++ 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/whisk/api.go b/whisk/api.go index 64af10b..6c062e5 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 0000000..5b908d5 --- /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 53d8ce5..7848026 100644 --- a/whisk/shared.go +++ b/whisk/shared.go @@ -57,6 +57,26 @@ func (keyValueArr KeyValueArr) FindKeyValue(key string) int { } /* + * 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. */ func (keyValueArr KeyValueArr) AppendKeyValueArr(appKeyValueArr KeyValueArr) KeyValueArr { -- To stop receiving notification emails like this one, please contact dube...@apache.org.