From 3b108d3aeda29112aa901667d108cbb0f173fd5d Mon Sep 17 00:00:00 2001 From: Matt Fuller Date: Wed, 15 Feb 2017 14:11:51 -0500 Subject: [PATCH 1/2] adding a healthcheck path --- VERSION | 2 +- src/http/handler.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 79127d8..18fa8e7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v1.2.0 +v1.3.0 diff --git a/src/http/handler.go b/src/http/handler.go index 7db52ba..5d999ba 100644 --- a/src/http/handler.go +++ b/src/http/handler.go @@ -18,6 +18,8 @@ const ( credentialType = "AWS-HMAC" credentialCode = "Success" iamPath = "/meta-data/iam/security-credentials/" + healthMethod = "GET" + healthPath = "/healthcheck" ) var ( @@ -50,6 +52,12 @@ func (handler *httpHandler) serveFastHTTP(ctx *fasthttp.RequestCtx) { "remoteAddr": addr, }) + if method == healthMethod && path == healthPath { + logger.Debug("Serving health check request") + handler.serveHealthRequest(ctx, logger) + return + } + if method == iamMethod { idx := strings.LastIndex(path, iamPath) if idx == (len(path) - len(iamPath)) { @@ -127,6 +135,11 @@ func (handler *httpHandler) serveDeniedRequest(ctx *fasthttp.RequestCtx, addr st logger.Debug("Successfully responded") } +func (handler *httpHandler) serveHealthRequest(ctx *fasthttp.RequestCtx, logger *logrus.Entry) { + ctx.SetStatusCode(200) + logger.Debug("Successfully responded") +} + func (handler *httpHandler) credentialsForAddress(address string) (*string, *sts.Credentials, error) { ip := strings.Split(address, ":")[0] role, err := handler.containerStore.IAMRoleForIP(ip) From 8afe8ba4dbb75f2ba0b6318e942c5a372ad2e894 Mon Sep 17 00:00:00 2001 From: Matt Fuller Date: Wed, 15 Feb 2017 15:07:55 -0500 Subject: [PATCH 2/2] combining conditionals for http handler --- src/http/handler.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/http/handler.go b/src/http/handler.go index 5d999ba..cefe602 100644 --- a/src/http/handler.go +++ b/src/http/handler.go @@ -56,9 +56,7 @@ func (handler *httpHandler) serveFastHTTP(ctx *fasthttp.RequestCtx) { logger.Debug("Serving health check request") handler.serveHealthRequest(ctx, logger) return - } - - if method == iamMethod { + } else if method == iamMethod { idx := strings.LastIndex(path, iamPath) if idx == (len(path) - len(iamPath)) { logger.Debug("Serving list IAM credentials request")