Expose route and app models to RunnerCall for extensions (alternative 2) (#880)

This commit is contained in:
Dario Domizioli
2018-03-22 20:07:39 +00:00
committed by Gerardo Viedma
parent 563a4576ef
commit 8df8ed6360
2 changed files with 15 additions and 0 deletions

View File

@@ -101,6 +101,7 @@ func FromRequest(appName, path string, req *http.Request) CallOpt {
Memory: route.Memory, Memory: route.Memory,
CPUs: route.CPUs, CPUs: route.CPUs,
Config: buildConfig(app, route), Config: buildConfig(app, route),
Annotations: buildAnnotations(app, route),
Headers: req.Header, Headers: req.Header,
CreatedAt: strfmt.DateTime(time.Now()), CreatedAt: strfmt.DateTime(time.Now()),
URL: reqURL(req), URL: reqURL(req),
@@ -135,6 +136,17 @@ func buildConfig(app *models.App, route *models.Route) models.Config {
return conf return conf
} }
func buildAnnotations(app *models.App, route *models.Route) models.Annotations {
ann := make(models.Annotations)
for k, v := range app.Annotations {
ann[k] = v
}
for k, v := range route.Annotations {
ann[k] = v
}
return ann
}
func reqURL(req *http.Request) string { func reqURL(req *http.Request) string {
if req.URL.Scheme == "" { if req.URL.Scheme == "" {
if req.TLS == nil { if req.TLS == nil {

View File

@@ -126,6 +126,9 @@ type Call struct {
// Config is the set of configuration variables for the call // Config is the set of configuration variables for the call
Config Config `json:"config,omitempty" db:"-"` Config Config `json:"config,omitempty" db:"-"`
// Annotations is the set of annotations for the app/route of the call.
Annotations Annotations `json:"annotations,omitempty" db:"-"`
// Headers are headers from the request that created this call // Headers are headers from the request that created this call
Headers http.Header `json:"headers,omitempty" db:"-"` Headers http.Header `json:"headers,omitempty" db:"-"`