Documentation
¶
Overview ¶
Package castle provides a client for the Castle API.
Index ¶
- Variables
- func VerifyWebhookSignature(body []byte, signature, apiSecret string) error
- type APIError
- type Client
- func (c *Client) ArchiveListItem(ctx context.Context, listId string, id string) (*api.ArchiveListItemResponse, error)
- func (c *Client) CountListItems(ctx context.Context, listId string, body api.CountListItemsJSONRequestBody) (*api.CountListItemsResponse, error)
- func (c *Client) CountListItemsWithBody(ctx context.Context, listId string, contentType string, body io.Reader) (*api.CountListItemsResponse, error)
- func (c *Client) CreateList(ctx context.Context, body api.CreateListJSONRequestBody) (*api.CreateListResponse, error)
- func (c *Client) CreateListItem(ctx context.Context, listId string, body api.CreateListItemJSONRequestBody) (*api.CreateListItemResponse, error)
- func (c *Client) CreateListItemWithBody(ctx context.Context, listId string, contentType string, body io.Reader) (*api.CreateListItemResponse, error)
- func (c *Client) CreateListWithBody(ctx context.Context, contentType string, body io.Reader) (*api.CreateListResponse, error)
- func (c *Client) CreateOrUpdateBatchListItems(ctx context.Context, listId string, ...) (*api.CreateOrUpdateBatchListItemsResponse, error)
- func (c *Client) CreateOrUpdateBatchListItemsWithBody(ctx context.Context, listId string, contentType string, body io.Reader) (*api.CreateOrUpdateBatchListItemsResponse, error)
- func (c *Client) DeleteList(ctx context.Context, id string) (*api.DeleteListResponse, error)
- func (c *Client) DeleteUserPrivacy(ctx context.Context, body api.DeleteUserPrivacyJSONRequestBody) (*api.DeleteUserPrivacyResponse, error)
- func (c *Client) DeleteUserPrivacyDeprecated(ctx context.Context, id string) (*api.DeleteUserPrivacyDeprecatedResponse, error)
- func (c *Client) DeleteUserPrivacyWithBody(ctx context.Context, contentType string, body io.Reader) (*api.DeleteUserPrivacyResponse, error)
- func (c *Client) DownloadIpDatasetExport(ctx context.Context, dataset string, window string, format string) (*api.DownloadIpDatasetExportResponse, error)
- func (c *Client) Filter(ctx context.Context, body api.FilterJSONRequestBody) (*api.FilterResponse, error)
- func (c *Client) FilterWithBody(ctx context.Context, contentType string, body io.Reader) (*api.FilterResponse, error)
- func (c *Client) GetEventSchema(ctx context.Context) (*api.GetEventSchemaResponse, error)
- func (c *Client) GetLatestIpDatasetExportMetadata(ctx context.Context, dataset string, window string, format string) (*api.GetLatestIpDatasetExportMetadataResponse, error)
- func (c *Client) GetList(ctx context.Context, id string, params *api.GetListParams) (*api.GetListResponse, error)
- func (c *Client) GetListItem(ctx context.Context, listId string, id string) (*api.GetListItemResponse, error)
- func (c *Client) GetLists(ctx context.Context) (*api.GetListsResponse, error)
- func (c *Client) GetUserPrivacy(ctx context.Context, body api.GetUserPrivacyJSONRequestBody) (*api.GetUserPrivacyResponse, error)
- func (c *Client) GetUserPrivacyDeprecated(ctx context.Context, id string) (*api.GetUserPrivacyDeprecatedResponse, error)
- func (c *Client) GetUserPrivacyWithBody(ctx context.Context, contentType string, body io.Reader) (*api.GetUserPrivacyResponse, error)
- func (c *Client) GroupEvents(ctx context.Context, body api.GroupEventsJSONRequestBody) (*api.GroupEventsResponse, error)
- func (c *Client) GroupEventsWithBody(ctx context.Context, contentType string, body io.Reader) (*api.GroupEventsResponse, error)
- func (c *Client) IpsLookupBatch(ctx context.Context, body api.IpsLookupBatchJSONRequestBody) (*api.IpsLookupBatchResponse, error)
- func (c *Client) IpsLookupBatchWithBody(ctx context.Context, contentType string, body io.Reader) (*api.IpsLookupBatchResponse, error)
- func (c *Client) IpsLookupSingle(ctx context.Context, value string) (*api.IpsLookupSingleResponse, error)
- func (c *Client) QueryEvents(ctx context.Context, body api.QueryEventsJSONRequestBody) (*api.QueryEventsResponse, error)
- func (c *Client) QueryEventsWithBody(ctx context.Context, contentType string, body io.Reader) (*api.QueryEventsResponse, error)
- func (c *Client) QueryListItems(ctx context.Context, listId string, body api.QueryListItemsJSONRequestBody) (*api.QueryListItemsResponse, error)
- func (c *Client) QueryListItemsWithBody(ctx context.Context, listId string, contentType string, body io.Reader) (*api.QueryListItemsResponse, error)
- func (c *Client) QueryLists(ctx context.Context, body api.QueryListsJSONRequestBody) (*api.QueryListsResponse, error)
- func (c *Client) QueryListsWithBody(ctx context.Context, contentType string, body io.Reader) (*api.QueryListsResponse, error)
- func (c *Client) Risk(ctx context.Context, body api.RiskJSONRequestBody) (*api.RiskResponse, error)
- func (c *Client) RiskWithBody(ctx context.Context, contentType string, body io.Reader) (*api.RiskResponse, error)
- func (c *Client) UnarchiveListItem(ctx context.Context, listId string, id string, ...) (*api.UnarchiveListItemResponse, error)
- func (c *Client) UnarchiveListItemWithBody(ctx context.Context, listId string, id string, contentType string, ...) (*api.UnarchiveListItemResponse, error)
- func (c *Client) UpdateList(ctx context.Context, id string, body api.UpdateListJSONRequestBody) (*api.UpdateListResponse, error)
- func (c *Client) UpdateListItem(ctx context.Context, listId string, id string, ...) (*api.UpdateListItemResponse, error)
- func (c *Client) UpdateListItemWithBody(ctx context.Context, listId string, id string, contentType string, ...) (*api.UpdateListItemResponse, error)
- func (c *Client) UpdateListWithBody(ctx context.Context, id string, contentType string, body io.Reader) (*api.UpdateListResponse, error)
- type Config
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrWebhookVerification = errors.New("castle: webhook signature verification failed")
ErrWebhookVerification indicates a missing or invalid webhook signature or secret.
Functions ¶
func VerifyWebhookSignature ¶
VerifyWebhookSignature verifies the X-Castle-Signature header against the exact request body bytes using the API secret selected for webhook signing in Castle. Call it before parsing or processing the body. It returns ErrWebhookVerification for an empty secret, missing or malformed signature, or signature mismatch.
Types ¶
type APIError ¶
type APIError struct{ StatusCode int }
APIError reports a non-success HTTP status without exposing response data.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls Castle's generated API operations. It is safe for concurrent use.
func NewClient ¶
NewClient constructs a client using apiSecret as the Basic authentication password.
func (*Client) ArchiveListItem ¶
func (c *Client) ArchiveListItem(ctx context.Context, listId string, id string) (*api.ArchiveListItemResponse, error)
ArchiveListItem calls DELETE /lists/{list_id}/items/{id}/archive with the shared client policy.
func (*Client) CountListItems ¶
func (c *Client) CountListItems(ctx context.Context, listId string, body api.CountListItemsJSONRequestBody) (*api.CountListItemsResponse, error)
CountListItems calls POST /lists/{list_id}/items/count with the shared client policy.
func (*Client) CountListItemsWithBody ¶
func (c *Client) CountListItemsWithBody(ctx context.Context, listId string, contentType string, body io.Reader) (*api.CountListItemsResponse, error)
CountListItemsWithBody calls POST /lists/{list_id}/items/count with the shared client policy.
func (*Client) CreateList ¶
func (c *Client) CreateList(ctx context.Context, body api.CreateListJSONRequestBody) (*api.CreateListResponse, error)
CreateList calls POST /lists with the shared client policy.
func (*Client) CreateListItem ¶
func (c *Client) CreateListItem(ctx context.Context, listId string, body api.CreateListItemJSONRequestBody) (*api.CreateListItemResponse, error)
CreateListItem calls POST /lists/{list_id}/items with the shared client policy.
func (*Client) CreateListItemWithBody ¶
func (c *Client) CreateListItemWithBody(ctx context.Context, listId string, contentType string, body io.Reader) (*api.CreateListItemResponse, error)
CreateListItemWithBody calls POST /lists/{list_id}/items with the shared client policy.
func (*Client) CreateListWithBody ¶
func (c *Client) CreateListWithBody(ctx context.Context, contentType string, body io.Reader) (*api.CreateListResponse, error)
CreateListWithBody calls POST /lists with the shared client policy.
func (*Client) CreateOrUpdateBatchListItems ¶
func (c *Client) CreateOrUpdateBatchListItems(ctx context.Context, listId string, body api.CreateOrUpdateBatchListItemsJSONRequestBody) (*api.CreateOrUpdateBatchListItemsResponse, error)
CreateOrUpdateBatchListItems calls POST /lists/{list_id}/items/batch with the shared client policy.
func (*Client) CreateOrUpdateBatchListItemsWithBody ¶
func (c *Client) CreateOrUpdateBatchListItemsWithBody(ctx context.Context, listId string, contentType string, body io.Reader) (*api.CreateOrUpdateBatchListItemsResponse, error)
CreateOrUpdateBatchListItemsWithBody calls POST /lists/{list_id}/items/batch with the shared client policy.
func (*Client) DeleteList ¶
DeleteList calls DELETE /lists/{id} with the shared client policy.
func (*Client) DeleteUserPrivacy ¶
func (c *Client) DeleteUserPrivacy(ctx context.Context, body api.DeleteUserPrivacyJSONRequestBody) (*api.DeleteUserPrivacyResponse, error)
DeleteUserPrivacy calls DELETE /privacy/users with the shared client policy.
func (*Client) DeleteUserPrivacyDeprecated ¶
func (c *Client) DeleteUserPrivacyDeprecated(ctx context.Context, id string) (*api.DeleteUserPrivacyDeprecatedResponse, error)
DeleteUserPrivacyDeprecated calls DELETE /privacy/users/{id} with the shared client policy. Deprecated: This operation is deprecated in Castle's API specification.
func (*Client) DeleteUserPrivacyWithBody ¶
func (c *Client) DeleteUserPrivacyWithBody(ctx context.Context, contentType string, body io.Reader) (*api.DeleteUserPrivacyResponse, error)
DeleteUserPrivacyWithBody calls DELETE /privacy/users with the shared client policy.
func (*Client) DownloadIpDatasetExport ¶
func (c *Client) DownloadIpDatasetExport(ctx context.Context, dataset string, window string, format string) (*api.DownloadIpDatasetExportResponse, error)
DownloadIpDatasetExport calls GET /ips/downloads/{dataset}/{window}.{format}.gz with the shared client policy.
func (*Client) Filter ¶
func (c *Client) Filter(ctx context.Context, body api.FilterJSONRequestBody) (*api.FilterResponse, error)
Filter calls POST /filter with the shared client policy.
func (*Client) FilterWithBody ¶
func (c *Client) FilterWithBody(ctx context.Context, contentType string, body io.Reader) (*api.FilterResponse, error)
FilterWithBody calls POST /filter with the shared client policy.
func (*Client) GetEventSchema ¶
GetEventSchema calls GET /events/schema with the shared client policy.
func (*Client) GetLatestIpDatasetExportMetadata ¶
func (c *Client) GetLatestIpDatasetExportMetadata(ctx context.Context, dataset string, window string, format string) (*api.GetLatestIpDatasetExportMetadataResponse, error)
GetLatestIpDatasetExportMetadata calls HEAD /ips/downloads/{dataset}/{window}.{format}.gz with the shared client policy.
func (*Client) GetList ¶
func (c *Client) GetList(ctx context.Context, id string, params *api.GetListParams) (*api.GetListResponse, error)
GetList calls GET /lists/{id} with the shared client policy.
func (*Client) GetListItem ¶
func (c *Client) GetListItem(ctx context.Context, listId string, id string) (*api.GetListItemResponse, error)
GetListItem calls GET /lists/{list_id}/items/{id} with the shared client policy.
func (*Client) GetUserPrivacy ¶
func (c *Client) GetUserPrivacy(ctx context.Context, body api.GetUserPrivacyJSONRequestBody) (*api.GetUserPrivacyResponse, error)
GetUserPrivacy calls POST /privacy/users with the shared client policy.
func (*Client) GetUserPrivacyDeprecated ¶
func (c *Client) GetUserPrivacyDeprecated(ctx context.Context, id string) (*api.GetUserPrivacyDeprecatedResponse, error)
GetUserPrivacyDeprecated calls POST /privacy/users/{id} with the shared client policy. Deprecated: This operation is deprecated in Castle's API specification.
func (*Client) GetUserPrivacyWithBody ¶
func (c *Client) GetUserPrivacyWithBody(ctx context.Context, contentType string, body io.Reader) (*api.GetUserPrivacyResponse, error)
GetUserPrivacyWithBody calls POST /privacy/users with the shared client policy.
func (*Client) GroupEvents ¶
func (c *Client) GroupEvents(ctx context.Context, body api.GroupEventsJSONRequestBody) (*api.GroupEventsResponse, error)
GroupEvents calls POST /events/group with the shared client policy.
func (*Client) GroupEventsWithBody ¶
func (c *Client) GroupEventsWithBody(ctx context.Context, contentType string, body io.Reader) (*api.GroupEventsResponse, error)
GroupEventsWithBody calls POST /events/group with the shared client policy.
func (*Client) IpsLookupBatch ¶
func (c *Client) IpsLookupBatch(ctx context.Context, body api.IpsLookupBatchJSONRequestBody) (*api.IpsLookupBatchResponse, error)
IpsLookupBatch calls POST /ips/query with the shared client policy.
func (*Client) IpsLookupBatchWithBody ¶
func (c *Client) IpsLookupBatchWithBody(ctx context.Context, contentType string, body io.Reader) (*api.IpsLookupBatchResponse, error)
IpsLookupBatchWithBody calls POST /ips/query with the shared client policy.
func (*Client) IpsLookupSingle ¶
func (c *Client) IpsLookupSingle(ctx context.Context, value string) (*api.IpsLookupSingleResponse, error)
IpsLookupSingle calls GET /ips/{value} with the shared client policy.
func (*Client) QueryEvents ¶
func (c *Client) QueryEvents(ctx context.Context, body api.QueryEventsJSONRequestBody) (*api.QueryEventsResponse, error)
QueryEvents calls POST /events/query with the shared client policy.
func (*Client) QueryEventsWithBody ¶
func (c *Client) QueryEventsWithBody(ctx context.Context, contentType string, body io.Reader) (*api.QueryEventsResponse, error)
QueryEventsWithBody calls POST /events/query with the shared client policy.
func (*Client) QueryListItems ¶
func (c *Client) QueryListItems(ctx context.Context, listId string, body api.QueryListItemsJSONRequestBody) (*api.QueryListItemsResponse, error)
QueryListItems calls POST /lists/{list_id}/items/query with the shared client policy.
func (*Client) QueryListItemsWithBody ¶
func (c *Client) QueryListItemsWithBody(ctx context.Context, listId string, contentType string, body io.Reader) (*api.QueryListItemsResponse, error)
QueryListItemsWithBody calls POST /lists/{list_id}/items/query with the shared client policy.
func (*Client) QueryLists ¶
func (c *Client) QueryLists(ctx context.Context, body api.QueryListsJSONRequestBody) (*api.QueryListsResponse, error)
QueryLists calls POST /lists/query with the shared client policy.
func (*Client) QueryListsWithBody ¶
func (c *Client) QueryListsWithBody(ctx context.Context, contentType string, body io.Reader) (*api.QueryListsResponse, error)
QueryListsWithBody calls POST /lists/query with the shared client policy.
func (*Client) Risk ¶
func (c *Client) Risk(ctx context.Context, body api.RiskJSONRequestBody) (*api.RiskResponse, error)
Risk calls POST /risk with the shared client policy.
Example ¶
package main
import (
"context"
"fmt"
"io"
"net/http"
"net/http/httptest"
castle "github.com/fchimpan/castle-go"
"github.com/fchimpan/castle-go/api"
)
func main() {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
io.WriteString(w, `{"type":"$login","policy":{"action":"challenge","name":null,"id":null,"revision_id":null},"signals":{},"device":{"fingerprint":null}}`)
}))
defer server.Close()
client, err := castle.NewClient("synthetic-secret", castle.Config{
BaseURL: server.URL,
})
if err != nil {
panic(err)
}
var name, value api.Context_Headers_Item
if err := name.FromContextHeaders0("User-Agent"); err != nil {
panic(err)
}
if err := value.FromContextHeaders0("ExampleBrowser/1"); err != nil {
panic(err)
}
var request api.Risk
if err := request.FromLoginRiskRequest(api.LoginRiskRequest{
Status: api.LoginRiskRequestStatusSucceeded,
RequestToken: new("synthetic-request-token"),
Context: &api.Context{
Ip: "192.0.2.1",
Headers: [][]api.Context_Headers_Item{{name, value}},
},
User: api.UserForMonitorAndRisk{
Id: "user-123",
},
}); err != nil {
panic(err)
}
result, err := client.Risk(context.Background(), request)
if err != nil {
panic(err)
}
login, err := result.JSON201.AsLoginResponse()
if err != nil {
panic(err)
}
action, err := login.Policy.Action.Get()
if err != nil {
panic(err)
}
fmt.Println(action)
fmt.Println(login.Scores == nil)
}
Output: challenge true
func (*Client) RiskWithBody ¶
func (c *Client) RiskWithBody(ctx context.Context, contentType string, body io.Reader) (*api.RiskResponse, error)
RiskWithBody calls POST /risk with the shared client policy.
func (*Client) UnarchiveListItem ¶
func (c *Client) UnarchiveListItem(ctx context.Context, listId string, id string, body api.UnarchiveListItemJSONRequestBody) (*api.UnarchiveListItemResponse, error)
UnarchiveListItem calls PUT /lists/{list_id}/items/{id}/unarchive with the shared client policy.
func (*Client) UnarchiveListItemWithBody ¶
func (c *Client) UnarchiveListItemWithBody(ctx context.Context, listId string, id string, contentType string, body io.Reader) (*api.UnarchiveListItemResponse, error)
UnarchiveListItemWithBody calls PUT /lists/{list_id}/items/{id}/unarchive with the shared client policy.
func (*Client) UpdateList ¶
func (c *Client) UpdateList(ctx context.Context, id string, body api.UpdateListJSONRequestBody) (*api.UpdateListResponse, error)
UpdateList calls PUT /lists/{id} with the shared client policy.
func (*Client) UpdateListItem ¶
func (c *Client) UpdateListItem(ctx context.Context, listId string, id string, body api.UpdateListItemJSONRequestBody) (*api.UpdateListItemResponse, error)
UpdateListItem calls PUT /lists/{list_id}/items/{id} with the shared client policy.
type Config ¶
type Config struct {
// BaseURL includes the API version path. Empty uses https://api.castle.io/v1.
BaseURL string
// HTTPClient is copied before use. Nil uses a client without a timeout.
HTTPClient *http.Client
// MaxResponseBytes bounds response bodies. Zero uses 4 MiB.
MaxResponseBytes int64
}
Config configures the client. Its zero value uses Castle's production API.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package api provides primitives to interact with the openapi HTTP API.
|
Package api provides primitives to interact with the openapi HTTP API. |
|
internal
|
|
|
cmd/generateclient
command
Command generateclient wraps generated endpoint calls in the shared SDK policy.
|
Command generateclient wraps generated endpoint calls in the shared SDK policy. |
|
cmd/prepareapi
command
Command prepareapi applies documented generation-only adaptations to the snapshot.
|
Command prepareapi applies documented generation-only adaptations to the snapshot. |