command: move remote configuration stuff

This commit is contained in:
Mitchell Hashimoto 2015-03-04 16:17:30 -08:00
parent a4bc5ba3ff
commit 01cd761023
8 changed files with 45 additions and 57 deletions

View File

@ -120,7 +120,7 @@ func (c *InitCommand) Run(args []string) int {
}
// Initialize a blank state file with remote enabled
remoteCmd := &RemoteCommand{
remoteCmd := &RemoteConfigCommand{
Meta: c.Meta,
remoteConf: remoteConf,
}

View File

@ -21,15 +21,15 @@ type remoteCommandConfig struct {
backupPath string
}
// RemoteCommand is a Command implementation that is used to
// RemoteConfigCommand is a Command implementation that is used to
// enable and disable remote state management
type RemoteCommand struct {
type RemoteConfigCommand struct {
Meta
conf remoteCommandConfig
remoteConf terraform.RemoteState
}
func (c *RemoteCommand) Run(args []string) int {
func (c *RemoteConfigCommand) Run(args []string) int {
args = c.Meta.process(args, false)
config := make(map[string]string)
cmdFlags := flag.NewFlagSet("remote", flag.ContinueOnError)
@ -115,7 +115,7 @@ func (c *RemoteCommand) Run(args []string) int {
// disableRemoteState is used to disable remote state management,
// and move the state file into place.
func (c *RemoteCommand) disableRemoteState() int {
func (c *RemoteConfigCommand) disableRemoteState() int {
if c.stateResult == nil {
c.Ui.Error(fmt.Sprintf(
"Internal error. State() must be called internally before remote\n" +
@ -173,7 +173,7 @@ func (c *RemoteCommand) disableRemoteState() int {
// validateRemoteConfig is used to verify that the remote configuration
// we have is valid
func (c *RemoteCommand) validateRemoteConfig() error {
func (c *RemoteConfigCommand) validateRemoteConfig() error {
conf := c.remoteConf
_, err := remote.NewClient(conf.Type, conf.Config)
if err != nil {
@ -184,7 +184,7 @@ func (c *RemoteCommand) validateRemoteConfig() error {
// initBlank state is used to initialize a blank state that is
// remote enabled
func (c *RemoteCommand) initBlankState() int {
func (c *RemoteConfigCommand) initBlankState() int {
// Validate the remote configuration
if err := c.validateRemoteConfig(); err != nil {
return 1
@ -212,7 +212,7 @@ func (c *RemoteCommand) initBlankState() int {
// updateRemoteConfig is used to update the configuration of the
// remote state store
func (c *RemoteCommand) updateRemoteConfig() int {
func (c *RemoteConfigCommand) updateRemoteConfig() int {
// Validate the remote configuration
if err := c.validateRemoteConfig(); err != nil {
return 1
@ -240,7 +240,7 @@ func (c *RemoteCommand) updateRemoteConfig() int {
// enableRemoteState is used to enable remote state management
// and to move a state file into place
func (c *RemoteCommand) enableRemoteState() int {
func (c *RemoteConfigCommand) enableRemoteState() int {
// Validate the remote configuration
if err := c.validateRemoteConfig(); err != nil {
return 1
@ -299,7 +299,7 @@ func (c *RemoteCommand) enableRemoteState() int {
return 0
}
func (c *RemoteCommand) Help() string {
func (c *RemoteConfigCommand) Help() string {
helpText := `
Usage: terraform remote [options]
@ -334,6 +334,6 @@ Options:
return strings.TrimSpace(helpText)
}
func (c *RemoteCommand) Synopsis() string {
func (c *RemoteConfigCommand) Synopsis() string {
return "Configures remote state management"
}

View File

@ -8,11 +8,11 @@ import (
"github.com/hashicorp/terraform/state"
)
type PullCommand struct {
type RemotePullCommand struct {
Meta
}
func (c *PullCommand) Run(args []string) int {
func (c *RemotePullCommand) Run(args []string) int {
args = c.Meta.process(args, false)
cmdFlags := flag.NewFlagSet("pull", flag.ContinueOnError)
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
@ -67,7 +67,7 @@ func (c *PullCommand) Run(args []string) int {
return 0
}
func (c *PullCommand) Help() string {
func (c *RemotePullCommand) Help() string {
helpText := `
Usage: terraform pull [options]
@ -77,6 +77,6 @@ Usage: terraform pull [options]
return strings.TrimSpace(helpText)
}
func (c *PullCommand) Synopsis() string {
func (c *RemotePullCommand) Synopsis() string {
return "Refreshes the local state copy from the remote server"
}

View File

@ -15,12 +15,12 @@ import (
"github.com/mitchellh/cli"
)
func TestPull_noRemote(t *testing.T) {
func TestRemotePull_noRemote(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
ui := new(cli.MockUi)
c := &PullCommand{
c := &RemotePullCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
@ -33,7 +33,7 @@ func TestPull_noRemote(t *testing.T) {
}
}
func TestPull_local(t *testing.T) {
func TestRemotePull_local(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
@ -62,7 +62,7 @@ func TestPull_local(t *testing.T) {
}
ui := new(cli.MockUi)
c := &PullCommand{
c := &RemotePullCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,

View File

@ -8,11 +8,11 @@ import (
"github.com/hashicorp/terraform/state"
)
type PushCommand struct {
type RemotePushCommand struct {
Meta
}
func (c *PushCommand) Run(args []string) int {
func (c *RemotePushCommand) Run(args []string) int {
var force bool
args = c.Meta.process(args, false)
cmdFlags := flag.NewFlagSet("push", flag.ContinueOnError)
@ -71,7 +71,7 @@ func (c *PushCommand) Run(args []string) int {
return 0
}
func (c *PushCommand) Help() string {
func (c *RemotePushCommand) Help() string {
helpText := `
Usage: terraform push [options]
@ -87,6 +87,6 @@ Options:
return strings.TrimSpace(helpText)
}
func (c *PushCommand) Synopsis() string {
func (c *RemotePushCommand) Synopsis() string {
return "Uploads the the local state to the remote server"
}

View File

@ -9,12 +9,12 @@ import (
"github.com/mitchellh/cli"
)
func TestPush_noRemote(t *testing.T) {
func TestRemotePush_noRemote(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
ui := new(cli.MockUi)
c := &PushCommand{
c := &RemotePushCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
@ -27,7 +27,7 @@ func TestPush_noRemote(t *testing.T) {
}
}
func TestPush_local(t *testing.T) {
func TestRemotePush_local(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
@ -56,7 +56,7 @@ func TestPush_local(t *testing.T) {
}
ui := new(cli.MockUi)
c := &PushCommand{
c := &RemotePushCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,

View File

@ -13,7 +13,7 @@ import (
)
// Test disabling remote management
func TestRemote_disable(t *testing.T) {
func TestRemoteConfig_disable(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
@ -39,7 +39,7 @@ func TestRemote_disable(t *testing.T) {
}
ui := new(cli.MockUi)
c := &RemoteCommand{
c := &RemoteConfigCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
@ -68,7 +68,7 @@ func TestRemote_disable(t *testing.T) {
}
// Test disabling remote management without pulling
func TestRemote_disable_noPull(t *testing.T) {
func TestRemoteConfig_disable_noPull(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
@ -94,7 +94,7 @@ func TestRemote_disable_noPull(t *testing.T) {
}
ui := new(cli.MockUi)
c := &RemoteCommand{
c := &RemoteConfigCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
@ -122,12 +122,12 @@ func TestRemote_disable_noPull(t *testing.T) {
}
// Test disabling remote management when not enabled
func TestRemote_disable_notEnabled(t *testing.T) {
func TestRemoteConfig_disable_notEnabled(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
ui := new(cli.MockUi)
c := &RemoteCommand{
c := &RemoteConfigCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
@ -141,7 +141,7 @@ func TestRemote_disable_notEnabled(t *testing.T) {
}
// Test disabling remote management with a state file in the way
func TestRemote_disable_otherState(t *testing.T) {
func TestRemoteConfig_disable_otherState(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
@ -171,7 +171,7 @@ func TestRemote_disable_otherState(t *testing.T) {
}
ui := new(cli.MockUi)
c := &RemoteCommand{
c := &RemoteConfigCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
@ -185,7 +185,7 @@ func TestRemote_disable_otherState(t *testing.T) {
}
// Test the case where both managed and non managed state present
func TestRemote_managedAndNonManaged(t *testing.T) {
func TestRemoteConfig_managedAndNonManaged(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
@ -215,7 +215,7 @@ func TestRemote_managedAndNonManaged(t *testing.T) {
}
ui := new(cli.MockUi)
c := &RemoteCommand{
c := &RemoteConfigCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
@ -229,12 +229,12 @@ func TestRemote_managedAndNonManaged(t *testing.T) {
}
// Test initializing blank state
func TestRemote_initBlank(t *testing.T) {
func TestRemoteConfig_initBlank(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
ui := new(cli.MockUi)
c := &RemoteCommand{
c := &RemoteConfigCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
@ -269,12 +269,12 @@ func TestRemote_initBlank(t *testing.T) {
}
// Test initializing without remote settings
func TestRemote_initBlank_missingRemote(t *testing.T) {
func TestRemoteConfig_initBlank_missingRemote(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
ui := new(cli.MockUi)
c := &RemoteCommand{
c := &RemoteConfigCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
@ -288,7 +288,7 @@ func TestRemote_initBlank_missingRemote(t *testing.T) {
}
// Test updating remote config
func TestRemote_updateRemote(t *testing.T) {
func TestRemoteConfig_updateRemote(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
@ -310,7 +310,7 @@ func TestRemote_updateRemote(t *testing.T) {
}
ui := new(cli.MockUi)
c := &RemoteCommand{
c := &RemoteConfigCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,
@ -345,7 +345,7 @@ func TestRemote_updateRemote(t *testing.T) {
}
// Test enabling remote state
func TestRemote_enableRemote(t *testing.T) {
func TestRemoteConfig_enableRemote(t *testing.T) {
tmp, cwd := testCwd(t)
defer testFixCwd(t, tmp, cwd)
@ -365,7 +365,7 @@ func TestRemote_enableRemote(t *testing.T) {
}
ui := new(cli.MockUi)
c := &RemoteCommand{
c := &RemoteConfigCommand{
Meta: Meta{
ContextOpts: testCtxConfig(testProvider()),
Ui: ui,

View File

@ -80,18 +80,6 @@ func init() {
}, nil
},
"pull": func() (cli.Command, error) {
return &command.PullCommand{
Meta: meta,
}, nil
},
"push": func() (cli.Command, error) {
return &command.PushCommand{
Meta: meta,
}, nil
},
"refresh": func() (cli.Command, error) {
return &command.RefreshCommand{
Meta: meta,