diff options
author | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2021-10-15 12:11:44 +0200 |
---|---|---|
committer | Lukasz Rajewski <lukasz.rajewski@orange.com> | 2021-10-15 12:12:44 +0200 |
commit | b2f51225bc78212682fd087a4ef8a67c51a94188 (patch) | |
tree | 6984ad7ca8a6af18658957d4fa6be9d029d11111 /src/k8splugin/internal/rb/definition.go | |
parent | 7e265aa8286a5e77ddc63fe2f9e20c776792e2f1 (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/definition.go')
-rw-r--r-- | src/k8splugin/internal/rb/definition.go | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/k8splugin/internal/rb/definition.go b/src/k8splugin/internal/rb/definition.go index 73ea44da..aa76afaa 100644 --- a/src/k8splugin/internal/rb/definition.go +++ b/src/k8splugin/internal/rb/definition.go @@ -61,6 +61,7 @@ func (dk DefinitionKey) String() string { // DefinitionManager is an interface exposes the resource bundle definition functionality type DefinitionManager interface { Create(def Definition) (Definition, error) + Update(def Definition) (Definition, error) List(name string) ([]Definition, error) Get(name string, version string) (Definition, error) Delete(name string, version string) error @@ -104,13 +105,13 @@ func (v *DefinitionClient) Create(def Definition) (Definition, error) { // Create a default profile automatically prc := NewProfileClient() - pr, err := prc.Create(Profile{ + pr, err := prc.CreateOrUpdate(Profile{ RBName: def.RBName, RBVersion: def.RBVersion, ProfileName: "default", Namespace: "default", ReleaseName: "default", - }) + }, false) if err != nil { logutils.Error("Create Default Profile", logutils.Fields{ @@ -139,6 +140,26 @@ func (v *DefinitionClient) Create(def Definition) (Definition, error) { return def, nil } +// Update an entry for the resource in the database` +func (v *DefinitionClient) Update(def Definition) (Definition, error) { + + //Construct composite key consisting of name and version + key := DefinitionKey{RBName: def.RBName, RBVersion: def.RBVersion} + + //Check if this definition already exists + _, err := v.Get(def.RBName, def.RBVersion) + if err != nil { + return Definition{}, pkgerrors.New("Definition does not exists") + } + + err = db.DBconn.Update(v.storeName, key, v.tagMeta, def) + if err != nil { + return Definition{}, pkgerrors.Wrap(err, "Updating DB Entry") + } + + return def, nil +} + // List all resource entry's versions in the database func (v *DefinitionClient) List(name string) ([]Definition, error) { res, err := db.DBconn.ReadAll(v.storeName, v.tagMeta) |