tyk

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: MPL-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// Main endpoints used in this wrapper
	PORTAL_DEVS     Endpoint = "/api/portal/developers/email"
	PORTAL_DEVS_SSO Endpoint = "/api/portal/developers/ssokey"
	PORTAL_DEV      Endpoint = "/api/portal/developers"
	SSO_ADMIN       Endpoint = "/admin/sso"
	SSO_REGULAR     Endpoint = "/api/sso"
	OAUTH_AUTHORIZE Endpoint = "tyk/oauth/authorize-client/"
	TOKENS          Endpoint = "/api/apis/{APIID}/keys"
	STANDARD_TOKENS Endpoint = "/api/keys"

	// Main APis used in this wrapper
	GATEWAY    TykAPIName = "gateway"
	DASH       TykAPIName = "dash"
	DASH_SUPER TykAPIName = "dash_super"

	HASH_PlainText HashType = ""
	HASH_BCrypt    HashType = "bcrypt"
)

Variables

This section is empty.

Functions

func ReloadLogger added in v1.1.0

func ReloadLogger()

ReloadLogger in case that user set an external logger

func SetHttpClient added in v1.1.0

func SetHttpClient(c *http.Client)

Types

type AccessDefinition

type AccessDefinition struct {
	APIName     string       `json:"api_name"`
	APIID       string       `json:"api_id"`
	Versions    []string     `json:"versions"`
	AllowedURLs []AccessSpec `bson:"allowed_urls"  json:"allowed_urls"` // mapped string MUST be a valid regex
}

AccessDefinition defines which versions of an API a key has access to

type AccessSpec

type AccessSpec struct {
	URL     string   `json:"url"`
	Methods []string `json:"methods"`
}

AccessSpecs define what URLS a user has access to an what methods are enabled

type Endpoint

type Endpoint string // A type for endpoints

type EndpointConfig

type EndpointConfig struct {
	Endpoint    string
	Port        string
	AdminSecret string
}

EndpointConfig is a Configuration for an API Endpoint of one of the Tyk APIs

type HashType

type HashType string

HashType is an encryption method for basic auth keys

type OAuthMethod

type OAuthMethod string
var Access OAuthMethod = "AccessToken"

type OAuthResponse

type OAuthResponse struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   int64  `json:"expires_in"`
	RedirectTo  string `json:"redirect_to"`
	TokenType   string `json:"token_type"`
}

type PortalDeveloper

type PortalDeveloper struct {
	Id              model.ObjectID                          `bson:"_id,omitempty" json:"id"`
	Email           string                                  `bson:"email" json:"email"`
	Password        string                                  `bson:"password" json:"-"`
	DateCreated     time.Time                               `bson:"date_created" json:"date_created"`
	InActive        bool                                    `bson:"inactive" json:"inactive"`
	OrgId           string                                  `bson:"org_id" json:"org_id"`
	Keys            map[string][]string                     `bson:"keys" json:"keys"`
	Subscriptions   map[string]string                       `bson:"subscriptions" json:"subscriptions"`
	Fields          map[string]string                       `bson:"fields" json:"fields"`
	Nonce           string                                  `bson:"nonce" json:"nonce"`
	SSOKey          string                                  `bson:"sso_key" json:"sso_key"`
	OauthClients    map[string][]PortalDeveloperOAuthClient `bson:"oauth_clients,omitempty" json:"oauth_clients,omitempty"`
	PasswordMaxDays int                                     `bson:"password_max_days" json:"password_max_days"`
	PasswordUpdated time.Time                               `bson:"password_updated" json:"password_updated"`
	PWHistory       []string                                `bson:"PWHistory" json:"PWHistory"`
	LastLoginDate   time.Time                               `bson:"last_login_date" json:"last_login_date"`
}

PortalDeveloper represents a portal developer

type PortalDeveloperOAuthClient added in v1.2.4

type PortalDeveloperOAuthClient struct {
	ClientID          string       `bson:"client_id" json:"client_id"`
	ClientName        string       `bson:"client_name" json:"client_name"`
	ClientSecret      string       `bson:"secret" json:"secret"`
	ClientRedirectURI string       `bson:"redirect_uri" json:"redirect_uri"`
	AppDescription    string       `bson:"app_description" json:"app_description"`
	UseCase           string       `bson:"use_case" json:"use_case"`
	DateCreated       time.Time    `bson:"date_created" json:"date_created"`
	DCRRegistration   Registration `bson:"dcr_registration" json:"dcr_registration"`
}

type Registration added in v1.2.4

type Registration struct {
	ClientURI   string `bson:"client_uri" json:"client_uri"`
	AccessToken string `bson:"access_token" json:"access_token"`
	Provider    string `bson:"provider" json:"provider"`
}

type SessionState

type SessionState struct {
	LastCheck        int64                       `json:"last_check"`
	Allowance        float64                     `json:"allowance"`
	Rate             float64                     `json:"rate"`
	Per              float64                     `json:"per"`
	Expires          int64                       `json:"expires"`
	QuotaMax         int64                       `json:"quota_max"`
	QuotaRenews      int64                       `json:"quota_renews"`
	QuotaRemaining   int64                       `json:"quota_remaining"`
	QuotaRenewalRate int64                       `json:"quota_renewal_rate"`
	AccessRights     map[string]AccessDefinition `json:"access_rights"`
	OrgID            string                      `json:"org_id"`
	OauthClientID    string                      `json:"oauth_client_id"`
	OauthKeys        map[string]string           `json:"oauth_keys"`
	BasicAuthData    struct {
		Password string   `json:"password"`
		Hash     HashType `json:"hash_type"`
	} `json:"basic_auth_data"`
	JWTData struct {
		Secret string `json:"secret"`
	} `json:"jwt_data"`
	HMACEnabled   bool   `json:"hmac_enabled"`
	HmacSecret    string `json:"hmac_string"`
	IsInactive    bool   `json:"is_inactive"`
	ApplyPolicyID string `json:"apply_policy_id"`
	DataExpires   int64  `json:"data_expires"`
	Monitor       struct {
		TriggerLimits []float64 `json:"trigger_limits"`
	} `json:"monitor"`
	MetaData interface{} `json:"meta_data"`
	Tags     []string    `json:"tags"`
}

SessionState objects represent a current API session, mainly used for rate limiting.

type TokenResponse

type TokenResponse struct {
	KeyID string `json:"key_id"`
}

type TykAPI

type TykAPI struct {
	GatewayConfig         EndpointConfig
	DashboardConfig       EndpointConfig
	CustomDispatcher      func(target Endpoint, method string, usercode string, body io.Reader) ([]byte, int, error) `json:"-"`
	CustomSuperDispatcher func(target Endpoint, method string, body io.Reader) ([]byte, int, error)                  `json:"-"`
}

TykAPI is the main object (and configuration) of the Tyk API wrapper

func (*TykAPI) CreateAdminSSONonce

func (t *TykAPI) CreateAdminSSONonce(data interface{}) (interface{}, Endpoint, error)

Legacy admin API

func (*TykAPI) CreateDeveloper

func (t *TykAPI) CreateDeveloper(UserCred string, dev PortalDeveloper) error

CreateDeveloper will create a developer using the advanced API

func (*TykAPI) CreateSSONonce

func (t *TykAPI) CreateSSONonce(userAPICred string, data interface{}) (interface{}, Endpoint, error)

CreateSSONonce will generate a single-signon nonce for the relevant part of the Tyk service (dashbaord or portal), nonces are single-use and expire after 60 seconds to prevent hijacking, they are only available during successful requests by redirecting the user. It is recommended that SSL is used throughout

func (*TykAPI) Decode

func (t *TykAPI) Decode(raw []byte, retVal interface{}) error

Dcode will unmarshal a request body, a bit redundant tbh

func (*TykAPI) DispatchAndDecode

func (t *TykAPI) DispatchAndDecode(target Endpoint, method string, APIName TykAPIName, retVal interface{}, creds string, body io.Reader, ctype string) (error, int, bool)

DispatchAndDecode will select the API to target, dispatch the request, then decode ther esponse to return to the caller

func (*TykAPI) DispatchDashboard

func (t *TykAPI) DispatchDashboard(target Endpoint, method string, usercode string, body io.Reader) ([]byte, int, error)

DispatchDashboard dispatches a request to the dashboard API and handles the response

func (*TykAPI) DispatchDashboardSuper

func (t *TykAPI) DispatchDashboardSuper(target Endpoint, method string, body io.Reader) ([]byte, int, error)

DispatchDashboardSuper will dispatch a request to the dashbaord super-user API (admin)

func (*TykAPI) DispatchGateway

func (t *TykAPI) DispatchGateway(target Endpoint, method string, body io.Reader, ctype string) ([]byte, int, error)

DispatchGateway will dispatch a request to the gateway API

func (*TykAPI) GetDeveloper

func (t *TykAPI) GetDeveloper(UserCred string, DeveloperEmail string) (PortalDeveloper, error)

GetDeveloper will retrieve a developer from the Advanced API using their Email address

func (*TykAPI) GetDeveloperBySSOKey

func (t *TykAPI) GetDeveloperBySSOKey(UserCred string, SsoKey string) (PortalDeveloper, error, bool)

GetDeveloperBySSOKey will retrieve a deverloper from the Advanced API using their SSO Key address

func (*TykAPI) InvalidateToken

func (t *TykAPI) InvalidateToken(UserCred string, BaseAPI string, token string) (error, bool)

func (*TykAPI) RequestOAuthToken

func (t *TykAPI) RequestOAuthToken(APIlistenPath, redirect_uri, responseType, clientId, secret, orgID, policyID, BaseAPIID string, userInfo interface{}) (*OAuthResponse, error)

func (*TykAPI) RequestStandardToken

func (t *TykAPI) RequestStandardToken(orgID, policyID, BaseAPIID, UserCred string, expires int64, userInfo interface{}) (*TokenResponse, error)

func (*TykAPI) UpdateDeveloper

func (t *TykAPI) UpdateDeveloper(UserCred string, dev PortalDeveloper) error

UpdateDeveloper will update a developer object using the advanced API

type TykAPIName

type TykAPIName string // A type for Tyk API names (e.g. dashboard, gateway)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL