adapter

package
v0.0.0-...-5dcfa68 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SCAFFOLDING #11 - pkg/adapter/datasource.go: Update the set of valid entity types this adapter supports.
	Users  string = "users"
	Groups string = "groups"
	Teams  string = "teams"
)
View Source
const (
	// MaxPageSize is the maximum page size allowed in a GetPage request.
	//
	// SCAFFOLDING #7 - pkg/adapter/validation.go: Update this limit to match the limit of the SoR.
	MaxPageSize = 100
)

Variables

View Source
var (

	// ValidEntityExternalIDs is a map 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{
		Users: {
			// contains filtered or unexported fields
		},
		Groups: {
			// contains filtered or unexported fields
		},
		Teams: {
			// contains filtered or unexported fields
		},
	}
)

Functions

func NewAdapter

func NewAdapter(client Client) framework.Adapter[Config]

NewAdapter instantiates a new Adapter.

SCAFFOLDING #21 - pkg/adapter/adapter.go: Add or remove parameters to match field updates above.

func ParseResponse

func ParseResponse(body []byte) (objects []map[string]any, nextCursor string, err *framework.Error)

Types

type Adapter

type Adapter struct {

	// Client provides access to the datasource.
	Client 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.

func (*Adapter) RequestPageFromDatasource

func (a *Adapter) RequestPageFromDatasource(
	ctx context.Context, request *framework.Request[Config],
) framework.Response

RequestPageFromDatasource requests a page of objects from a datasource.

func (*Adapter) ValidateGetPageRequest

func (a *Adapter) ValidateGetPageRequest(ctx context.Context, request *framework.Request[Config]) *framework.Error

ValidateGetPageRequest validates the fields of the GetPage Request.

type Client

type Client interface {
	// GetPage returns a page of JSON objects from the datasource for the
	// requested entity.
	// Returns a (possibly empty) list of JSON objects, each object being
	// unmarshaled into a map by Golang's JSON unmarshaler.
	GetPage(ctx context.Context, request *Request) (*Response, *framework.Error)
}

Client is a client that allows querying the datasource which contains JSON objects.

func NewClient

func NewClient(timeout int) Client

NewClient returns a Client to query the datasource.

type Config

type Config struct {

	// Example config field.
	APIVersion string `json:"apiVersion,omitempty"`
}

Config is the optional configuration passed in each GetPage calls to the adapter.

func (*Config) Validate

func (c *Config) Validate(_ context.Context) error

ValidateConfig validates that a Config received in a GetPage call is valid.

type Datasource

type Datasource struct {
	Client *http.Client
}

Datasource directly implements a Client interface to allow querying an external datasource.

func (*Datasource) GetPage

func (d *Datasource) GetPage(ctx context.Context, request *Request) (*Response, *framework.Error)

type DatasourceResponse

type DatasourceResponse struct {

	// SCAFFOLDING #14 - pkg/adapter/datasource.go: Update `objects` with field name in the SoR response that contains the list of objects.
	Teams  []map[string]any `json:"teams,omitempty"`
	Limit  int              `json:"limit,omitempty"`
	Offset int              `json:"offset,omitempty"`
	More   bool             `json:"more,omitempty"`
}

type Entity

type Entity struct {
	// contains filtered or unexported fields
}

Entity contains entity specific information, such as the entity's unique ID attribute and the endpoint to query that entity.

type Request

type Request struct {
	// BaseURL is the Base URL of the datasource to query.
	BaseURL string

	// Username is the username to use to authenticate with the datasource.
	Username string

	// Password is the password to use to authenticate with the datasource.
	Password string

	// Token is the Authorization token to use to authentication 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.
	// Optional. If not set, return the first page for this entity.
	Cursor string
}

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
	// May be empty.
	Objects []map[string]any

	// NextCursor is the cursor that identifies the first object of the next
	// page.
	// May be empty.
	NextCursor string
}

SCAFFOLDING #6 - pkg/adapter/client.go: Add/Remove/Update any fields to model the response from the SoR API. Response is a response returned by the datasource.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL