Documentation ¶
Overview ¶
Package tenant contains functions to determine for which tenant a request should be served.
As soon as an App is registered in d.velop cloud requests for ALL tenants which booked the app are routed to the App. So each App MUST be able to serve requests for multiple tenants concurrently.
Each request contains http headers (x-dv-tenant-id, x-dv-baseuri, x-dv-sig-1) which MUST be evaluated by the App to determine the tenant for which the request is meant.
The tenant-id is meant as a stable and unique identifier for a tenant which doesn't change over time. It can be used to store tenant specific data.
The systemBaseUri is the baseadress of the system for the particular tenant. It MUST be used if an App makes requests to other Apps on behalf of a tenant.
This package contains functions which read the tenant information from a request and put them in the context.
Example:
func main() { mux := http.NewServeMux() // NOTE: Each App gets it's own signature secret. So please change the following code accordingly and do not share your secret! mux.Handle("/hello", tenant.AddToCtx(os.Getenv("systemBaseUri"), base64.StdEncoding.DecodeString("U2VjcmV0"))(helloHandler())) } func helloHandler() http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // get systembaseuri from context systembaseuri,_ := tenant.SystemBaseUriFromCtx(r.Context()) // get tenant id from context tenant,_ := tenant.IdFromCtx(r.Context()) }) }
Index ¶
- func AddToCtx(defaultSystemBaseUri string, signatureSecretKey []byte) func(http.Handler) http.Handler
- func IdFromCtx(ctx context.Context) (string, error)
- func InitiatorSystemBaseUriFromCtx(ctx context.Context) (string, error)
- func SetId(ctx context.Context, tenantId string) context.Context
- func SetInitiatorSystemBaseUri(ctx context.Context, initiatorSystemBaseUri string) context.Context
- func SetSystemBaseUri(ctx context.Context, systemBaseUri string) context.Context
- func SystemBaseUriFromCtx(ctx context.Context) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddToCtx ¶
func AddToCtx(defaultSystemBaseUri string, signatureSecretKey []byte) func(http.Handler) http.Handler
Adds systemBaseUri and tenantId to request context. If the headers are not present the given defaultSystemBaseUri and tenant "0" are used. The signatureSecretKey is specific for each App and is provided by the registration process for d.velop cloud.
func InitiatorSystemBaseUriFromCtx ¶
InitiatorSystemBaseUriFromCtx reads the uri of the initial requesting host from the context.
func SetInitiatorSystemBaseUri ¶
SetInitiatorSystemBaseUri returns a new context.Context with the given initiatorSystemBaseUri
func SetSystemBaseUri ¶
SetSystemBaseUri returns a new context.Context with the given systemBaseUri
Types ¶
This section is empty.