func New(e *empire.Empire, options Options) http.Handler { r := httpx.NewRouter() if options.GitHub.Webhooks.Secret != "" { // Mount GitHub webhooks g := github.New(e, github.Options{ Secret: options.GitHub.Webhooks.Secret, Environment: options.GitHub.Deployments.Environment, ImageTemplate: options.GitHub.Deployments.ImageTemplate, TugboatURL: options.GitHub.Deployments.TugboatURL, }) r.Match(githubWebhook, g) } // Mount the heroku api h := heroku.New(e, options.Authenticator) r.Headers("Accept", heroku.AcceptHeader).Handler(h) // Mount health endpoint r.Handle("/health", NewHealthHandler(e)) return middleware.Common(r, middleware.CommonOpts{ Reporter: e.Reporter, Logger: e.Logger, }) }
func New(e *empire.Empire, options Options) *Server { r := httpx.NewRouter() s := &Server{mux: r} if options.GitHub.Webhooks.Secret != "" { // Mount GitHub webhooks g := github.New(e, github.Options{ Secret: options.GitHub.Webhooks.Secret, Environments: options.GitHub.Deployments.Environments, Deployer: newDeployer(e, options), }) r.Match(githubWebhook, g) } // Mount the heroku api s.Heroku = heroku.New(e) r.Headers("Accept", heroku.AcceptHeader).Handler(s.Heroku) // Mount SAML handlers. r.HandleFunc("/saml/login", s.SAMLLogin) r.HandleFunc("/saml/acs", s.SAMLACS) // Mount health endpoint r.Handle("/health", NewHealthHandler(e)) return s }
// New creates the API routes and returns a new http.Handler to serve them. func New(e *empire.Empire, authenticator auth.Authenticator) httpx.Handler { r := httpx.NewRouter() // Apps r.Handle("/apps", &GetApps{e}).Methods("GET") // hk apps r.Handle("/apps/{app}", &GetAppInfo{e}).Methods("GET") // hk info r.Handle("/apps/{app}", &DeleteApp{e}).Methods("DELETE") // hk destroy r.Handle("/apps/{app}", &PatchApp{e}).Methods("PATCH") // hk destroy r.Handle("/apps/{app}/deploys", &DeployApp{e}).Methods("POST") // Deploy an image to an app r.Handle("/apps", &PostApps{e}).Methods("POST") // hk create r.Handle("/organizations/apps", &PostApps{e}).Methods("POST") // hk create // Domains r.Handle("/apps/{app}/domains", &GetDomains{e}).Methods("GET") // hk domains r.Handle("/apps/{app}/domains", &PostDomains{e}).Methods("POST") // hk domain-add r.Handle("/apps/{app}/domains/{hostname}", &DeleteDomain{e}).Methods("DELETE") // hk domain-remove // Deploys r.Handle("/deploys", &PostDeploys{e}).Methods("POST") // Deploy an app // Releases r.Handle("/apps/{app}/releases", &GetReleases{e}).Methods("GET") // hk releases r.Handle("/apps/{app}/releases/{version}", &GetRelease{e}).Methods("GET") // hk release-info r.Handle("/apps/{app}/releases", &PostReleases{e}).Methods("POST") // hk rollback // Configs r.Handle("/apps/{app}/config-vars", &GetConfigs{e}).Methods("GET") // hk env, hk get r.Handle("/apps/{app}/config-vars", &PatchConfigs{e}).Methods("PATCH") // hk set, hk unset // Processes r.Handle("/apps/{app}/dynos", &GetProcesses{e}).Methods("GET") // hk dynos r.Handle("/apps/{app}/dynos", &PostProcess{e}).Methods("POST") // hk run r.Handle("/apps/{app}/dynos", &DeleteProcesses{e}).Methods("DELETE") // hk restart r.Handle("/apps/{app}/dynos/{ptype}.{pid}", &DeleteProcesses{e}).Methods("DELETE") // hk restart web.1 r.Handle("/apps/{app}/dynos/{pid}", &DeleteProcesses{e}).Methods("DELETE") // hk restart web // Formations r.Handle("/apps/{app}/formation", &PatchFormation{e}).Methods("PATCH") // hk scale // OAuth r.Handle("/oauth/authorizations", &PostAuthorizations{e}).Methods("POST") // SSL sslRemoved := errHandler(ErrSSLRemoved) r.Handle("/apps/{app}/ssl-endpoints", sslRemoved).Methods("GET") // hk ssl r.Handle("/apps/{app}/ssl-endpoints", sslRemoved).Methods("POST") // hk ssl-cert-add r.Handle("/apps/{app}/ssl-endpoints/{cert}", sslRemoved).Methods("PATCH") // hk ssl-cert-add, hk ssl-cert-rollback r.Handle("/apps/{app}/ssl-endpoints/{cert}", sslRemoved).Methods("DELETE") // hk ssl-destroy // Logs r.Handle("/apps/{app}/log-sessions", &PostLogs{e}).Methods("POST") // hk log errorHandler := func(err error, w http.ResponseWriter, r *http.Request) { Error(w, err, http.StatusInternalServerError) } api := Authenticate(r, authenticator) return middleware.HandleError(api, errorHandler) }
func NewHTTPHandler(r *Relay) http.Handler { m := httpx.NewRouter() m.Handle("POST", "/containers", &PostContainers{r}) var h httpx.Handler // Handle errors errorHandler := func(err error, w http.ResponseWriter, r *http.Request) { Error(w, err, http.StatusInternalServerError) } h = middleware.HandleError(m, errorHandler) // Recover from panics. h = middleware.Recover(h, reporter.NewLogReporter()) // Add a logger to the context. h = middleware.NewLogger(h, os.Stdout) // Add the request id to the context. h = middleware.ExtractRequestID(h) // Wrap the route in middleware to add a context.Context. return middleware.BackgroundContext(h) }
// New returns a new Server instance to serve the Heroku compatible API. func New(e *empire.Empire) *Server { r := &Server{ Empire: e, mux: httpx.NewRouter(), } // Apps r.handle("GET", "/apps", r.GetApps) // hk apps r.handle("GET", "/apps/{app}", r.GetAppInfo) // hk info r.handle("DELETE", "/apps/{app}", r.DeleteApp) // hk destroy r.handle("PATCH", "/apps/{app}", r.PatchApp) // hk destroy r.handle("POST", "/apps/{app}/deploys", r.DeployApp) // Deploy an image to an app r.handle("POST", "/apps", r.PostApps) // hk create r.handle("POST", "/organizations/apps", r.PostApps) // hk create // Domains r.handle("GET", "/apps/{app}/domains", r.GetDomains) // hk domains r.handle("POST", "/apps/{app}/domains", r.PostDomains) // hk domain-add r.handle("DELETE", "/apps/{app}/domains/{hostname}", r.DeleteDomain) // hk domain-remove // Deploys r.handle("POST", "/deploys", r.PostDeploys) // Deploy an app // Releases r.handle("GET", "/apps/{app}/releases", r.GetReleases) // hk releases r.handle("GET", "/apps/{app}/releases/{version}", r.GetRelease) // hk release-info r.handle("POST", "/apps/{app}/releases", r.PostReleases) // hk rollback // Configs r.handle("GET", "/apps/{app}/config-vars", r.GetConfigs) // hk env, hk get r.handle("PATCH", "/apps/{app}/config-vars", r.PatchConfigs) // hk set, hk unset // Processes r.handle("GET", "/apps/{app}/dynos", r.GetProcesses) // hk dynos r.handle("POST", "/apps/{app}/dynos", r.PostProcess) // hk run r.handle("DELETE", "/apps/{app}/dynos", r.DeleteProcesses) // hk restart r.handle("DELETE", "/apps/{app}/dynos/{ptype}.{pid}", r.DeleteProcesses) // hk restart web.1 r.handle("DELETE", "/apps/{app}/dynos/{pid}", r.DeleteProcesses) // hk restart web // Formations r.handle("GET", "/apps/{app}/formation", r.GetFormation) // hk scale -l r.handle("PATCH", "/apps/{app}/formation", r.PatchFormation) // hk scale // OAuth r.handle("POST", "/oauth/authorizations", r.PostAuthorizations) // SSL sslRemoved := errHandler(ErrSSLRemoved) r.mux.Handle("/apps/{app}/ssl-endpoints", sslRemoved).Methods("GET") // hk ssl r.mux.Handle("/apps/{app}/ssl-endpoints", sslRemoved).Methods("POST") // hk ssl-cert-add r.mux.Handle("/apps/{app}/ssl-endpoints/{cert}", sslRemoved).Methods("PATCH") // hk ssl-cert-add, hk ssl-cert-rollback r.mux.Handle("/apps/{app}/ssl-endpoints/{cert}", sslRemoved).Methods("DELETE") // hk ssl-destroy // Logs r.handle("POST", "/apps/{app}/log-sessions", r.PostLogs) // hk log return r }
func New(e *empire.Empire, options Options) http.Handler { r := httpx.NewRouter() auth := NewAuthorizer( options.GitHub.ClientID, options.GitHub.ClientSecret, options.GitHub.Organization, ) // Mount the heroku api h := heroku.New(e, auth) r.Headers("Accept", heroku.AcceptHeader).Handler(h) // Mount health endpoint r.Handle("/health", NewHealthHandler(e)) return middleware.Common(r, middleware.CommonOpts{ Reporter: e.Reporter, Logger: e.Logger, }) }
func New(e *empire.Empire, options Options) httpx.Handler { r := httpx.NewRouter() if options.GitHub.Webhooks.Secret != "" { // Mount GitHub webhooks g := github.New(e, github.Options{ Secret: options.GitHub.Webhooks.Secret, Environments: options.GitHub.Deployments.Environments, Deployer: newDeployer(e, options), }) r.Match(githubWebhook, g) } // Mount the heroku api hk := heroku.New(e, options.Authenticator) r.Headers("Accept", heroku.AcceptHeader).Handler(hk) // Mount health endpoint r.Handle("/health", NewHealthHandler(e)) return r }
func traceTest(t *testing.T, tt *tracerTest) { var m httpx.Handler r := httpx.NewRouter() if tt.routes != nil { tt.routes(r) } tx := new(mockTx) m = &NewRelicTracer{ handler: r, router: r, tracer: nil, createTx: func(transactionName, url string, tracer newrelic.TxTracer) newrelic.Tx { if tt.expectedTransactionName != transactionName { t.Fatalf("Transaction mismatch expected: %v got: %v", tt.expectedTransactionName, transactionName) } if tt.expectedUrl != url { t.Fatalf("Url mismatch expected: %v got: %v", tt.expectedUrl, url) } return tx }, } ctx := context.Background() resp := httptest.NewRecorder() tx.On("Start").Return(nil) tx.On("End").Return(nil) if err := m.ServeHTTPContext(ctx, resp, tt.req); err != nil { t.Fatal(err) } tx.AssertExpectations(t) }