Skip to content

Commit

Permalink
Read OpenStack creds from standard paths
Browse files Browse the repository at this point in the history
OpenStack creds cold be in 3 different paths (etc, home config and
current dir). Instead of re-implementing the logic to find and read the
clouds.yaml file, we should use gophercloud which is the standard
go library for OpenStack.

Note that deployments on OpenStack are currently broken unless there's
a clouds.yaml under /etc/openstack.

Fixes openshift#550
  • Loading branch information
flaper87 committed Nov 8, 2018
1 parent d8f8a80 commit 4f5658a
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions pkg/asset/manifests/tectonic.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package manifests

import (
"bufio"
"encoding/base64"
"io/ioutil"
"os"
"path/filepath"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/ghodss/yaml"
"github.com/pkg/errors"

"github.com/gophercloud/utils/openstack/clientconfig"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/machines"
Expand All @@ -20,7 +18,6 @@ import (

const (
tectonicManifestDir = "tectonic"
openStackCredsFile = "/etc/openstack/clouds.yaml"
)

var (
Expand Down Expand Up @@ -80,10 +77,17 @@ func (t *Tectonic) Generate(dependencies asset.Parents) error {
},
}
case "openstack":
credsEncoded, err := credsFileEncode(openStackCredsFile)
clouds, err := clientconfig.LoadCloudsYAML()
if err != nil {
return err
}

marshalled, err := yaml.Marshal(clouds)
if err != nil {
return err
}

credsEncoded := base64.StdEncoding.EncodeToString(marshalled)
cloudCreds = cloudCredsSecretData{
OpenStack: &OpenStackCredsSecretData{
Base64encodeCloudCreds: credsEncoded,
Expand Down Expand Up @@ -176,14 +180,3 @@ func (t *Tectonic) Load(f asset.FileFetcher) (bool, error) {
t.FileList, t.TectonicConfig = fileList, tectonicConfig
return true, nil
}

// credsFileEncode returns contents of a file as base64 encoded string
func credsFileEncode(credsFile string) (string, error) {
f, _ := os.Open(credsFile)
reader := bufio.NewReader(f)
credsData, err := ioutil.ReadAll(reader)
if err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(credsData), nil
}

0 comments on commit 4f5658a

Please sign in to comment.