-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add SCIM list users endpoint
- Loading branch information
Showing
13 changed files
with
557 additions
and
9 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
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) | ||
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
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.