aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/rb/profile.go
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@orange.com>2021-10-15 12:11:44 +0200
committerLukasz Rajewski <lukasz.rajewski@orange.com>2021-10-15 12:12:44 +0200
commitb2f51225bc78212682fd087a4ef8a67c51a94188 (patch)
tree6984ad7ca8a6af18658957d4fa6be9d029d11111 /src/k8splugin/internal/rb/profile.go
parent7e265aa8286a5e77ddc63fe2f9e20c776792e2f1 (diff)
Expose Update Handlers
Expose Update Handlers for Definition, Profile and Config Tmpl Issue-ID: MULTICLOUD-1410 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com> Change-Id: Ibe6fe05458f2af28f3e1ca14a54492a4bae19362
Diffstat (limited to 'src/k8splugin/internal/rb/profile.go')
-rw-r--r--src/k8splugin/internal/rb/profile.go25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/k8splugin/internal/rb/profile.go b/src/k8splugin/internal/rb/profile.go
index 78023e59..77398580 100644
--- a/src/k8splugin/internal/rb/profile.go
+++ b/src/k8splugin/internal/rb/profile.go
@@ -46,7 +46,7 @@ type Profile struct {
// ProfileManager is an interface exposes the resource bundle profile functionality
type ProfileManager interface {
- Create(def Profile) (Profile, error)
+ CreateOrUpdate(def Profile, update bool) (Profile, error)
Get(rbName, rbVersion, prName string) (Profile, error)
List(rbName, rbVersion string) ([]Profile, error)
Delete(rbName, rbVersion, prName string) error
@@ -89,8 +89,8 @@ func NewProfileClient() *ProfileClient {
}
}
-// Create an entry for the resource bundle profile in the database
-func (v *ProfileClient) Create(p Profile) (Profile, error) {
+// CreateOrUpdate an entry for the resource bundle profile in the database
+func (v *ProfileClient) CreateOrUpdate(p Profile, update bool) (Profile, error) {
// Name is required
if p.ProfileName == "" {
@@ -99,10 +99,12 @@ func (v *ProfileClient) Create(p Profile) (Profile, error) {
//Check if profile already exists
_, err := v.Get(p.RBName, p.RBVersion, p.ProfileName)
- if err == nil {
+ if err == nil && !update {
return Profile{}, pkgerrors.New("Profile already exists for this Definition")
}
-
+ if err != nil && update {
+ return Profile{}, pkgerrors.New("Profile does not exists for this Definition")
+ }
//Check if provided resource bundle information is valid
_, err = NewDefinitionClient().Get(p.RBName, p.RBVersion)
if err != nil {
@@ -120,9 +122,16 @@ func (v *ProfileClient) Create(p Profile) (Profile, error) {
ProfileName: p.ProfileName,
}
- err = db.DBconn.Create(v.storeName, key, v.tagMeta, p)
- if err != nil {
- return Profile{}, pkgerrors.Wrap(err, "Creating Profile DB Entry")
+ if update {
+ err = db.DBconn.Update(v.storeName, key, v.tagMeta, p)
+ if err != nil {
+ return Profile{}, pkgerrors.Wrap(err, "Updating Profile DB Entry")
+ }
+ } else {
+ err = db.DBconn.Create(v.storeName, key, v.tagMeta, p)
+ if err != nil {
+ return Profile{}, pkgerrors.Wrap(err, "Creating Profile DB Entry")
+ }
}
return p, nil