-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: SCIM list provider users #3405
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
03f5cf7
feat: scim list provider users
BruceMacD 70f6c79
feat: scim list provider users
BruceMacD b3bdb8e
feat: scim list provider users
BruceMacD 12f5be5
feat: scim list provider users
BruceMacD 00e7a67
feat: scim list provider users
BruceMacD d3b2c75
feat: scim list provider users
BruceMacD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package api | ||
|
||
import "github.com/infrahq/infra/internal/validate" | ||
|
||
type SCIMUserName struct { | ||
GivenName string `json:"givenName"` | ||
FamilyName string `json:"familyName"` | ||
} | ||
|
||
type SCIMUserEmail struct { | ||
Primary bool `json:"primary"` | ||
Value string `json:"value"` | ||
} | ||
|
||
func (r SCIMUserEmail) ValidationRules() []validate.ValidationRule { | ||
return []validate.ValidationRule{ | ||
validate.Required("value", r.Value), | ||
validate.Email("value", r.Value), | ||
} | ||
} | ||
|
||
const UserSchema = "urn:ietf:params:scim:schemas:core:2.0:User" | ||
|
||
type SCIMMetadata struct { | ||
ResourceType string `json:"resourceType"` | ||
} | ||
|
||
type SCIMUser struct { | ||
Schemas []string `json:"schemas"` | ||
ID string `json:"id"` | ||
UserName string `json:"userName"` | ||
Name SCIMUserName `json:"name"` | ||
Emails []SCIMUserEmail `json:"emails"` | ||
Active bool `json:"active"` | ||
Meta SCIMMetadata `json:"meta"` | ||
} | ||
|
||
type SCIMParametersRequest struct { | ||
// these pagination parameters must conform to the SCIM spec, rather than our standard pagination | ||
StartIndex int `form:"startIndex"` | ||
Count int `form:"count"` | ||
} | ||
|
||
func (r SCIMParametersRequest) ValidationRules() []validate.ValidationRule { | ||
return []validate.ValidationRule{ | ||
validate.IntRule{ | ||
Name: "startIndex", | ||
Value: r.StartIndex, | ||
Min: validate.Int(0), | ||
}, | ||
validate.IntRule{ | ||
Name: "count", | ||
Value: r.Count, | ||
Min: validate.Int(0), | ||
}, | ||
} | ||
} | ||
|
||
const ListResponseSchema = "urn:ietf:params:scim:api:messages:2.0:ListResponse" | ||
|
||
type ListProviderUsersResponse struct { | ||
Schemas []string `json:"schemas"` | ||
TotalResults int `json:"totalResults"` | ||
Resources []SCIMUser `json:"Resources"` // intentionally capitalized | ||
StartIndex int `json:"startIndex"` | ||
ItemsPerPage int `json:"itemsPerPage"` | ||
} |
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,20 @@ | ||
package access | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gin-gonic/gin" | ||
|
||
"github.com/infrahq/infra/internal/server/data" | ||
"github.com/infrahq/infra/internal/server/models" | ||
) | ||
|
||
func ListProviderUsers(c *gin.Context, p *data.SCIMParameters) ([]models.ProviderUser, error) { | ||
// this can only be run by an access key issued for an identity provider | ||
ctx := GetRequestContext(c) | ||
users, err := data.ListProviderUsers(ctx.DBTxn, ctx.Authenticated.AccessKey.IssuedFor, p) | ||
BruceMacD marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return nil, fmt.Errorf("list provider users: %w", err) | ||
} | ||
return users, nil | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this missing a call to
RequireInfraRole
(orIsAuthorized
) ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally that was part of this change, but after building out the rest of the SCIM functionality I realized that the SCIM role wasn't needed. This endpoint can only be called with an access key issued for a provider, and it can only modify the provider that the access key was issued for. In this way is acts similarly to our other
isSelf
endpoints.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, because we query with
AccessKey.IssusedFor
, which will have a providerID in the case of these SCIM access keys, and there should never be an overlap between userIDs and providerIDs, got it!