func (s *CredentialsFileSuite) TestReadEmptyFile(c *gc.C) {
	err := ioutil.WriteFile(osenv.JujuXDGDataHomePath("credentials.yaml"), []byte(""), 0600)
	c.Assert(err, jc.ErrorIsNil)

	credentialstore := jujuclient.NewFileCredentialStore()
	_, err = credentialstore.CredentialForCloud("foo")
	c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
Beispiel #2
0
// NewDetectCredentialsCommand returns a command to add credential information to credentials.yaml.
func NewDetectCredentialsCommand() cmd.Command {
	c := &detectCredentialsCommand{
		store: jujuclient.NewFileCredentialStore(),
		registeredProvidersFunc: environs.RegisteredProviders,
		cloudByNameFunc:         jujucloud.CloudByName,
	}
	c.allCloudsFunc = func() (map[string]jujucloud.Cloud, error) {
		return c.allClouds()
	}
	return c
}
Beispiel #3
0
func (s *CredentialsSuite) SetUpTest(c *gc.C) {
	s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
	s.store = jujuclient.NewFileCredentialStore()
	s.cloudName = "testcloud"
	s.credentials = cloud.CloudCredential{
		DefaultCredential: "peter",
		DefaultRegion:     "east",
		AuthCredentials: map[string]cloud.Credential{
			"peter": cloud.NewCredential(cloud.AccessKeyAuthType, nil),
			"paul":  cloud.NewCredential(cloud.AccessKeyAuthType, nil),
		},
	}
}
Beispiel #4
0
func (s *CredentialsSuite) TestUpdateCredentialRemovesDefaultIfNecessary(c *gc.C) {
	s.cloudName = firstTestCloudName(c)

	store := jujuclient.NewFileCredentialStore()
	err := store.UpdateCredential(s.cloudName, s.credentials)
	c.Assert(err, jc.ErrorIsNil)
	newCreds := s.credentials
	// "peter" is the default credential
	delete(newCreds.AuthCredentials, "peter")
	err = store.UpdateCredential(s.cloudName, newCreds)
	c.Assert(err, jc.ErrorIsNil)
	creds, err := store.AllCredentials()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(creds[s.cloudName].DefaultCredential, gc.Equals, "")
}
func (s *CredentialsSuite) TestUpdateCredentialRemovesDefaultIfNecessary(c *gc.C) {
	origHome := osenv.SetJujuXDGDataHome(c.MkDir())
	s.AddCleanup(func(*gc.C) { osenv.SetJujuXDGDataHome(origHome) })

	s.cloudName = firstTestCloudName(c)

	store := jujuclient.NewFileCredentialStore()
	err := store.UpdateCredential(s.cloudName, s.credentials)
	c.Assert(err, jc.ErrorIsNil)
	newCreds := s.credentials
	// "peter" is the default credential
	delete(newCreds.AuthCredentials, "peter")
	err = store.UpdateCredential(s.cloudName, newCreds)
	c.Assert(err, jc.ErrorIsNil)
	creds, err := store.AllCredentials()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(creds[s.cloudName].DefaultCredential, gc.Equals, "")
}
Beispiel #6
0
// NewCreateModelCommand returns a command to create an model.
func NewCreateModelCommand() cmd.Command {
	return modelcmd.WrapController(&createModelCommand{
		credentialStore: jujuclient.NewFileCredentialStore(),
	})
}
Beispiel #7
0
// NewremoveCredentialCommand returns a command to remove a named credential for a cloud.
func NewRemoveCredentialCommand() cmd.Command {
	return &removeCredentialCommand{
		store: jujuclient.NewFileCredentialStore(),
	}
}
Beispiel #8
0
// NewSetDefaultCredentialCommand returns a command to set the default credential for a cloud.
func NewSetDefaultCredentialCommand() cmd.Command {
	return &setDefaultCredentialCommand{
		store: jujuclient.NewFileCredentialStore(),
	}
}
Beispiel #9
0
// NewAddCredentialCommand returns a command to add credential information.
func NewAddCredentialCommand() cmd.Command {
	return &addCredentialCommand{
		store:           jujuclient.NewFileCredentialStore(),
		cloudByNameFunc: jujucloud.CloudByName,
	}
}
Beispiel #10
0
// NewListCredentialsCommand returns a command to list cloud credentials.
func NewListCredentialsCommand() cmd.Command {
	return &listCredentialsCommand{
		store:           jujuclient.NewFileCredentialStore(),
		cloudByNameFunc: jujucloud.CloudByName,
	}
}