Documentation
¶
Index ¶
- Constants
- func ConstructQuery(request *Request) (string, []any, error)
- func NewAdapter(client Client) framework.Adapter[Config]
- func ParseResponse(rows *sql.Rows, request *Request) ([]map[string]any, int64, *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(ctx context.Context, request *Request) (*Response, *framework.Error)
- type MockSQLClient
- func (c *MockSQLClient) Connect(datasourceName string) (*sql.DB, error)
- func (c *MockSQLClient) IsProxied() bool
- func (c *MockSQLClient) Proxy(_ context.Context, _ *grpc_proxy_v1.ProxyRequestMessage) (*grpc_proxy_v1.Response, error)
- func (c *MockSQLClient) Query(db *sql.DB, query string, args ...any) (*sql.Rows, error)
- type Request
- type Response
- type SQLClient
- type SQLColumnTypes
- type SQLRow
- type SQLRows
Constants ¶
const (
TestDatasourceForConnectFailure = "test.connect.failure"
)
const TotalRemainingRowsColumn = "total_remaining_rows"
TotalRemainingRowsColumn is the column name for the COUNT window function result that provides the total count of rows matching the query conditions.
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"`
Filters map[string]condexpr.Condition `json:"filters,omitempty"`
}
Config is the configuration passed in each GetPage calls to the adapter.
Adapter configuration example: nolint: godot
{
"requestTimeoutSeconds": 10,
"localTimeZoneOffset": 43200,
"database": "sgnl",
"filters": {
"users": {
"or": [
{
"and": [
{
"field": "age",
"op": ">",
"value": 18
},
{
"field": "country",
"op": "=",
"value": "USA"
}
]
},
{
"field": "verified",
"op": "=",
"value": true
}
]
},
"groups": {
"field": "country",
"op": "IN",
"value": ["active", "inactive"]
}
}
}
type Datasource ¶
type Datasource struct {
Client SQLClient
}
func (*Datasource) ProxyRequest ¶
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) (*sql.DB, error)
func (*MockSQLClient) IsProxied ¶
func (c *MockSQLClient) IsProxied() bool
func (*MockSQLClient) Proxy ¶
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
// A filter to apply to the MySQL request when pulling data for the current entity.
Filter *condexpr.Condition
// 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 *string `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 ¶
DatasourceName to connect to.
func (*Request) SimpleSQLValidation ¶
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 *string `json:"nextCursor,omitempty"`
}
Response is a response returned by the datasource.
type SQLClient ¶
type SQLClient interface {
IsProxied() bool
Proxy(ctx context.Context, req *grpc_proxy_v1.ProxyRequestMessage) (*grpc_proxy_v1.Response, error)
Connect(dataSourceName string) (*sql.DB, error)
Query(db *sql.DB, query string, args ...any) (*sql.Rows, error)
}
func NewDefaultSQLClient ¶
func NewDefaultSQLClient(client grpc_proxy_v1.ProxyServiceClient) SQLClient
NewDefaultSQLClient creates a new SQLClient instance. It is used to connect to a SQL database and execute queries. The client is not proxied by default. If you want to use a proxied client, you need to provide a grpc_proxy_v1.ProxyServiceClient instance.