tenant

package module
v0.0.0-...-39ac581 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 8 Imported by: 4

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

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 IdFromCtx

func IdFromCtx(ctx context.Context) (string, error)

IdFromCtx reads the tenant id from the context.

func InitiatorSystemBaseUriFromCtx

func InitiatorSystemBaseUriFromCtx(ctx context.Context) (string, error)

InitiatorSystemBaseUriFromCtx reads the uri of the initial requesting host from the context.

func SetId

func SetId(ctx context.Context, tenantId string) context.Context

SetId returns a new context.Context with the given tenantId

func SetInitiatorSystemBaseUri

func SetInitiatorSystemBaseUri(ctx context.Context, initiatorSystemBaseUri string) context.Context

SetInitiatorSystemBaseUri returns a new context.Context with the given initiatorSystemBaseUri

func SetSystemBaseUri

func SetSystemBaseUri(ctx context.Context, systemBaseUri string) context.Context

SetSystemBaseUri returns a new context.Context with the given systemBaseUri

func SystemBaseUriFromCtx

func SystemBaseUriFromCtx(ctx context.Context) (string, error)

SystemBaseUriFromCtx reads the systemBaseUri from the context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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