Skip to content

Commit

Permalink
PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 committed Sep 6, 2023
1 parent cfa2d85 commit 8782743
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions cmd/jimmctl/cmd/importmodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import (
const importModelCommandDoc = `
import-model imports a model running on a controller to jimm.
When importing, it is necessary for JIMM to contain cloud credentials
for the user against the cloud the incoming model resides.
The --owner command is necessary when importing a model created by a
local user and will switch the model owner to the desired external user.
E.g. --owner my-user@external
Example:
jimmctl import-model <controller name> <model-uuid>
jimmctl import-model <controller name> <model-uuid> --owner <username>
Expand Down
13 changes: 10 additions & 3 deletions internal/jimm/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ func (j *JIMM) ImportModel(ctx context.Context, u *dbmodel.User, controllerName
if err != nil {
return errors.E(op, err)
}
if ownerTag.IsLocal() {
return errors.E(op, "cannot import model from local user, try --owner to switch the model owner")
}
ownerUser := dbmodel.User{}
ownerUser.SetTag(ownerTag)
err = j.Database.GetUser(ctx, &ownerUser)
Expand Down Expand Up @@ -554,9 +557,13 @@ func (j *JIMM) ImportModel(ctx context.Context, u *dbmodel.User, controllerName

var usersExcludingLocalUsers []dbmodel.UserModelAccess
for _, userAccess := range model.Users {
if !strings.Contains(userAccess.User.Username, "@") {
// If the username doesn't contain an "@" the user is local
// to the controller and we don't want to propagate it.
username, err := names.ParseUserTag(userAccess.User.Username)
if err != nil {
zapctx.Error(ctx, "failed to parse user tag", zap.String("username", userAccess.User.Username))
continue
}
if username.IsLocal() {
// Don't propogate local users into JIMM.
continue
}
usersExcludingLocalUsers = append(usersExcludingLocalUsers, userAccess)
Expand Down

0 comments on commit 8782743

Please sign in to comment.