rename ModuleStorage to Storage
get rid of stutter and use module.Storage
This commit is contained in:
parent
70a5b1b734
commit
3a495ffe56
|
@ -107,7 +107,7 @@ func testModule(t *testing.T, name string) *module.Tree {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &module.ModuleStorage{
|
s := &module.Storage{
|
||||||
StorageDir: tempDir(t),
|
StorageDir: tempDir(t),
|
||||||
Mode: module.GetModeGet,
|
Mode: module.GetModeGet,
|
||||||
}
|
}
|
||||||
|
|
|
@ -368,8 +368,8 @@ func (m *Meta) flagSet(n string) *flag.FlagSet {
|
||||||
|
|
||||||
// moduleStorage returns the module.Storage implementation used to store
|
// moduleStorage returns the module.Storage implementation used to store
|
||||||
// modules for commands.
|
// modules for commands.
|
||||||
func (m *Meta) moduleStorage(root string, mode module.GetMode) *module.ModuleStorage {
|
func (m *Meta) moduleStorage(root string, mode module.GetMode) *module.Storage {
|
||||||
return &module.ModuleStorage{
|
return &module.Storage{
|
||||||
StorageDir: filepath.Join(root, "modules"),
|
StorageDir: filepath.Join(root, "modules"),
|
||||||
Services: m.Services,
|
Services: m.Services,
|
||||||
Ui: m.Ui,
|
Ui: m.Ui,
|
||||||
|
|
|
@ -41,7 +41,7 @@ func testConfig(t *testing.T, n string) *config.Config {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func testStorage(t *testing.T) *ModuleStorage {
|
func testStorage(t *testing.T) *Storage {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
return &ModuleStorage{StorageDir: tempDir(t)}
|
return &Storage{StorageDir: tempDir(t)}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,19 +55,23 @@ type moduleRecord struct {
|
||||||
registry bool
|
registry bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ModuleStorage implements methods to record and fetch metadata about the
|
// Storage implements methods to record and fetch metadata about the
|
||||||
// modules that have been fetched and stored locally. The getter.Storgae
|
// modules that have been fetched and stored locally. The getter.Storgae
|
||||||
// abstraction doesn't provide the information needed to know which versions of
|
// abstraction doesn't provide the information needed to know which versions of
|
||||||
// a module have been stored, or their location.
|
// a module have been stored, or their location.
|
||||||
type ModuleStorage struct {
|
type Storage struct {
|
||||||
|
// StorageDir is the directory where all modules will be stored.
|
||||||
StorageDir string
|
StorageDir string
|
||||||
Services *disco.Disco
|
// Services is a *Disco which ay have services and credentials pre-loaded.
|
||||||
Ui cli.Ui
|
Services *disco.Disco
|
||||||
Mode GetMode
|
// Ui is an optional cli.Ui for user output
|
||||||
|
Ui cli.Ui
|
||||||
|
// Mode is the GetMode that will be used for various operations.
|
||||||
|
Mode GetMode
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadManifest returns the moduleManifest file from the parent directory.
|
// loadManifest returns the moduleManifest file from the parent directory.
|
||||||
func (m ModuleStorage) loadManifest() (moduleManifest, error) {
|
func (m Storage) loadManifest() (moduleManifest, error) {
|
||||||
manifest := moduleManifest{}
|
manifest := moduleManifest{}
|
||||||
|
|
||||||
manifestPath := filepath.Join(m.StorageDir, manifestName)
|
manifestPath := filepath.Join(m.StorageDir, manifestName)
|
||||||
|
@ -90,7 +94,7 @@ func (m ModuleStorage) loadManifest() (moduleManifest, error) {
|
||||||
// root directory. The storage method loads the entire file and rewrites it
|
// root directory. The storage method loads the entire file and rewrites it
|
||||||
// each time. This is only done a few times during init, so efficiency is
|
// each time. This is only done a few times during init, so efficiency is
|
||||||
// not a concern.
|
// not a concern.
|
||||||
func (m ModuleStorage) recordModule(rec moduleRecord) error {
|
func (m Storage) recordModule(rec moduleRecord) error {
|
||||||
manifest, err := m.loadManifest()
|
manifest, err := m.loadManifest()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// if there was a problem with the file, we will attempt to write a new
|
// if there was a problem with the file, we will attempt to write a new
|
||||||
|
@ -127,7 +131,7 @@ func (m ModuleStorage) recordModule(rec moduleRecord) error {
|
||||||
// load the manifest from dir, and return all module versions matching the
|
// load the manifest from dir, and return all module versions matching the
|
||||||
// provided source. Records with no version info will be skipped, as they need
|
// provided source. Records with no version info will be skipped, as they need
|
||||||
// to be uniquely identified by other means.
|
// to be uniquely identified by other means.
|
||||||
func (m ModuleStorage) moduleVersions(source string) ([]moduleRecord, error) {
|
func (m Storage) moduleVersions(source string) ([]moduleRecord, error) {
|
||||||
manifest, err := m.loadManifest()
|
manifest, err := m.loadManifest()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return manifest.Modules, err
|
return manifest.Modules, err
|
||||||
|
@ -144,7 +148,7 @@ func (m ModuleStorage) moduleVersions(source string) ([]moduleRecord, error) {
|
||||||
return matching, nil
|
return matching, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m ModuleStorage) moduleDir(key string) (string, error) {
|
func (m Storage) moduleDir(key string) (string, error) {
|
||||||
manifest, err := m.loadManifest()
|
manifest, err := m.loadManifest()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -160,7 +164,7 @@ func (m ModuleStorage) moduleDir(key string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// return only the root directory of the module stored in dir.
|
// return only the root directory of the module stored in dir.
|
||||||
func (m ModuleStorage) getModuleRoot(dir string) (string, error) {
|
func (m Storage) getModuleRoot(dir string) (string, error) {
|
||||||
manifest, err := m.loadManifest()
|
manifest, err := m.loadManifest()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -176,7 +180,7 @@ func (m ModuleStorage) getModuleRoot(dir string) (string, error) {
|
||||||
|
|
||||||
// record only the Root directory for the module stored at dir.
|
// record only the Root directory for the module stored at dir.
|
||||||
// TODO: remove this compatibility function to store the full moduleRecord.
|
// TODO: remove this compatibility function to store the full moduleRecord.
|
||||||
func (m ModuleStorage) recordModuleRoot(dir, root string) error {
|
func (m Storage) recordModuleRoot(dir, root string) error {
|
||||||
rec := moduleRecord{
|
rec := moduleRecord{
|
||||||
Dir: dir,
|
Dir: dir,
|
||||||
Root: root,
|
Root: root,
|
||||||
|
@ -185,7 +189,7 @@ func (m ModuleStorage) recordModuleRoot(dir, root string) error {
|
||||||
return m.recordModule(rec)
|
return m.recordModule(rec)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m ModuleStorage) getStorage(key string, src string) (string, bool, error) {
|
func (m Storage) getStorage(key string, src string) (string, bool, error) {
|
||||||
storage := &getter.FolderStorage{
|
storage := &getter.FolderStorage{
|
||||||
StorageDir: m.StorageDir,
|
StorageDir: m.StorageDir,
|
||||||
}
|
}
|
||||||
|
@ -213,7 +217,7 @@ func (m ModuleStorage) getStorage(key string, src string) (string, bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// find a stored module that's not from a registry
|
// find a stored module that's not from a registry
|
||||||
func (m ModuleStorage) findModule(key string) (string, error) {
|
func (m Storage) findModule(key string) (string, error) {
|
||||||
if m.Mode == GetModeUpdate {
|
if m.Mode == GetModeUpdate {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
@ -222,7 +226,7 @@ func (m ModuleStorage) findModule(key string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// find a registry module
|
// find a registry module
|
||||||
func (m ModuleStorage) findRegistryModule(mSource, constraint string) (moduleRecord, error) {
|
func (m Storage) findRegistryModule(mSource, constraint string) (moduleRecord, error) {
|
||||||
rec := moduleRecord{
|
rec := moduleRecord{
|
||||||
Source: mSource,
|
Source: mSource,
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ func TestTree(t *testing.T, path string) (*Tree, func()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the child modules
|
// Get the child modules
|
||||||
s := &ModuleStorage{StorageDir: dir, Mode: GetModeGet}
|
s := &Storage{StorageDir: dir, Mode: GetModeGet}
|
||||||
if err := mod.Load(s); err != nil {
|
if err := mod.Load(s); err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
|
@ -52,7 +52,7 @@ func NewEmptyTree() *Tree {
|
||||||
// We do this dummy load so that the tree is marked as "loaded". It
|
// We do this dummy load so that the tree is marked as "loaded". It
|
||||||
// should never fail because this is just about a no-op. If it does fail
|
// should never fail because this is just about a no-op. If it does fail
|
||||||
// we panic so we can know its a bug.
|
// we panic so we can know its a bug.
|
||||||
if err := t.Load(&ModuleStorage{Mode: GetModeGet}); err != nil {
|
if err := t.Load(&Storage{Mode: GetModeGet}); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ func (t *Tree) Name() string {
|
||||||
// module trees inherently require the configuration to be in a reasonably
|
// module trees inherently require the configuration to be in a reasonably
|
||||||
// sane state: no circular dependencies, proper module sources, etc. A full
|
// sane state: no circular dependencies, proper module sources, etc. A full
|
||||||
// suite of validations can be done by running Validate (after loading).
|
// suite of validations can be done by running Validate (after loading).
|
||||||
func (t *Tree) Load(s *ModuleStorage) error {
|
func (t *Tree) Load(s *Storage) error {
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ func (t *Tree) Load(s *ModuleStorage) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tree) getChildren(s *ModuleStorage) (map[string]*Tree, error) {
|
func (t *Tree) getChildren(s *Storage) (map[string]*Tree, error) {
|
||||||
children := make(map[string]*Tree)
|
children := make(map[string]*Tree)
|
||||||
|
|
||||||
// Go through all the modules and get the directory for them.
|
// Go through all the modules and get the directory for them.
|
||||||
|
|
|
@ -121,7 +121,7 @@ func TestTreeLoad_duplicate(t *testing.T) {
|
||||||
|
|
||||||
func TestTreeLoad_copyable(t *testing.T) {
|
func TestTreeLoad_copyable(t *testing.T) {
|
||||||
dir := tempDir(t)
|
dir := tempDir(t)
|
||||||
storage := &ModuleStorage{
|
storage := &Storage{
|
||||||
StorageDir: dir,
|
StorageDir: dir,
|
||||||
Mode: GetModeGet,
|
Mode: GetModeGet,
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ func TestTreeLoad_copyable(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
tree := NewTree("", cfg)
|
tree := NewTree("", cfg)
|
||||||
storage := &ModuleStorage{
|
storage := &Storage{
|
||||||
StorageDir: dir2,
|
StorageDir: dir2,
|
||||||
Mode: GetModeNone,
|
Mode: GetModeNone,
|
||||||
}
|
}
|
||||||
|
@ -287,7 +287,7 @@ func TestTree_recordManifest(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(td)
|
defer os.RemoveAll(td)
|
||||||
|
|
||||||
storage := ModuleStorage{StorageDir: td}
|
storage := Storage{StorageDir: td}
|
||||||
|
|
||||||
dir := filepath.Join(td, "0131bf0fef686e090b16bdbab4910ddf")
|
dir := filepath.Join(td, "0131bf0fef686e090b16bdbab4910ddf")
|
||||||
|
|
||||||
|
@ -792,7 +792,7 @@ func TestTreeLoad_changeIntermediateSource(t *testing.T) {
|
||||||
if err := os.MkdirAll(".terraform/modules", 0777); err != nil {
|
if err := os.MkdirAll(".terraform/modules", 0777); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
storage := &ModuleStorage{StorageDir: ".terraform/modules"}
|
storage := &Storage{StorageDir: ".terraform/modules"}
|
||||||
cfg, err := config.LoadDir("./")
|
cfg, err := config.LoadDir("./")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -750,7 +750,7 @@ func testModule(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the modules
|
// Load the modules
|
||||||
modStorage := &module.ModuleStorage{
|
modStorage := &module.Storage{
|
||||||
StorageDir: filepath.Join(cfgPath, ".tfmodules"),
|
StorageDir: filepath.Join(cfgPath, ".tfmodules"),
|
||||||
Mode: module.GetModeGet,
|
Mode: module.GetModeGet,
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ func testModule(t *testing.T, name string) *module.Tree {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &module.ModuleStorage{
|
s := &module.Storage{
|
||||||
StorageDir: tempDir(t),
|
StorageDir: tempDir(t),
|
||||||
Mode: module.GetModeGet,
|
Mode: module.GetModeGet,
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ func testModuleInline(t *testing.T, config map[string]string) *module.Tree {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the modules
|
// Load the modules
|
||||||
modStorage := &module.ModuleStorage{
|
modStorage := &module.Storage{
|
||||||
StorageDir: filepath.Join(cfgPath, ".tfmodules"),
|
StorageDir: filepath.Join(cfgPath, ".tfmodules"),
|
||||||
Mode: module.GetModeGet,
|
Mode: module.GetModeGet,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue