-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #813 from BajuMcBites/instance-access-sb
api: Implement new access API
- Loading branch information
Showing
31 changed files
with
2,616 additions
and
1,948 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/gorilla/mux" | ||
|
||
internalInstance "github.com/lxc/incus/v6/internal/instance" | ||
"github.com/lxc/incus/v6/internal/server/request" | ||
"github.com/lxc/incus/v6/internal/server/response" | ||
) | ||
|
||
// swagger:operation GET /1.0/instances/{name}/access instances instance_access | ||
// | ||
// Get who has access to an instnace | ||
// | ||
// Gets the access information for the instance. | ||
// | ||
// --- | ||
// produces: | ||
// - application/json | ||
// parameters: | ||
// - in: query | ||
// name: project | ||
// description: Project name | ||
// type: string | ||
// responses: | ||
// "200": | ||
// description: Access | ||
// schema: | ||
// type: object | ||
// description: Sync response | ||
// properties: | ||
// type: | ||
// type: string | ||
// description: Response type | ||
// example: sync | ||
// status: | ||
// type: string | ||
// description: Status description | ||
// example: Success | ||
// status_code: | ||
// type: integer | ||
// description: Status code | ||
// example: 200 | ||
// metadata: | ||
// $ref: "#/definitions/Access" | ||
// "400": | ||
// $ref: "#/responses/BadRequest" | ||
// "403": | ||
// $ref: "#/responses/Forbidden" | ||
// "500": | ||
// $ref: "#/responses/InternalServerError" | ||
func instanceAccess(d *Daemon, r *http.Request) response.Response { | ||
s := d.State() | ||
|
||
instanceType, err := urlInstanceTypeDetect(r) | ||
if err != nil { | ||
return response.SmartError(err) | ||
} | ||
|
||
projectName := request.ProjectParam(r) | ||
name, err := url.PathUnescape(mux.Vars(r)["name"]) | ||
if err != nil { | ||
return response.SmartError(err) | ||
} | ||
|
||
if internalInstance.IsSnapshot(name) { | ||
return response.BadRequest(fmt.Errorf("Invalid instance name")) | ||
} | ||
|
||
// Handle requests targeted to a container on a different node | ||
resp, err := forwardedResponseIfInstanceIsRemote(s, r, projectName, name, instanceType) | ||
if err != nil { | ||
return response.SmartError(err) | ||
} | ||
|
||
if resp != nil { | ||
return resp | ||
} | ||
|
||
access, err := s.Authorizer.GetInstanceAccess(context.TODO(), projectName, mux.Vars(r)["name"]) | ||
|
||
if err != nil { | ||
return response.InternalError(err) | ||
} | ||
|
||
return response.SyncResponse(true, access) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.