Esempio n. 1
0
func (s *ModelValidationSuite) TestValidateModelName(c *gc.C) {
	c.Assert(jujuclient.ValidateModelName("foo@bar/baz"), jc.ErrorIsNil)
	c.Assert(jujuclient.ValidateModelName("foo"), gc.ErrorMatches, `validating model name "foo": unqualified model name "foo" not valid`)
	c.Assert(jujuclient.ValidateModelName(""), gc.ErrorMatches, `validating model name "": unqualified model name "" not valid`)
	c.Assert(jujuclient.ValidateModelName("!"), gc.ErrorMatches, `validating model name "!": unqualified model name "!" not valid`)
	c.Assert(jujuclient.ValidateModelName("!/foo"), gc.ErrorMatches, `validating model name "!/foo": user name "!" not valid`)
}
Esempio n. 2
0
// UpdateModel implements ModelUpdater.
func (c *MemStore) UpdateModel(controller, account, model string, details jujuclient.ModelDetails) error {
	if err := jujuclient.ValidateControllerName(controller); err != nil {
		return err
	}
	if err := jujuclient.ValidateAccountName(account); err != nil {
		return err
	}
	if err := jujuclient.ValidateModelName(model); err != nil {
		return err
	}
	if err := jujuclient.ValidateModelDetails(details); err != nil {
		return err
	}
	controllerAccountModels, ok := c.Models[controller]
	if !ok {
		controllerAccountModels.AccountModels = make(map[string]*jujuclient.AccountModels)
		c.Models[controller] = controllerAccountModels
	}
	accountModels, ok := controllerAccountModels.AccountModels[account]
	if !ok {
		accountModels = &jujuclient.AccountModels{
			Models: make(map[string]jujuclient.ModelDetails),
		}
		controllerAccountModels.AccountModels[account] = accountModels
	}
	accountModels.Models[model] = details
	return nil
}
Esempio n. 3
0
// RemoveModel implements ModelRemover.
func (c *MemStore) RemoveModel(controller, account, model string) error {
	if err := jujuclient.ValidateControllerName(controller); err != nil {
		return err
	}
	if err := jujuclient.ValidateAccountName(account); err != nil {
		return err
	}
	if err := jujuclient.ValidateModelName(model); err != nil {
		return err
	}
	controllerAccountModels, ok := c.Models[controller]
	if !ok {
		return errors.NotFoundf("models for controller %s", controller)
	}
	accountModels, ok := controllerAccountModels.AccountModels[account]
	if !ok {
		return errors.NotFoundf(
			"models for account %s on controller %s",
			account, controller,
		)
	}
	if _, ok := accountModels.Models[model]; !ok {
		return errors.NotFoundf("model %s:%s:%s", controller, account, model)
	}
	delete(accountModels.Models, model)
	if accountModels.CurrentModel == model {
		accountModels.CurrentModel = ""
	}
	return nil
}
Esempio n. 4
0
// SetCurrentModel implements ModelUpdater.
func (c *MemStore) SetCurrentModel(controllerName, accountName, modelName string) error {
	if err := jujuclient.ValidateControllerName(controllerName); err != nil {
		return errors.Trace(err)
	}
	if err := jujuclient.ValidateAccountName(accountName); err != nil {
		return err
	}
	if err := jujuclient.ValidateModelName(modelName); err != nil {
		return errors.Trace(err)
	}
	controllerAccountModels, ok := c.Models[controllerName]
	if !ok {
		return errors.NotFoundf("models for controller %s", controllerName)
	}
	accountModels, ok := controllerAccountModels.AccountModels[accountName]
	if !ok {
		return errors.NotFoundf(
			"models for account %s on controller %s",
			accountName, controllerName,
		)
	}
	if _, ok := accountModels.Models[modelName]; !ok {
		return errors.NotFoundf("model %s:%s:%s", controllerName, accountName, modelName)
	}
	accountModels.CurrentModel = modelName
	return nil
}
Esempio n. 5
0
// ModelByName implements ModelGetter.
func (c *MemStore) ModelByName(controller, account, model string) (*jujuclient.ModelDetails, error) {
	if err := jujuclient.ValidateControllerName(controller); err != nil {
		return nil, err
	}
	if err := jujuclient.ValidateAccountName(account); err != nil {
		return nil, err
	}
	if err := jujuclient.ValidateModelName(model); err != nil {
		return nil, err
	}
	controllerAccountModels, ok := c.Models[controller]
	if !ok {
		return nil, errors.NotFoundf("models for controller %s", controller)
	}
	accountModels, ok := controllerAccountModels.AccountModels[account]
	if !ok {
		return nil, errors.NotFoundf("models for account %s on controller %s", account, controller)
	}
	details, ok := accountModels.Models[model]
	if !ok {
		return nil, errors.NotFoundf("model %s:%s:%s", controller, account, model)
	}
	return &details, nil
}
func (s *ModelValidationSuite) TestValidateModelName(c *gc.C) {
	c.Assert(jujuclient.ValidateModelName(""), gc.ErrorMatches, "empty model name not valid")
}