Add WorkDir method to airshipctl config
The method also creates a directory if it doesn't exist. Relates-To: #480 Closes: #480 Change-Id: I240b963c0b850bb3965396473898eb23df7c5a62
This commit is contained in:
parent
f0523a3808
commit
dae03cff83
@ -583,3 +583,13 @@ func (c *Config) CurrentContextManifestMetadata() (*Metadata, error) {
|
|||||||
}
|
}
|
||||||
return meta, nil
|
return meta, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WorkDir returns working directory for airshipctl. Creates if it doesn't exist
|
||||||
|
func (c *Config) WorkDir() (dir string, err error) {
|
||||||
|
dir = filepath.Join(util.UserHomeDir(), AirshipConfigDir)
|
||||||
|
// if not dir, create it
|
||||||
|
if !c.fileSystem.IsDir(dir) {
|
||||||
|
err = c.fileSystem.MkdirAll(dir)
|
||||||
|
}
|
||||||
|
return dir, err
|
||||||
|
}
|
||||||
|
@ -541,3 +541,11 @@ func TestModifyEncryptionConfigs(t *testing.T) {
|
|||||||
conf.ModifyEncryptionConfig(encryptionConfig, eco)
|
conf.ModifyEncryptionConfig(encryptionConfig, eco)
|
||||||
assert.Equal(t, eco.DecryptionKeyPath, modifiedConfig.DecryptionKeyPath)
|
assert.Equal(t, eco.DecryptionKeyPath, modifiedConfig.DecryptionKeyPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWorkDir(t *testing.T) {
|
||||||
|
conf, cleanup := testutil.InitConfig(t)
|
||||||
|
defer cleanup(t)
|
||||||
|
wd, err := conf.WorkDir()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotEmpty(t, wd)
|
||||||
|
}
|
||||||
|
@ -28,7 +28,6 @@ import (
|
|||||||
inventoryifc "opendev.org/airship/airshipctl/pkg/inventory/ifc"
|
inventoryifc "opendev.org/airship/airshipctl/pkg/inventory/ifc"
|
||||||
"opendev.org/airship/airshipctl/pkg/log"
|
"opendev.org/airship/airshipctl/pkg/log"
|
||||||
"opendev.org/airship/airshipctl/pkg/phase/ifc"
|
"opendev.org/airship/airshipctl/pkg/phase/ifc"
|
||||||
"opendev.org/airship/airshipctl/pkg/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Helper provides functions built around phase bundle to filter and build documents
|
// Helper provides functions built around phase bundle to filter and build documents
|
||||||
@ -41,11 +40,14 @@ type Helper struct {
|
|||||||
|
|
||||||
inventory inventoryifc.Inventory
|
inventory inventoryifc.Inventory
|
||||||
metadata *config.Metadata
|
metadata *config.Metadata
|
||||||
|
config *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHelper constructs metadata interface based on config
|
// NewHelper constructs metadata interface based on config
|
||||||
func NewHelper(cfg *config.Config) (ifc.Helper, error) {
|
func NewHelper(cfg *config.Config) (ifc.Helper, error) {
|
||||||
helper := &Helper{}
|
helper := &Helper{
|
||||||
|
config: cfg,
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
helper.targetPath, err = cfg.CurrentContextTargetPath()
|
helper.targetPath, err = cfg.CurrentContextTargetPath()
|
||||||
@ -321,10 +323,9 @@ func (helper *Helper) PhaseEntryPointBasePath() string {
|
|||||||
return helper.phaseEntryPointBasePath
|
return helper.phaseEntryPointBasePath
|
||||||
}
|
}
|
||||||
|
|
||||||
// WorkDir return manifest root
|
// WorkDir return working directory for aisrhipctl, creates it, if doesn't exist
|
||||||
// TODO add creation of WorkDir if it doesn't exist
|
|
||||||
func (helper *Helper) WorkDir() (string, error) {
|
func (helper *Helper) WorkDir() (string, error) {
|
||||||
return filepath.Join(util.UserHomeDir(), config.AirshipConfigDir), nil
|
return helper.config.WorkDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inventory return inventory interface
|
// Inventory return inventory interface
|
||||||
|
Loading…
x
Reference in New Issue
Block a user