aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/connection/connection.go
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2019-07-17 01:54:06 +0000
committerGerrit Code Review <gerrit@onap.org>2019-07-17 01:54:06 +0000
commit71a2a9c8b8c77cee67571549a06c96ceb3781077 (patch)
tree0c99ee3688f7fd819e3273d6148525b03db5ac26 /src/k8splugin/internal/connection/connection.go
parenta21d70037b5c3bf0e21d4f0d71a2682a5e2f3c77 (diff)
parent2313ea3cc0730e076bdbc822991534c904570857 (diff)
Merge "Remove kubeconfigdir. Use a tempfile instead"
Diffstat (limited to 'src/k8splugin/internal/connection/connection.go')
-rw-r--r--src/k8splugin/internal/connection/connection.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/k8splugin/internal/connection/connection.go b/src/k8splugin/internal/connection/connection.go
index adb1e992..df1400b5 100644
--- a/src/k8splugin/internal/connection/connection.go
+++ b/src/k8splugin/internal/connection/connection.go
@@ -20,8 +20,6 @@ import (
"encoding/base64"
"encoding/json"
"io/ioutil"
- "log"
- "path/filepath"
"github.com/onap/multicloud-k8s/src/k8splugin/internal/db"
@@ -149,7 +147,6 @@ func (v *ConnectionClient) GetConnectivityRecordByName(connectionName string,
}
for _, value := range conn.OtherConnectivityList.ConnectivityRecords {
- log.Println(value)
if connectivityRecordName == value["connectivity-record-name"] {
return value, nil
}
@@ -173,7 +170,7 @@ func (v *ConnectionClient) Delete(name string) error {
// Download the connection information onto a kubeconfig file
// The file is named after the name of the connection and will
// be placed in the provided parent directory
-func (v *ConnectionClient) Download(name string, parentdir string) (string, error) {
+func (v *ConnectionClient) Download(name string) (string, error) {
conn, err := v.Get(name)
if err != nil {
@@ -186,11 +183,17 @@ func (v *ConnectionClient) Download(name string, parentdir string) (string, erro
return "", pkgerrors.Wrap(err, "Converting from base64")
}
- target := filepath.Join(parentdir, conn.CloudRegion)
- err = ioutil.WriteFile(target, kubeContent, 0644)
+ //Create temp file to write kubeconfig
+ //Assume this file will be deleted after usage by the consumer
+ tempF, err := ioutil.TempFile("", "kube-config-temp-")
+ if err != nil {
+ return "", pkgerrors.Wrap(err, "Creating temp file")
+ }
+
+ _, err = tempF.Write(kubeContent)
if err != nil {
return "", pkgerrors.Wrap(err, "Writing kubeconfig to file")
}
- return target, nil
+ return tempF.Name(), nil
}