Documentation
¶
Overview ¶
Copyright 2025 SGNL.ai, Inc.
Copyright 2025 SGNL.ai, Inc.
Copyright 2025 SGNL.ai, Inc.
Copyright 2025 SGNL.ai, Inc.
Copyright 2025 SGNL.ai, Inc.
Copyright 2025 SGNL.ai, Inc.
Index ¶
- Constants
- func NewAdapter(client Client) framework.Adapter[Config]
- func ParseResponse(rows *sql.Rows, request *Request) ([]map[string]any, *framework.Error)
- 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
- func (d *Datasource) GetPage(ctx context.Context, request *Request) (*Response, *framework.Error)
- func (d *Datasource) ProxyRequest(ctx context.Context, request *Request, ci *connector.ConnectorInfo) (*Response, *framework.Error)
- func (d *Datasource) Request(_ context.Context, request *Request) (*Response, *framework.Error)
- type MockSQLClient
- type Request
- type Response
- type SQLClient
- type SQLColumnTypes
- type SQLRow
- type SQLRows
Constants ¶
const (
TestDatasourceForConnectFailure = "test.connect.failure"
)
Variables ¶
This section is empty.
Functions ¶
func NewAdapter ¶
NewAdapter instantiates a new Adapter.
Types ¶
type Adapter ¶
type Adapter struct {
MySQLClient 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 Config ¶
type Config struct {
*config.CommonConfig
// MySQL database to connect to.
Database string `json:"database,omitempty"`
}
Config is the configuration passed in each GetPage calls to the adapter. Adapter configuration example: nolint: godot
{
"requestTimeoutSeconds": 10,
"localTimeZoneOffset": 43200,
"database": "sgnl"
}
type Datasource ¶
type Datasource struct {
Client SQLClient
}
func (*Datasource) ProxyRequest ¶ added in v1.39.0
func (d *Datasource) ProxyRequest(ctx context.Context, request *Request, ci *connector.ConnectorInfo, ) (*Response, *framework.Error)
ProxyRequest sends serialized SQL query request to the on-premises connector.
type MockSQLClient ¶
func NewMockSQLClient ¶
func NewMockSQLClient() *MockSQLClient
func (*MockSQLClient) Connect ¶
func (c *MockSQLClient) Connect(datasourceName string) error
func (*MockSQLClient) Proxy ¶ added in v1.39.0
func (c *MockSQLClient) Proxy(_ context.Context, _ *grpc_proxy_v1.ProxyRequestMessage, ) (*grpc_proxy_v1.Response, error)
type Request ¶
type Request struct {
// BaseURL is the Base URL of the datasource to query.
BaseURL string `json:"baseURL"`
// Username is the user name used to authenticate with the MySQL instance.
Username string `json:"username"`
// Password is the password used to authenticate with the MySQL instance.
Password string `json:"password"`
// PageSize is the maximum number of objects to return from the entity.
PageSize int64 `json:"pageSize,omitempty"`
// EntityConfig contains the entity configuration for the current request.
EntityConfig framework.EntityConfig
// 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 *int64 `json:"cursor,omitempty"`
// MySQL database to connect to.
Database string `json:"database"`
// UniqueAttributeExternalID is used to specify the unique ID that should be used when ordering results from
// the specified table.
UniqueAttributeExternalID string `json:"uniqueAttributeExternalID"`
}
Request is a request to a MySQL database.
func (*Request) DatasourceName ¶ added in v1.39.0
DatasourceName to connect to.
func (*Request) SimpleSQLValidation ¶ added in v1.39.0
SimpleSQLValidation performs simple validation on specific fields to prevent SQL Ingestion attacks, since we can't use table names or column names in prepared queries which leaves us vulnerable.
type Response ¶
type Response struct {
// StatusCode is an HTTP status code.
StatusCode int `json:"statusCode"`
// RetryAfterHeader is the Retry-After response HTTP header, if set.
RetryAfterHeader string `json:"retryAfterHeader"`
// Objects is the list of objects returned from the datasource.
// May be empty.
Objects []map[string]any `json:"objects"`
// 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 *int64 `json:"nextCursor,omitempty"`
}
Response is a response returned by the datasource.
type SQLClient ¶
type SQLClient interface {
Proxy(ctx context.Context, req *grpc_proxy_v1.ProxyRequestMessage) (*grpc_proxy_v1.Response, error)
Connect(dataSourceName string) error
Query(query string, args ...any) (*sql.Rows, error)
}
func NewDefaultSQLClient ¶
func NewDefaultSQLClient() SQLClient