Documentation
¶
Index ¶
- Constants
- Variables
- func AddGroupParams(params *url.Values, request *Request)
- func AddMemberParams(params *url.Values, request *Request)
- func AddUserParams(params *url.Values, request *Request)
- func ConstructEndpoint(request *Request) (string, *framework.Error)
- func NewAdapter(client Client) framework.Adapter[Config]
- func ParseNextCursor(nextPageToken *string, oldCursor *pagination.CompositeCursor[string]) (nextCursor *pagination.CompositeCursor[string])
- func ParseResponse(body []byte, request *Request) (objects []map[string]any, nextCursor *pagination.CompositeCursor[string], ...)
- type Adapter
- func (a *Adapter) GetPage(ctx context.Context, request *framework.Request[Config]) framework.Response
- func (a *Adapter) RequestPageFromDatasource(ctx context.Context, request *framework.Request[Config]) framework.Response
- func (a *Adapter) ValidateGetPageRequest(ctx context.Context, request *framework.Request[Config]) *framework.Error
- type Client
- type Config
- type Datasource
- type DatasourceResponse
- type DatasourceResponseTemplate
- type Entity
- type ErrorDetails
- type ErrorInfo
- type Filters
- type GroupFilters
- type MemberFilters
- type Request
- type Response
- type UserFilters
Constants ¶
const ( User = "User" Group = "Group" Member = "Member" )
const (
OrderByAscending = "ASCENDING"
)
Variables ¶
var ( // ValidEntityExternalIDs is a set of valid external IDs of entities that can be queried. // The map value is the Entity struct which contains the unique ID attribute. ValidEntityExternalIDs = map[string]Entity{ User: { Path: "/admin/directory/%s/users", OrderByAttribute: "EMAIL", MaxPageSize: 500, UniqueIDAttribute: "id", }, Group: { Path: "/admin/directory/%s/groups", OrderByAttribute: "EMAIL", MaxPageSize: 1000, UniqueIDAttribute: "id", }, Member: { Path: "/admin/directory/%s/groups/%s/members", MaxPageSize: 1000, UniqueIDAttribute: "uniqueId", RequiredAttributes: []string{"id", "groupId"}, }, } )
Functions ¶
func AddGroupParams ¶
func AddMemberParams ¶
func AddUserParams ¶
func ConstructEndpoint ¶
ConstructEndpoint constructs and returns the endpoint to query the datasource.
func NewAdapter ¶
NewAdapter instantiates a new Adapter.
func ParseNextCursor ¶
func ParseNextCursor( nextPageToken *string, oldCursor *pagination.CompositeCursor[string], ) (nextCursor *pagination.CompositeCursor[string])
func ParseResponse ¶
func ParseResponse(body []byte, request *Request) ( objects []map[string]any, nextCursor *pagination.CompositeCursor[string], err *framework.Error, )
Types ¶
type Adapter ¶
type Adapter struct {
GoogleWorkspaceClient Client
}
Adapter implements the framework.Adapter interface to query pages of objects from datasources.
func (*Adapter) GetPage ¶
func (a *Adapter) GetPage(ctx context.Context, request *framework.Request[Config]) framework.Response
GetPage is called by SGNL's ingestion service to query a page of objects from a datasource.
type Client ¶
type Client interface {
GetPage(ctx context.Context, request *Request) (*Response, *framework.Error)
}
Client is a client that allows querying the datasource which contains JSON objects.
type Config ¶
type Config struct {
// Common configuration
*config.CommonConfig
// APIVersion is the version of the Google Workspace API to use.
APIVersion string `json:"apiVersion"`
// Note: Only one of Customer or Domain should be set.
// The unique ID for the customer's Google Workspace account. In case of a multi-domain account,
// to fetch all entities for a customer, use this field instead of domain.
Customer *string `json:"customer"`
// Note: Only one of Customer or Domain should be set.
// Use this field to get entities from only one domain.
Domain *string `json:"domain"`
Filters Filters `json:"filters"`
}
Config is the configuration passed in each GetPage calls to the adapter. Google Workspace Adapter configuration example: nolint: godot
{
"requestTimeoutSeconds": 10,
"localTimeZoneOffset": 43200,
"apiVersion": "v1",
"domain": "sgnldemos.com",
"filters": {
"user": {
"showDeleted": true,
"query": ""
},
"group": {
"query": ""
},
"member": {
"includeDerivedMembership": false,
"roles": "MEMBER"
}
}
}
type Datasource ¶
Datasource directly implements a Client interface to allow querying an external datasource.
type DatasourceResponse ¶
type DatasourceResponse struct {
DatasourceResponseTemplate
Users []map[string]interface{} `json:"users"`
Groups []map[string]interface{} `json:"groups"`
Members []map[string]interface{} `json:"members"`
}
type DatasourceResponseTemplate ¶
type DatasourceResponseTemplate struct {
Kind string `json:"kind"`
Etag string `json:"etag"`
NextPageToken *string `json:"nextPageToken"`
Error *ErrorDetails `json:"error"`
}
Google Workspace API response template.
type Entity ¶
type Entity struct {
// Path is the endpoint to query the entity.
Path string
// OrderByAttribute is the attribute to order the results by.
// This is only supported for certain endpoints.
// User: https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/list#orderby
// Group: https://developers.google.com/admin-sdk/directory/reference/rest/v1/groups/list#orderby
OrderByAttribute string
// MaxPageSize is the maximum page size allowed for each entity's endpoint.
MaxPageSize int64
// The RequiredAttributes array specifies attributes necessary to create the uniqueID in the response.
// In Member, the id field is the member object's id. To create the uniqueId, both id and groupId are needed.
// groupId is required for establishing relationships between Groups and Members (members can be groups or users).
RequiredAttributes []string
// UniqueIDAttribute is the attribute that uniquely identifies an entity.
UniqueIDAttribute string
}
Entity contains entity specific information, such as the entity's unique ID attribute and the endpoint path to query that entity.
type ErrorDetails ¶
type Filters ¶
type Filters struct {
UserFilters *UserFilters `json:"user"`
GroupFilters *GroupFilters `json:"group"`
MemberFilters *MemberFilters `json:"member"`
}
type GroupFilters ¶
type GroupFilters struct {
// Query is a string for searching entity fields. For more information:
// Constructing group queries: https://developers.google.com/admin-sdk/directory/v1/guides/search-groups
Query *string `json:"query"`
}
type MemberFilters ¶
type Request ¶
type Request struct {
Filters
// BaseURL is the Base URL of the datasource to query.
BaseURL string
// APIVersion is the version of the Google Workspace Admin API to query.
APIVersion string
// Customer is the Google Workspace customer ID to query for entities in.
Customer *string
// Domain is the domain to query for entities in.
Domain *string
// Bearer token to authenticate with the datasource.
Token string
// PageSize is the maximum number of objects to return from the entity.
PageSize int64
// EntityExternalID is the external ID of the entity.
// The external ID should match the API's resource name.
EntityExternalID string
// Cursor identifies the first object of the page to return, as returned by
// the last request for the entity.
// nil in the request for the first page.
Cursor *pagination.CompositeCursor[string]
// RequestTimeoutSeconds is the timeout duration for requests made to datasources.
// This should be set to the number of seconds to wait before timing out.
RequestTimeoutSeconds int
// Ordered is a boolean that indicates whether the results should be ordered.
Ordered bool
}
Request is a request to the datasource.
type Response ¶
type Response struct {
// StatusCode is an HTTP status code.
StatusCode int
// RetryAfterHeader is the Retry-After response HTTP header, if set.
RetryAfterHeader string
// Objects is the list of items returned by the datasource.
// May be empty.
Objects []map[string]any
// NextCursor is the cursor that identifies the first object of the next page.
// nil if this is the last page in this full sync.
NextCursor *pagination.CompositeCursor[string]
}
Response is a response returned by the datasource.
type UserFilters ¶
type UserFilters struct {
// If set to true, retrieves the list of deleted users. (Default: false)
ShowDeleted bool `json:"showDeleted"`
// Query is a string for searching entity fields. For more information:
// Constructing user queries: https://developers.google.com/admin-sdk/directory/v1/guides/search-users
Query *string `json:"query"`
}