Skip to content

Commit

Permalink
*** WIP. ROLL BACK. ***
Browse files Browse the repository at this point in the history
  • Loading branch information
manadart committed Nov 26, 2024
1 parent 89d2088 commit ce023dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
20 changes: 10 additions & 10 deletions apiserver/facades/client/modelmanager/modelmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ func (m *ModelManagerAPI) createModelNew(
// we will try and apply the defaults where authorisation allows us to.
defaultCloudName, _, err := m.modelService.DefaultModelCloudNameAndCredential(ctx)
if errors.Is(err, modelerrors.NotFound) {
return coremodel.UUID(""), errors.New("failed to find default model cloud and credential for controller")
return "", errors.New("failed to find default model cloud and credential for controller")
}

var cloudTag names.CloudTag
if args.CloudTag != "" {
var err error
cloudTag, err = names.ParseCloudTag(args.CloudTag)
if err != nil {
return coremodel.UUID(""), errors.Trace(err)
return "", errors.Trace(err)
}
} else {
cloudTag = names.NewCloudTag(defaultCloudName)
Expand All @@ -233,33 +233,33 @@ func (m *ModelManagerAPI) createModelNew(

err = m.authorizer.HasPermission(ctx, permission.SuperuserAccess, m.state.ControllerTag())
if err != nil && !errors.Is(err, authentication.ErrorEntityMissingPermission) {
return coremodel.UUID(""), errors.Trace(err)
return "", errors.Trace(err)
}
if err != nil {
canAddModel, err := m.checkAddModelPermission(ctx, cloudTag.Id(), m.apiUser)
if err != nil {
return coremodel.UUID(""), errors.Trace(err)
return "", errors.Trace(err)
}
if !canAddModel {
return coremodel.UUID(""), apiservererrors.ErrPerm
return "", apiservererrors.ErrPerm
}
}

ownerTag, err := names.ParseUserTag(args.OwnerTag)
if err != nil {
return coremodel.UUID(""), errors.Trace(err)
return "", errors.Trace(err)
}

// a special case of ErrPerm will happen if the user has add-model permission but is trying to
// create a model for another person, which is not yet supported.
if !m.isAdmin && ownerTag != m.apiUser {
return coremodel.UUID(""), errors.Annotatef(apiservererrors.ErrPerm, "%q permission does not permit creation of models for different owners", permission.AddModelAccess)
return "", errors.Annotatef(apiservererrors.ErrPerm, "%q permission does not permit creation of models for different owners", permission.AddModelAccess)
}

user, err := m.accessService.GetUserByName(ctx, user.NameFromTag(ownerTag))
if err != nil {
// TODO handle error properly
return coremodel.UUID(""), errors.Trace(err)
return "", errors.Trace(err)
}
creationArgs.Owner = user.UUID

Expand All @@ -268,7 +268,7 @@ func (m *ModelManagerAPI) createModelNew(
var err error
cloudCredentialTag, err = names.ParseCloudCredentialTag(args.CloudCredentialTag)
if err != nil {
return coremodel.UUID(""), errors.Trace(err)
return "", errors.Trace(err)
}

creationArgs.Credential = credential.KeyFromTag(cloudCredentialTag)
Expand All @@ -277,7 +277,7 @@ func (m *ModelManagerAPI) createModelNew(
// Create the model in the controller database.
modelID, activator, err := m.modelService.CreateModel(ctx, creationArgs)
if err != nil {
return coremodel.UUID(""), errors.Annotatef(err, "failed to create model %q", modelID)
return "", errors.Annotatef(err, "failed to create model %q", modelID)
}

// We need to get the model domain services from the newly created model
Expand Down
1 change: 0 additions & 1 deletion domain/model/service/modelservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func (s *ModelService) CreateModel(

args := model.ReadOnlyModelCreationArgs{
UUID: m.UUID,
AgentVersion: m.AgentVersion,
ControllerUUID: controllerUUID,
Name: m.Name,
Type: m.ModelType,
Expand Down

0 comments on commit ce023dd

Please sign in to comment.