tyk

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2018 License: MPL-2.0 Imports: 12 Imported by: 0

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             Endpoint = "/admin/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

This section is empty.

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            bson.ObjectId     `bson:"_id,omitempty" json:"id"`
	Email         string            `bson:"email" json:"email"`
	Password      string            `bson:"password" json:"password"`
	DateCreated   time.Time         `bson:"date_created" json:"date_created"`
	InActive      bool              `bson:"inactive" json:"inactive"`
	OrgId         string            `bson:"org_id" json:"org_id"`
	ApiKeys       map[string]string `bson:"api_keys" json:"api_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"`
}

PortalDeveloper represents a portal developer

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
}

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

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(target Endpoint, data interface{}) (interface{}, 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 ecommended 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

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, 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, 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, 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 deverloper from the Advanced API using their Email address

func (*TykAPI) GetDeveloperBySSOKey

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

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

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