ldap

package
v1.38.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Overview

Copyright 2025 SGNL.ai, Inc.

Copyright 2025 SGNL.ai, Inc.

Index

Constants

View Source
const (
	ErrorMsgAttributeTypeDoesNotMatchFmt = "Attribute '%s' was returned from the " +
		"configured datasource as type %s; wanted type %s"
)

Variables

This section is empty.

Functions

func BytesToOctetString

func BytesToOctetString(data []byte) *string

func DefaultEntityConfig

func DefaultEntityConfig() map[string]*EntityConfig

defaultEntityConfig: if entityConfig is nil, defaulting to values that pull data from ActiveDirectory.

func EntryToObject

func EntryToObject(e *ldap_v3.Entry, attrConfig map[string]*framework.AttributeConfig) (
	map[string]interface{}, *framework.Error)

func NewAdapter

func NewAdapter() framework.Adapter[Config]

NewAdapter instantiates a new Adapter.

func OctetStringToBytes

func OctetStringToBytes(octalString string) ([]byte, error)

func ResultCodeToHTTPStatusCode

func ResultCodeToHTTPStatusCode(ldapError *ldap_v3.Error) int

func SetFilters

func SetFilters(request *Request) (string, *framework.Error)

SetFilters configures the LDAP search filters based on the inputs received in entityConfig.

func StringAttrValuesToRequestedType

func StringAttrValuesToRequestedType(attr *ldap_v3.EntryAttribute, isList bool,
	attrType framework.AttributeType) (any, *framework.Error)

Types

type Adapter

type Adapter struct {
	ADClient 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(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() Client

NewClient returns a Client to query the datasource.

type Config

type Config struct {
	// Common configuration
	*config.CommonConfig

	BaseDN string `json:"baseDN"`

	// CertificateChain is a base64 encoded Certificates
	CertificateChain string `json:"certificateChain,omitempty"`

	// EntityConfigMap is an map containing the config required for each entity associated with this
	// datasource. The key is the entity's external_name and value is EntityConfig.
	EntityConfigMap map[string]*EntityConfig `json:"entityConfig"`
}

func (*Config) Validate

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

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

type ConnectionParams

type ConnectionParams struct {
	// Host is the Hostname of the datasource to query.
	Host string

	// BaseDN is the Base DN of the datasource to query.
	BaseDN string

	// BindDN is the Bind DN of the datasource to query.
	BindDN string

	// BindPassword is the password of the datasource to query.
	BindPassword string

	// IsLDAPS flag to check if connection is secured
	IsLDAPS bool

	// CertificateChain contains certificate chain to use for ldaps connection
	CertificateChain string
}

type Datasource

type Datasource struct{}

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 EntityConfig

type EntityConfig struct {
	Query                     string  `json:"query"`
	CollectionAttribute       *string `json:"collectionAttribute"`
	MemberUniqueIDAttribute   *string `json:"memberUniqueIdAttribute,omitempty"`
	MemberOfUniqueIDAttribute *string `json:"memberOfUniqueIdAttribute,omitempty"`
	MemberOf                  *string `json:"memberOf,omitempty"`
}

EntityConfig holds attributes which are used to create LDAP search filter.

type PageInfo

type PageInfo struct {
	// Collection is a map of the attributes of the collection entity.
	Collection map[string]any `json:"collection"`

	// NextPageCursor is the cursor to the next page of results.
	NextPageCursor *string `json:"nextPageCursor"`
}

func DecodePageInfo

func DecodePageInfo(cursor *string) (*PageInfo, *framework.Error)

func ParseResponse

func ParseResponse(searchResult *ldap_v3.SearchResult, attributes map[string]*framework.AttributeConfig) (
	objects []map[string]any, pageInfo *PageInfo, err *framework.Error)

type Request

type Request struct {
	// ConnectionParams contains LDAP specific params
	ConnectionParams

	// BaseURL is the Base URL of the datasource to query.
	BaseURL 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]

	// UniqueIDAttribute is a attribute which can be used to uniquely identify the Entity.
	// This is specific to ldap server implementation
	UniqueIDAttribute string

	// EntityConfigMap is an map containing the config required for each entity associated with this
	// datasource. The key is the entity's external_name and value is EntityConfig.
	EntityConfigMap map[string]*EntityConfig

	// Attributes contains the list of attributes to request along with the current request.
	Attributes []*framework.AttributeConfig

	// 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
}

Request is a request to the datasource.

type Response

type Response struct {
	// TODO: Update the comment once we support LDAP status with adapter-framework
	// 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.
	// nil if this is the last page in this full sync.
	NextCursor *pagination.CompositeCursor[string]
}

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