Files
sdk/api_gateway.go

399 lines
14 KiB
Go

/*
Hanzo Cloud API
The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
API version: v1
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package hanzoai
import (
"bytes"
"context"
"io"
"net/http"
"net/url"
)
// GatewayAPIService GatewayAPI service
type GatewayAPIService service
type GatewayAPIGatewayTrafficRequest struct {
ctx context.Context
ApiService *GatewayAPIService
}
func (r GatewayAPIGatewayTrafficRequest) Execute() (*GatewayTrafficView, *http.Response, error) {
return r.ApiService.GatewayTrafficExecute(r)
}
/*
GatewayTraffic Report who is calling this org's API right now
Reports who is calling this organization's API right now: the request
count for the last minute split by AGENCY LANE — agent, human, bot, unknown —
and the busiest callers behind it, each with its request count, its
authentication-failure count, how many distinct paths it touched, and any
verdict currently held against it.
The lane split is the answer to the question a generic bot filter cannot
answer: which of this traffic is the customer's own automation and which is
somebody working through a list. It is computed from credentials we issued, not
from the client's self-description, so a scraper cannot move itself into the
agent lane by editing a header.
A validated caller appears as a FINGERPRINT — a one-way, per-process digest. It
is stable enough to recognise the same caller across a minute and cannot be
turned back into a key, so this report is safe to read, screenshot and paste.
It also reports what the sensor's own ceilings are doing (strain, tracked,
ceiling, refused) and how many screens the scorer did not answer (unscored), so
a control that has stopped measuring or a judge that has stopped answering is a
number here rather than a quiet day.
Scoped to the caller's own validated organization. A SuperAdmin may inspect a
specific tenant with ?org=<slug>, or the lane that has no tenant — every caller
the identity boundary could not validate — with an empty ?org=.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return GatewayAPIGatewayTrafficRequest
*/
func (a *GatewayAPIService) GatewayTraffic(ctx context.Context) GatewayAPIGatewayTrafficRequest {
return GatewayAPIGatewayTrafficRequest{
ApiService: a,
ctx: ctx,
}
}
// Execute executes the request
//
// @return GatewayTrafficView
func (a *GatewayAPIService) GatewayTrafficExecute(r GatewayAPIGatewayTrafficRequest) (*GatewayTrafficView, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *GatewayTrafficView
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "GatewayAPIService.GatewayTraffic")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/gateway/traffic"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
var v ProblemDetails
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type GatewayAPIGetGatewayConfigRequest struct {
ctx context.Context
ApiService *GatewayAPIService
}
func (r GatewayAPIGetGatewayConfigRequest) Execute() (*GatewayPolicy, *http.Response, error) {
return r.ApiService.GetGatewayConfigExecute(r)
}
/*
GetGatewayConfig Returns the EFFECTIVE edge policy the caller is subject to: the platform CORS allowlist and pre-auth per-IP flood cap in force, plus the caller's own authenticated rate ceiling, edge-cache TTLs and accepted-method allowlist.
Returns the EFFECTIVE edge policy the caller is subject to: the platform CORS
allowlist and pre-auth per-IP flood cap in force, plus the caller's own authenticated
rate ceiling, edge-cache TTLs and accepted-method allowlist. A SuperAdmin may inspect
a specific tenant's effective policy with ?org=<slug>.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return GatewayAPIGetGatewayConfigRequest
*/
func (a *GatewayAPIService) GetGatewayConfig(ctx context.Context) GatewayAPIGetGatewayConfigRequest {
return GatewayAPIGetGatewayConfigRequest{
ApiService: a,
ctx: ctx,
}
}
// Execute executes the request
//
// @return GatewayPolicy
func (a *GatewayAPIService) GetGatewayConfigExecute(r GatewayAPIGetGatewayConfigRequest) (*GatewayPolicy, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodGet
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *GatewayPolicy
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "GatewayAPIService.GetGatewayConfig")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/gateway/config"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
var v ProblemDetails
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}
type GatewayAPIPutGatewayConfigRequest struct {
ctx context.Context
ApiService *GatewayAPIService
gatewayPolicy *GatewayPolicy
}
func (r GatewayAPIPutGatewayConfigRequest) GatewayPolicy(gatewayPolicy GatewayPolicy) GatewayAPIPutGatewayConfigRequest {
r.gatewayPolicy = &gatewayPolicy
return r
}
func (r GatewayAPIPutGatewayConfigRequest) Execute() (*GatewayPolicy, *http.Response, error) {
return r.ApiService.PutGatewayConfigExecute(r)
}
/*
PutGatewayConfig Updates one policy scope and returns the policy in force after the write.
Updates one policy scope and returns the policy in force after the write.
Writing requires a signed-in admin of the organization, or a SuperAdmin; a
member and every API key are refused 403, and so is a browser session's change
that its own page did not send.
A body carrying any PLATFORM field (cors_origins, per_ip_rpm, window_sec) is a
platform write and requires SuperAdmin; otherwise it is a per-org write (org_rpm,
cache_ttl_sec, cache_paths, methods) scoped to the caller's own org — or, for a
SuperAdmin, the tenant named by ?org=<slug>. A body that sets nothing is a 400.
The abuse gate's mode and an organization's rate cap (org_cap) are OPERATOR
fields: setting either requires SuperAdmin, whichever organization it lands on,
and an org_cap change is recorded on the audit trail with the cap before and
after (gateway.org_cap), or refused (503) when the trail cannot take it. The
platform's org_rpm is every organization's default cap, so moving it is recorded
the same way (gateway.default_cap). An
organization's own org_rpm may lower its ceiling but not raise it past its cap. updated_at and updated_by are server-stamped; a client-supplied value is
ignored.
@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
@return GatewayAPIPutGatewayConfigRequest
*/
func (a *GatewayAPIService) PutGatewayConfig(ctx context.Context) GatewayAPIPutGatewayConfigRequest {
return GatewayAPIPutGatewayConfigRequest{
ApiService: a,
ctx: ctx,
}
}
// Execute executes the request
//
// @return GatewayPolicy
func (a *GatewayAPIService) PutGatewayConfigExecute(r GatewayAPIPutGatewayConfigRequest) (*GatewayPolicy, *http.Response, error) {
var (
localVarHTTPMethod = http.MethodPut
localVarPostBody interface{}
formFiles []formFile
localVarReturnValue *GatewayPolicy
)
localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "GatewayAPIService.PutGatewayConfig")
if err != nil {
return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()}
}
localVarPath := localBasePath + "/v1/gateway/config"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := url.Values{}
localVarFormParams := url.Values{}
if r.gatewayPolicy == nil {
return localVarReturnValue, nil, reportError("gatewayPolicy is required and must be specified")
}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{"application/json"}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json", "application/problem+json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
// body params
localVarPostBody = r.gatewayPolicy
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := io.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
var v ProblemDetails
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v)
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := &GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}