Skip to content

Commit

Permalink
client/incus: Fallback to operation wait when project events aren't a…
Browse files Browse the repository at this point in the history
…ccessible

If we're not allowed to get a project-wide event stream, fallback to the
operations wait API. This is to accomodate the rare situation where a
user is given access to specific instances within a project but without
any other project-wide permissions.

Closes #292

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Mar 28, 2024
1 parent 16661b3 commit 1d5b243
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions client/incus.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,13 @@ func (r *ProtocolIncus) queryStruct(method string, path string, data any, ETag s
// It sets up an early event listener, performs the query, processes the response, and manages the lifecycle of the event listener.
func (r *ProtocolIncus) queryOperation(method string, path string, data any, ETag string) (Operation, string, error) {
// Attempt to setup an early event listener
skipListener := false
listener, err := r.GetEvents()
if err != nil {
if api.StatusErrorCheck(err, http.StatusForbidden) {
skipListener = true
}

listener = nil
}

Expand All @@ -393,10 +398,11 @@ func (r *ProtocolIncus) queryOperation(method string, path string, data any, ETa

// Setup an Operation wrapper
op := operation{
Operation: *respOperation,
r: r,
listener: listener,
chActive: make(chan bool),
Operation: *respOperation,
r: r,
listener: listener,
skipListener: skipListener,
chActive: make(chan bool),
}

// Log the data
Expand Down

0 comments on commit 1d5b243

Please sign in to comment.