Skip to content

Commit

Permalink
feat: Add /tags endpoint
Browse files Browse the repository at this point in the history
The instance tags are useful to understand things for debugging, such as:
- The launch template version
- The CloudFormation stack name
  • Loading branch information
akash1810 committed Aug 22, 2024
1 parent f8b867e commit 2721d49
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/controllers/ManagementController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@ import buildinfo.BuildInfo
import play.api.Logging
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent, BaseController, ControllerComponents}
import scala.io.Source

class ManagementController (override val controllerComponents: ControllerComponents) extends BaseController with Logging {
def manifest: Action[AnyContent] = Action {
Ok(Json.parse(BuildInfo.toJson))
}

def tags: Action[AnyContent] = Action {
/*
This file is created by https://github.com/guardian/instance-tag-discovery,
which is part of the `cdk-base` AMIgo role.
*/
val filename = "/etc/config/tags.json"
try {
val content = Source.fromFile(filename)
val tagsJson = try content.mkString finally content.close()
Ok(Json.parse(tagsJson))
}
catch {
case e: Exception => InternalServerError(e.getMessage)
}
}

def disallowRobots: Action[AnyContent] = Action {
Ok("User-agent: *\nDisallow: /\n")
}
Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
GET / controllers.ManagementController.manifest
GET /tags controllers.ManagementController.tags
GET /healthcheck controllers.ManagementController.healthCheck
GET /moved-permanently controllers.ManagementController.movedPermanently
GET /bad-request controllers.ManagementController.badRequest
Expand Down

0 comments on commit 2721d49

Please sign in to comment.