aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin/internal')
-rw-r--r--src/k8splugin/internal/connection/connection.go45
-rw-r--r--src/k8splugin/internal/helm/helm.go14
-rw-r--r--src/k8splugin/internal/rb/archive.go7
-rw-r--r--src/k8splugin/internal/utils.go12
4 files changed, 65 insertions, 13 deletions
diff --git a/src/k8splugin/internal/connection/connection.go b/src/k8splugin/internal/connection/connection.go
index d110c221..adb1e992 100644
--- a/src/k8splugin/internal/connection/connection.go
+++ b/src/k8splugin/internal/connection/connection.go
@@ -20,6 +20,7 @@ import (
"encoding/base64"
"encoding/json"
"io/ioutil"
+ "log"
"path/filepath"
"github.com/onap/multicloud-k8s/src/k8splugin/internal/db"
@@ -32,7 +33,13 @@ type Connection struct {
CloudRegion string `json:"cloud-region"`
CloudOwner string `json:"cloud-owner"`
Kubeconfig string `json:"kubeconfig"`
- OtherConnectivityList map[string]interface{} `json:"other-connectivity-list"`
+ OtherConnectivityList ConnectivityRecordList `json:"other-connectivity-list"`
+}
+
+// ConnectivityRecordList covers lists of connectivity records
+// and any other data that needs to be stored
+type ConnectivityRecordList struct {
+ ConnectivityRecords []map[string]string `json:"connectivity-records"`
}
// ConnectionKey is the key structure that is used in the database
@@ -56,6 +63,7 @@ type ConnectionManager interface {
Create(c Connection) (Connection, error)
Get(name string) (Connection, error)
Delete(name string) error
+ GetConnectivityRecordByName(connname string, name string) (map[string]string, error)
}
// ConnectionClient implements the ConnectionManager
@@ -65,7 +73,7 @@ type ConnectionClient struct {
tagMeta string
}
-// New ConnectionClient returns an instance of the ConnectionClient
+// NewConnectionClient returns an instance of the ConnectionClient
// which implements the ConnectionManager
func NewConnectionClient() *ConnectionClient {
return &ConnectionClient{
@@ -117,6 +125,39 @@ func (v *ConnectionClient) Get(name string) (Connection, error) {
return Connection{}, pkgerrors.New("Error getting Connection")
}
+// GetConnectivityRecordByName returns Connection for corresponding to name
+// JSON example:
+// "connectivity-records" :
+// [
+// {
+// “connectivity-record-name” : “<name>”, // example: OVN
+// “FQDN-or-ip” : “<fqdn>”,
+// “ca-cert-to-verify-server” : “<contents of CA certificate to validate the OVN server>”,
+// “ssl-initiator” : “<true/false”>,
+// “user-name”: “<user name>”, //valid if ssl-initator is false
+// “password” : “<password>”, // valid if ssl-initiator is false
+// “private-key” : “<contents of private key in PEM>”, // valid if ssl-initiator is true
+// “cert-to-present” : “<contents of certificate to present to server>” , //valid if ssl-initiator is true
+// },
+// ]
+func (v *ConnectionClient) GetConnectivityRecordByName(connectionName string,
+ connectivityRecordName string) (map[string]string, error) {
+
+ conn, err := v.Get(connectionName)
+ if err != nil {
+ return nil, pkgerrors.Wrap(err, "Error getting connection")
+ }
+
+ for _, value := range conn.OtherConnectivityList.ConnectivityRecords {
+ log.Println(value)
+ if connectivityRecordName == value["connectivity-record-name"] {
+ return value, nil
+ }
+ }
+
+ return nil, pkgerrors.New("Connectivity record " + connectivityRecordName + " not found")
+}
+
// Delete the Connection from database
func (v *ConnectionClient) Delete(name string) error {
diff --git a/src/k8splugin/internal/helm/helm.go b/src/k8splugin/internal/helm/helm.go
index 1ab701ae..2150758b 100644
--- a/src/k8splugin/internal/helm/helm.go
+++ b/src/k8splugin/internal/helm/helm.go
@@ -21,11 +21,12 @@ import (
"io/ioutil"
"k8s.io/helm/pkg/strvals"
"os"
- "path"
"path/filepath"
"regexp"
"strings"
+ utils "github.com/onap/multicloud-k8s/src/k8splugin/internal"
+
"github.com/ghodss/yaml"
pkgerrors "github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -135,15 +136,6 @@ func (h *TemplateClient) mergeValues(dest map[string]interface{}, src map[string
return dest
}
-func (h *TemplateClient) ensureDirectory(f string) error {
- base := path.Dir(f)
- _, err := os.Stat(base)
- if err != nil && !os.IsNotExist(err) {
- return err
- }
- return os.MkdirAll(base, 0755)
-}
-
// GenerateKubernetesArtifacts a mapping of type to fully evaluated helm template
func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFiles []string,
values []string) ([]KubernetesResourceTemplate, error) {
@@ -245,7 +237,7 @@ func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFile
}
mfilePath := filepath.Join(outputDir, m.Name)
- h.ensureDirectory(mfilePath)
+ utils.EnsureDirectory(mfilePath)
err = ioutil.WriteFile(mfilePath, []byte(data), 0666)
if err != nil {
return retData, err
diff --git a/src/k8splugin/internal/rb/archive.go b/src/k8splugin/internal/rb/archive.go
index 624adfba..c0753134 100644
--- a/src/k8splugin/internal/rb/archive.go
+++ b/src/k8splugin/internal/rb/archive.go
@@ -24,6 +24,8 @@ import (
"io/ioutil"
"os"
"path/filepath"
+
+ utils "github.com/onap/multicloud-k8s/src/k8splugin/internal"
)
func isTarGz(r io.Reader) error {
@@ -113,6 +115,11 @@ func ExtractTarBall(r io.Reader) (string, error) {
}
}
case tar.TypeReg:
+ err = utils.EnsureDirectory(target)
+ if err != nil {
+ return "", pkgerrors.Wrap(err, "Creating Directory")
+ }
+
f, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR, os.FileMode(header.Mode))
if err != nil {
return "", pkgerrors.Wrap(err, "Creating file")
diff --git a/src/k8splugin/internal/utils.go b/src/k8splugin/internal/utils.go
index 627fb305..47a236c2 100644
--- a/src/k8splugin/internal/utils.go
+++ b/src/k8splugin/internal/utils.go
@@ -18,6 +18,7 @@ import (
"log"
"os"
"path/filepath"
+ "path"
"plugin"
"strings"
@@ -128,3 +129,14 @@ func CheckInitialSettings() error {
return nil
}
+
+//EnsureDirectory makes sure that the directories specified in the path exist
+//If not, it will create them, if possible.
+func EnsureDirectory(f string) error {
+ base := path.Dir(f)
+ _, err := os.Stat(base)
+ if err != nil && !os.IsNotExist(err) {
+ return err
+ }
+ return os.MkdirAll(base, 0755)
+}