Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support alt. namespace resource uuid as tenant id to API gateway service #130

Merged
merged 6 commits into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ matrix:
include:
- os: linux
sudo: required
group: deprecated-2017Q3
go: "1.9.3"
services: docker
dist: xenial

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert on travis but is the travis build failure related to these?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, it passed travis.


git:
depth: 3
Expand All @@ -39,7 +39,8 @@ before_install:
- cd $TRAVIS_BUILD_DIR
- GO_FILES=$(find . -iname '*.go' -type f | grep -v /vendor/)
- test -z "$(gofmt -s -l $(echo $GO_FILES))"
- pip install --upgrade pip setuptools
#- pip install --upgrade pip setuptools
- pip install --user --upgrade pip setuptools
- ./tools/travis/setup.sh

install:
Expand Down
1 change: 1 addition & 0 deletions whisk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type Config struct {
Insecure bool
UserAgent string
ApigwAccessToken string
ApigwTenantId string
AdditionalHeaders http.Header
}

Expand Down
23 changes: 14 additions & 9 deletions whisk/wskprops.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,30 @@ const (
DEFAULT_VERSION = "v1"
DEFAULT_NAMESPACE = "_"

NAMESPACE = "NAMESPACE"
AUTH = "AUTH"
APIGW_ACCESS_TOKEN = "APIGW_ACCESS_TOKEN"
APIGW_TENANT_ID = "APIGW_TENANT_ID"
APIHOST = "APIHOST"
APIVERSION = "APIVERSION"
KEY = "KEY"
AUTH = "AUTH"
CERT = "CERT"
APIHOST = "APIHOST"
KEY = "KEY"
NAMESPACE = "NAMESPACE"

DEFAULT_SOURCE = "wsk props"
WSKPROP = "wsk props"
WHISK_PROPERTY = "whisk.properties"
)

type Wskprops struct {
APIHost string
AuthKey string
Namespace string
AuthAPIGWKey string
APIGWSpaceSuid string
APIGWTenantId string
APIHost string
Apiversion string
Key string
AuthAPIGWKey string
AuthKey string
Cert string
Key string
Namespace string
Source string
}

Expand Down Expand Up @@ -177,6 +179,7 @@ func (pi PropertiesImp) GetPropsFromWskprops(path string) *Wskprops {
dep.AuthKey = GetValue(results, AUTH, dep.AuthKey)
dep.Namespace = GetValue(results, NAMESPACE, dep.Namespace)
dep.AuthAPIGWKey = GetValue(results, APIGW_ACCESS_TOKEN, dep.AuthAPIGWKey)
dep.APIGWTenantId = GetValue(results, APIGW_TENANT_ID, dep.APIGWTenantId)
if len(dep.AuthKey) > 0 {
dep.APIGWSpaceSuid = strings.Split(dep.AuthKey, ":")[0]
}
Expand All @@ -194,6 +197,7 @@ func (pi PropertiesImp) GetPropsFromWhiskProperties() *Wskprops {
results, err := ReadProps(path)

if err == nil {
// TODO Determine why we have a hardcoed "test.auth" file here, is this only for unit tests? documented?
authPath := GetValue(results, TEST_AUTH_FILE, "")
b, err := ioutil.ReadFile(authPath)
if err == nil {
Expand Down Expand Up @@ -281,6 +285,7 @@ func GetDefaultWskprops(source string) *Wskprops {
AuthKey: "",
Namespace: DEFAULT_NAMESPACE,
AuthAPIGWKey: "",
APIGWTenantId: "",
APIGWSpaceSuid: "",
Apiversion: DEFAULT_VERSION,
Key: "",
Expand Down
75 changes: 49 additions & 26 deletions whisk/wskprops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

const (
TEST_FILE = "TEST_AUTH_FILE"
TEST_AUTH_FILE_NAME = "TEST_AUTH_FILE"
NON_EXISTING_TEST_FILE = "NON_EXISTING_TEST_FILE"
EXPECTED_OPENWHISK_HOST = "192.168.9.100"
EXPECTED_OPENWHISK_PORT = "443"
Expand All @@ -38,6 +38,7 @@ const (
EXPECTED_HOST = EXPECTED_OPENWHISK_HOST + ":" + EXPECTED_OPENWHISK_PORT
EXPECTED_AUTH_API_KEY = "EXPECTED_AUTH_API_KEY"
EXPECTED_API_GW_SPACE_SUID = "32kc46b1-71f6-4ed5-8c54-816aa4f8c502"
EXPECTED_APIGW_TENANT_ID = "crn:v1:providername:public:servicename:region:a/1234567890abcdef0987654321fedcba:faaa50ec-dce9-4a23-9aaa-a8cb5c7648dc::"
APIGW_SPACE_SUID = "APIGW_SPACE_SUID"
EXPECTED_API_VERSION = "v1"
EXPECTED_CERT = "EXPECTED_CERT"
Expand Down Expand Up @@ -115,29 +116,30 @@ type FakePropertiesImp struct {

func (pi FakePropertiesImp) GetPropsFromWskprops(path string) *Wskprops {
dep := Wskprops{
APIGWSpaceSuid: GetValue(pi.StoredValues_LOCAL_CONF, APIGW_SPACE_SUID, ""),
APIGWTenantId: GetValue(pi.StoredValues_LOCAL_CONF, APIGW_TENANT_ID, ""),
APIHost: GetValue(pi.StoredValues_LOCAL_CONF, APIHOST, ""),
AuthKey: GetValue(pi.StoredValues_LOCAL_CONF, AUTH, ""),
Namespace: GetValue(pi.StoredValues_LOCAL_CONF, NAMESPACE, ""),
Apiversion: GetValue(pi.StoredValues_LOCAL_CONF, APIVERSION, ""),
AuthAPIGWKey: GetValue(pi.StoredValues_LOCAL_CONF, APIGW_ACCESS_TOKEN, ""),
APIGWSpaceSuid: GetValue(pi.StoredValues_LOCAL_CONF, APIGW_SPACE_SUID, ""),
AuthKey: GetValue(pi.StoredValues_LOCAL_CONF, AUTH, ""),
Cert: GetValue(pi.StoredValues_LOCAL_CONF, CERT, ""),
Key: GetValue(pi.StoredValues_LOCAL_CONF, KEY, ""),
Apiversion: GetValue(pi.StoredValues_LOCAL_CONF, APIVERSION, ""),
Namespace: GetValue(pi.StoredValues_LOCAL_CONF, NAMESPACE, ""),
}

return &dep
}

func (pi FakePropertiesImp) GetPropsFromWhiskProperties() *Wskprops {
dep := Wskprops{
APIGWSpaceSuid: pi.StoredValues_WHISK[APIGW_SPACE_SUID],
APIGWTenantId: pi.StoredValues_WHISK[APIGW_TENANT_ID],
APIHost: pi.StoredValues_WHISK[APIHOST],
AuthKey: pi.StoredValues_WHISK[AUTH],
Namespace: pi.StoredValues_WHISK[NAMESPACE],
Apiversion: pi.StoredValues_WHISK[APIVERSION],
AuthAPIGWKey: pi.StoredValues_WHISK[APIGW_ACCESS_TOKEN],
APIGWSpaceSuid: pi.StoredValues_WHISK[APIGW_SPACE_SUID],
AuthKey: pi.StoredValues_WHISK[AUTH],
Cert: pi.StoredValues_WHISK[CERT],
Key: pi.StoredValues_WHISK[KEY],
Apiversion: pi.StoredValues_WHISK[APIVERSION],
Namespace: pi.StoredValues_WHISK[NAMESPACE],
}
return &dep
}
Expand All @@ -161,14 +163,17 @@ func DeleteFile(path string) error {
}

func TestGetPropsFromWhiskProperties(t *testing.T) {

// Variant 1 ------------------------------------------------------------------
lines := []string{EXPECTED_TEST_AUTH_KEY}
CreateFile(lines, TEST_FILE)
CreateFile(lines, TEST_AUTH_FILE_NAME)

fakeOSPackage := FakeOSPackage{
StoredValues: map[string]string{
OPENWHISK_HOME: getCurrentDir(),
},
}

pi := PropertiesImp{
OsPackage: fakeOSPackage,
}
Expand All @@ -184,15 +189,19 @@ func TestGetPropsFromWhiskProperties(t *testing.T) {
assert.Equal(t, "", dep.Cert)
assert.Equal(t, WHISK_PROPERTY, dep.Source)

lines = []string{TEST_AUTH_FILE + "=" + TEST_FILE, OPENWHISK_PRO + "=" + EXPECTED_OPENWHISK_PRO,
OPENWHISK_PORT + "=" + EXPECTED_OPENWHISK_PORT,
// Variant 2 ------------------------------------------------------------------
lines = []string{
OPENWHISK_HOST + "=" + EXPECTED_OPENWHISK_HOST,
OPENWHISK_PORT + "=" + EXPECTED_OPENWHISK_PORT,
OPENWHISK_PRO + "=" + EXPECTED_OPENWHISK_PRO,
TEST_AUTH_FILE + "=" + TEST_AUTH_FILE_NAME,
}

CreateFile(lines, OPENWHISK_PROPERTIES)

pi = PropertiesImp{
OsPackage: fakeOSPackage,
}

dep = pi.GetPropsFromWhiskProperties()
assert.Equal(t, DEFAULT_NAMESPACE, dep.Namespace)
assert.Equal(t, EXPECTED_TEST_AUTH_KEY, dep.AuthKey)
Expand All @@ -205,15 +214,23 @@ func TestGetPropsFromWhiskProperties(t *testing.T) {
assert.Equal(t, WHISK_PROPERTY, dep.Source)

DeleteFile(OPENWHISK_PROPERTIES)

DeleteFile(TEST_AUTH_FILE_NAME)
// Make sure the "non-existant" test.auth key file really does not exist
DeleteFile(NON_EXISTING_TEST_FILE)
lines = []string{TEST_AUTH_FILE + "=" + NON_EXISTING_TEST_FILE, OPENWHISK_PRO + "=" + EXPECTED_OPENWHISK_PRO,

// Variant 3 ------------------------------------------------------------------
lines = []string{
OPENWHISK_HOST + "=" + EXPECTED_OPENWHISK_HOST,
OPENWHISK_PORT + "=" + EXPECTED_OPENWHISK_PORT,
OPENWHISK_HOST + "=" + EXPECTED_OPENWHISK_HOST}
OPENWHISK_PRO + "=" + EXPECTED_OPENWHISK_PRO,
TEST_AUTH_FILE + "=" + NON_EXISTING_TEST_FILE,
}

CreateFile(lines, OPENWHISK_PROPERTIES)
pi = PropertiesImp{
OsPackage: fakeOSPackage,
}

dep = pi.GetPropsFromWhiskProperties()
assert.Equal(t, DEFAULT_NAMESPACE, dep.Namespace)
assert.Equal(t, "", dep.AuthKey)
Expand All @@ -225,15 +242,20 @@ func TestGetPropsFromWhiskProperties(t *testing.T) {
assert.Equal(t, "", dep.Cert)
assert.Equal(t, WHISK_PROPERTY, dep.Source)
DeleteFile(OPENWHISK_PROPERTIES)

DeleteFile(TEST_FILE)
}

func TestGetPropsFromWskprops(t *testing.T) {
lines := []string{APIHOST + "=" + EXPECTED_HOST, AUTH + "=" + EXPECTED_TEST_AUTH_KEY,
lines := []string{
APIGW_ACCESS_TOKEN + "=" + EXPECTED_AUTH_API_KEY,
APIGW_TENANT_ID + "=" + EXPECTED_APIGW_TENANT_ID,
APIHOST + "=" + EXPECTED_HOST,
APIVERSION + "=" + EXPECTED_API_VERSION,
AUTH + "=" + EXPECTED_TEST_AUTH_KEY,
CERT + "=" + EXPECTED_CERT,
KEY + "=" + EXPECTED_KEY,
NAMESPACE + "=" + DEFAULT_NAMESPACE,
APIGW_ACCESS_TOKEN + "=" + EXPECTED_AUTH_API_KEY, APIVERSION + "=" + EXPECTED_API_VERSION,
KEY + "=" + EXPECTED_KEY, CERT + "=" + EXPECTED_CERT}
}

CreateFile(lines, DEFAULT_LOCAL_CONFIG)

fakeOSPackage := FakeOSPackage{
Expand All @@ -259,13 +281,14 @@ func TestGetPropsFromWskprops(t *testing.T) {
path := getCurrentDir() + "/" + DEFAULT_LOCAL_CONFIG
dep = pi.GetPropsFromWskprops(path)
assert.Equal(t, DEFAULT_NAMESPACE, dep.Namespace)
assert.Equal(t, EXPECTED_TEST_AUTH_KEY, dep.AuthKey)
assert.Equal(t, EXPECTED_AUTH_API_KEY, dep.AuthAPIGWKey)
assert.Equal(t, EXPECTED_HOST, dep.APIHost)
assert.Equal(t, EXPECTED_API_GW_SPACE_SUID, dep.APIGWSpaceSuid)
assert.Equal(t, EXPECTED_APIGW_TENANT_ID, dep.APIGWTenantId)
assert.Equal(t, EXPECTED_API_VERSION, dep.Apiversion)
assert.Equal(t, EXPECTED_KEY, dep.Key)
assert.Equal(t, EXPECTED_AUTH_API_KEY, dep.AuthAPIGWKey)
assert.Equal(t, EXPECTED_CERT, dep.Cert)
assert.Equal(t, EXPECTED_HOST, dep.APIHost)
assert.Equal(t, EXPECTED_KEY, dep.Key)
assert.Equal(t, EXPECTED_TEST_AUTH_KEY, dep.AuthKey)
assert.Equal(t, WSKPROP, dep.Source)

DeleteFile(DEFAULT_LOCAL_CONFIG)
Expand Down