summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/rb
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-03-29 16:07:47 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-03-29 16:12:19 -0700
commitf3875e13c7a6675aa980c29580daae42a32eb97f (patch)
tree05cbe26f86ce0c3e1f936d724158223d8e522021 /src/k8splugin/internal/rb
parent5f5aabfbaff227c3c134c27ecbd7ecd347f74c09 (diff)
Make profile key explicit
Using profilename instead of name in the db key protects it from getting overwritten by anything else that might use name as a key. Using explicit key names makes sure that we don't have to add bson structure tags in the code. Issue-ID: MULTICLOUD-558 Change-Id: I9bd6f757496af22d8662b0d114f0ef7d33a5784a Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/rb')
-rw-r--r--src/k8splugin/internal/rb/profile.go44
-rw-r--r--src/k8splugin/internal/rb/profile_test.go22
2 files changed, 33 insertions, 33 deletions
diff --git a/src/k8splugin/internal/rb/profile.go b/src/k8splugin/internal/rb/profile.go
index 572a175c..679815ac 100644
--- a/src/k8splugin/internal/rb/profile.go
+++ b/src/k8splugin/internal/rb/profile.go
@@ -33,7 +33,7 @@ import (
type Profile struct {
RBName string `json:"rb-name"`
RBVersion string `json:"rb-version"`
- Name string `json:"profile-name"`
+ ProfileName string `json:"profile-name"`
ReleaseName string `json:"release-name"`
Namespace string `json:"namespace"`
KubernetesVersion string `json:"kubernetes-version"`
@@ -49,9 +49,9 @@ type ProfileManager interface {
}
type ProfileKey struct {
- RBName string `json:"rb-name"`
- RBVersion string `json:"rb-version"`
- Name string `json:"profile-name"`
+ RBName string `json:"rb-name"`
+ RBVersion string `json:"rb-version"`
+ ProfileName string `json:"profile-name"`
}
// We will use json marshalling to convert to string to
@@ -88,12 +88,12 @@ func NewProfileClient() *ProfileClient {
func (v *ProfileClient) Create(p Profile) (Profile, error) {
// Name is required
- if p.Name == "" {
+ if p.ProfileName == "" {
return Profile{}, pkgerrors.New("Name is required for Resource Bundle Profile")
}
//Check if profile already exists
- _, err := v.Get(p.RBName, p.RBVersion, p.Name)
+ _, err := v.Get(p.RBName, p.RBVersion, p.ProfileName)
if err == nil {
return Profile{}, pkgerrors.New("Profile already exists for this Definition")
}
@@ -106,13 +106,13 @@ func (v *ProfileClient) Create(p Profile) (Profile, error) {
//If release-name is not provided, we store name instead
if p.ReleaseName == "" {
- p.ReleaseName = p.Name
+ p.ReleaseName = p.ProfileName
}
key := ProfileKey{
- RBName: p.RBName,
- RBVersion: p.RBVersion,
- Name: p.Name,
+ RBName: p.RBName,
+ RBVersion: p.RBVersion,
+ ProfileName: p.ProfileName,
}
err = db.DBconn.Create(v.storeName, key, v.tagMeta, p)
@@ -126,9 +126,9 @@ func (v *ProfileClient) Create(p Profile) (Profile, error) {
// Get returns the Resource Bundle Profile for corresponding ID
func (v *ProfileClient) Get(rbName, rbVersion, prName string) (Profile, error) {
key := ProfileKey{
- RBName: rbName,
- RBVersion: rbVersion,
- Name: prName,
+ RBName: rbName,
+ RBVersion: rbVersion,
+ ProfileName: prName,
}
value, err := db.DBconn.Read(v.storeName, key, v.tagMeta)
if err != nil {
@@ -151,9 +151,9 @@ func (v *ProfileClient) Get(rbName, rbVersion, prName string) (Profile, error) {
// Delete the Resource Bundle Profile from database
func (v *ProfileClient) Delete(rbName, rbVersion, prName string) error {
key := ProfileKey{
- RBName: rbName,
- RBVersion: rbVersion,
- Name: prName,
+ RBName: rbName,
+ RBVersion: rbVersion,
+ ProfileName: prName,
}
err := db.DBconn.Delete(v.storeName, key, v.tagMeta)
if err != nil {
@@ -183,9 +183,9 @@ func (v *ProfileClient) Upload(rbName, rbVersion, prName string, inp []byte) err
}
key := ProfileKey{
- RBName: rbName,
- RBVersion: rbVersion,
- Name: prName,
+ RBName: rbName,
+ RBVersion: rbVersion,
+ ProfileName: prName,
}
//Encode given byte stream to text for storage
encodedStr := base64.StdEncoding.EncodeToString(inp)
@@ -210,9 +210,9 @@ func (v *ProfileClient) Download(rbName, rbVersion, prName string) ([]byte, erro
}
key := ProfileKey{
- RBName: rbName,
- RBVersion: rbVersion,
- Name: prName,
+ RBName: rbName,
+ RBVersion: rbVersion,
+ ProfileName: prName,
}
value, err := db.DBconn.Read(v.storeName, key, v.tagContent)
if err != nil {
diff --git a/src/k8splugin/internal/rb/profile_test.go b/src/k8splugin/internal/rb/profile_test.go
index 5d41b019..856e139b 100644
--- a/src/k8splugin/internal/rb/profile_test.go
+++ b/src/k8splugin/internal/rb/profile_test.go
@@ -39,7 +39,7 @@ func TestCreateProfile(t *testing.T) {
{
label: "Create Resource Bundle Profile",
inp: Profile{
- Name: "testprofile1",
+ ProfileName: "testprofile1",
ReleaseName: "testprofilereleasename",
Namespace: "testnamespace",
KubernetesVersion: "1.12.3",
@@ -47,7 +47,7 @@ func TestCreateProfile(t *testing.T) {
RBVersion: "v1",
},
expected: Profile{
- Name: "testprofile1",
+ ProfileName: "testprofile1",
ReleaseName: "testprofilereleasename",
Namespace: "testnamespace",
KubernetesVersion: "1.12.3",
@@ -70,7 +70,7 @@ func TestCreateProfile(t *testing.T) {
{
label: "Create Resource Bundle Profile With Non-Existing Definition",
inp: Profile{
- Name: "testprofile1",
+ ProfileName: "testprofile1",
ReleaseName: "testprofilereleasename",
Namespace: "testnamespace",
KubernetesVersion: "1.12.3",
@@ -136,7 +136,7 @@ func TestGetProfile(t *testing.T) {
rbversion: "v1",
prname: "testprofile1",
expected: Profile{
- Name: "testprofile1",
+ ProfileName: "testprofile1",
ReleaseName: "testprofilereleasename",
Namespace: "testnamespace",
KubernetesVersion: "1.12.3",
@@ -146,7 +146,7 @@ func TestGetProfile(t *testing.T) {
expectedError: "",
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", Name: "testprofile1"}.String(): {
+ ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile1"}.String(): {
"metadata": []byte(
"{\"profile-name\":\"testprofile1\"," +
"\"release-name\":\"testprofilereleasename\"," +
@@ -266,7 +266,7 @@ func TestUploadProfile(t *testing.T) {
},
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", Name: "testprofile1"}.String(): {
+ ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile1"}.String(): {
"metadata": []byte(
"{\"profile-name\":\"testprofile1\"," +
"\"release-name\":\"testprofilereleasename\"," +
@@ -307,7 +307,7 @@ func TestUploadProfile(t *testing.T) {
},
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", Name: "testprofile2"}.String(): {
+ ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile2"}.String(): {
"metadata": []byte(
"{\"profile-name\":\"testprofile1\"," +
"\"release-name\":\"testprofilereleasename\"," +
@@ -331,7 +331,7 @@ func TestUploadProfile(t *testing.T) {
},
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", Name: "testprofile1"}.String(): {
+ ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile1"}.String(): {
"metadata": []byte(
"{\"profile-name\":\"testprofile1\"," +
"\"release-name\":\"testprofilereleasename\"," +
@@ -426,7 +426,7 @@ func TestDownloadProfile(t *testing.T) {
},
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", Name: "testprofile1"}.String(): {
+ ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile1"}.String(): {
"metadata": []byte(
"{\"profile-name\":\"testprofile1\"," +
"\"release-name\":\"testprofilereleasename\"," +
@@ -450,7 +450,7 @@ func TestDownloadProfile(t *testing.T) {
expectedError: "Invalid Profile Name provided",
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
- ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", Name: "testprofile2"}.String(): {
+ ProfileKey{RBName: "testresourcebundle", RBVersion: "v1", ProfileName: "testprofile2"}.String(): {
"metadata": []byte(
"{\"profile-name\":\"testprofile1\"," +
"\"release-name\":\"testprofilereleasename\"," +
@@ -513,7 +513,7 @@ func TestResolveProfile(t *testing.T) {
mockdb: &db.MockDB{
Items: map[string]map[string][]byte{
ProfileKey{RBName: "testresourcebundle", RBVersion: "v1",
- Name: "profile1"}.String(): {
+ ProfileName: "profile1"}.String(): {
"metadata": []byte(
"{\"profile-name\":\"profile1\"," +
"\"release-name\":\"testprofilereleasename\"," +