Skip to content

Commit

Permalink
incusd/images: Set authorizer entries at the correct time
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Jul 25, 2024
1 parent 30af813 commit b0b62da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
17 changes: 0 additions & 17 deletions cmd/incusd/daemon_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import (
internalIO "github.com/lxc/incus/v6/internal/io"
"github.com/lxc/incus/v6/internal/server/db"
"github.com/lxc/incus/v6/internal/server/db/cluster"
"github.com/lxc/incus/v6/internal/server/lifecycle"
"github.com/lxc/incus/v6/internal/server/locking"
"github.com/lxc/incus/v6/internal/server/operations"
"github.com/lxc/incus/v6/internal/server/request"
"github.com/lxc/incus/v6/internal/server/response"
"github.com/lxc/incus/v6/internal/server/state"
localUtil "github.com/lxc/incus/v6/internal/server/util"
Expand Down Expand Up @@ -618,20 +616,5 @@ func ImageDownload(ctx context.Context, r *http.Request, s *state.State, op *ope

logger.Info("Image downloaded", ctxMap)

var requestor *api.EventLifecycleRequestor
if op != nil {
requestor = op.Requestor()
} else if r != nil {
requestor = request.CreateRequestor(r)
}

// Add the image to the authorizer.
err = s.Authorizer.AddImage(s.ShutdownCtx, args.ProjectName, info.Fingerprint)
if err != nil {
logger.Error("Failed to add image to authorizer", logger.Ctx{"fingerprint": info.Fingerprint, "project": args.ProjectName, "error": err})
}

s.Events.SendLifecycle(args.ProjectName, lifecycle.ImageCreated.Event(info.Fingerprint, args.ProjectName, requestor, logger.Ctx{"type": info.Type}))

return info, nil
}
13 changes: 13 additions & 0 deletions cmd/incusd/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -2279,6 +2279,19 @@ func autoUpdateImage(ctx context.Context, s *state.State, op *operations.Operati
continue
}
}

// Add the image to the authorizer.
err = s.Authorizer.AddImage(s.ShutdownCtx, projectName, info.Fingerprint)
if err != nil {
logger.Error("Failed to add image to authorizer", logger.Ctx{"fingerprint": info.Fingerprint, "project": projectName, "error": err})
}

var requestor *api.EventLifecycleRequestor
if op != nil {
requestor = op.Requestor()
}

s.Events.SendLifecycle(projectName, lifecycle.ImageCreated.Event(info.Fingerprint, projectName, requestor, logger.Ctx{"type": info.Type}))
}

// Image didn't change, nothing to do.
Expand Down
9 changes: 9 additions & 0 deletions cmd/incusd/instances_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/lxc/incus/v6/internal/server/instance"
"github.com/lxc/incus/v6/internal/server/instance/instancetype"
"github.com/lxc/incus/v6/internal/server/instance/operationlock"
"github.com/lxc/incus/v6/internal/server/lifecycle"
"github.com/lxc/incus/v6/internal/server/operations"
"github.com/lxc/incus/v6/internal/server/project"
"github.com/lxc/incus/v6/internal/server/request"
Expand Down Expand Up @@ -77,6 +78,14 @@ func ensureDownloadedImageFitWithinBudget(ctx context.Context, s *state.State, r
return nil, err
}

// Add the image to the authorizer.
err = s.Authorizer.AddImage(s.ShutdownCtx, p.Name, imgDownloaded.Fingerprint)
if err != nil {
logger.Error("Failed to add image to authorizer", logger.Ctx{"fingerprint": imgDownloaded.Fingerprint, "project": p.Name, "error": err})
}

s.Events.SendLifecycle(p.Name, lifecycle.ImageCreated.Event(imgDownloaded.Fingerprint, p.Name, op.Requestor(), logger.Ctx{"type": imgDownloaded.Type}))

return imgDownloaded, nil
}

Expand Down

0 comments on commit b0b62da

Please sign in to comment.