-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openstack: read credentials from clouds.yaml
- Loading branch information
Showing
16 changed files
with
167 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "clouds", | ||
srcs = [ | ||
"clouds.go", | ||
"read.go", | ||
], | ||
importpath = "github.com/edgelesssys/constellation/v2/internal/cloud/openstack/clouds", | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"//internal/file", | ||
"@com_github_mitchellh_go_homedir//:go-homedir", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Copyright (c) Edgeless Systems GmbH | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
package clouds | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/mitchellh/go-homedir" | ||
|
||
"github.com/edgelesssys/constellation/v2/internal/file" | ||
) | ||
|
||
func ReadCloudsYAML(fileHandler file.Handler, path string) (Clouds, error) { | ||
// Order of operations as performed by the OpenStack CLI: | ||
|
||
// Define a search path for clouds.yaml: | ||
// 1. If OS_CLIENT_CONFIG_FILE is set, use it as search path | ||
// 2. Otherwise, use the following paths: | ||
// - current directory | ||
// - `openstack` directory under standard user config directory (e.g. ~/.config/openstack) | ||
// - /etc/openstack (Unix only) | ||
|
||
confDir, err := os.UserConfigDir() | ||
if err != nil { | ||
return Clouds{}, fmt.Errorf("getting user config directory: %w", err) | ||
} | ||
|
||
var searchPaths []string | ||
if path != "" { | ||
expanded, err := homedir.Expand(path) | ||
if err == nil { | ||
searchPaths = append(searchPaths, expanded) | ||
} else { | ||
searchPaths = append(searchPaths, path) | ||
} | ||
} else if osClientConfigFile := os.Getenv("OS_CLIENT_CONFIG_FILE"); osClientConfigFile != "" { | ||
searchPaths = append(searchPaths, filepath.Join(osClientConfigFile, "clouds.yaml")) | ||
} else { | ||
searchPaths = append(searchPaths, "clouds.yaml") | ||
searchPaths = append(searchPaths, filepath.Join(confDir, "openstack", "clouds.yaml")) | ||
if os.PathSeparator == '/' { | ||
searchPaths = append(searchPaths, "/etc/openstack/clouds.yaml") | ||
} | ||
} | ||
|
||
var cloudsYAML Clouds | ||
for _, path := range searchPaths { | ||
if err := fileHandler.ReadYAML(path, &cloudsYAML); err == nil { | ||
return cloudsYAML, nil | ||
} | ||
} | ||
|
||
return Clouds{}, fmt.Errorf("clouds.yaml not found in search paths: %v", searchPaths) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.