diff options
author | Mike Crute <mike@crute.us> | 2021-11-22 18:39:08 -0800 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2021-11-22 18:39:08 -0800 |
commit | 4f457596a2fa991b5914d4c368697c659db9d1e7 (patch) | |
tree | 3731fab5a7ea1eafb59f6c2770eb74db821f1562 | |
parent | 114dbb5ab7952ab66a041c814d5c6a028c8e3039 (diff) | |
download | cloud-identity-broker-4f457596a2fa991b5914d4c368697c659db9d1e7.tar.bz2 cloud-identity-broker-4f457596a2fa991b5914d4c368697c659db9d1e7.tar.xz cloud-identity-broker-4f457596a2fa991b5914d4c368697c659db9d1e7.zip |
Add API index resource
-rw-r--r-- | app/controllers/api.go | 26 | ||||
-rw-r--r-- | cmd/web/server.go | 45 |
2 files changed, 51 insertions, 20 deletions
diff --git a/app/controllers/api.go b/app/controllers/api.go index 7beaa4c..5ee6591 100644 --- a/app/controllers/api.go +++ b/app/controllers/api.go | |||
@@ -1,6 +1,32 @@ | |||
1 | package controllers | 1 | package controllers |
2 | 2 | ||
3 | import ( | ||
4 | "net/http" | ||
5 | |||
6 | "code.crute.us/mcrute/cloud-identity-broker/app/middleware" | ||
7 | |||
8 | glecho "code.crute.us/mcrute/golib/echo" | ||
9 | "github.com/labstack/echo/v4" | ||
10 | ) | ||
11 | |||
3 | const ( | 12 | const ( |
4 | contentTypeV1 = "application/vnd.broker.v1+json" // Original type | 13 | contentTypeV1 = "application/vnd.broker.v1+json" // Original type |
5 | contentTypeV2 = "application/vnd.broker.v2+json" // Start of migration to multi-cloud | 14 | contentTypeV2 = "application/vnd.broker.v2+json" // Start of migration to multi-cloud |
6 | ) | 15 | ) |
16 | |||
17 | func APIIndexHandler(c echo.Context) error { | ||
18 | p, err := middleware.GetAuthorizedPrincipal(c) | ||
19 | if err != nil { | ||
20 | return echo.ErrUnauthorized | ||
21 | } | ||
22 | |||
23 | out := map[string]string{ | ||
24 | "accounts": glecho.URLFor(c, "/api/account").String(), | ||
25 | } | ||
26 | |||
27 | if p.IsAdmin { | ||
28 | out["users"] = glecho.URLFor(c, "/api/user").String() | ||
29 | } | ||
30 | |||
31 | return c.JSON(http.StatusOK, out) | ||
32 | } | ||
diff --git a/cmd/web/server.go b/cmd/web/server.go index 3797acd..c573244 100644 --- a/cmd/web/server.go +++ b/cmd/web/server.go | |||
@@ -127,30 +127,35 @@ func webMain(cfg app.Config, embeddedTemplates fs.FS, version string) { | |||
127 | } | 127 | } |
128 | am.RegisterUrls(s) | 128 | am.RegisterUrls(s) |
129 | 129 | ||
130 | api := s.Group("/api/account") | 130 | api := s.Group("/api") |
131 | api.Use(glmw.VaryCookie()) | 131 | api.Use(glmw.VaryCookie()) |
132 | api.Use(glmw.CacheNeverMiddleware) | 132 | api.Use(glmw.CacheNeverMiddleware) |
133 | api.Use(am.Middleware) | 133 | api.Use(am.Middleware) |
134 | { | 134 | { |
135 | api.GET("", controllers.NewAPIAccountListHandler(as)) | 135 | api.GET("", controllers.APIIndexHandler) |
136 | api.GET( | 136 | |
137 | "/:account/credentials", | 137 | account := api.Group("/account") |
138 | controllers.NewAPIRegionListHandler(aws), | 138 | { |
139 | ) | 139 | account.GET("", controllers.NewAPIAccountListHandler(as)) |
140 | api.GET( | 140 | account.GET( |
141 | "/:account/console", | 141 | "/:account/credentials", |
142 | controllers.NewAPIConsoleRedirectHandler(aws, cfg.IssuerEndpoint), | 142 | controllers.NewAPIRegionListHandler(aws), |
143 | rateLimit, | 143 | ) |
144 | ) | 144 | account.GET( |
145 | api.GET( | 145 | "/:account/console", |
146 | "/:account/credentials/:region", | 146 | controllers.NewAPIConsoleRedirectHandler(aws, cfg.IssuerEndpoint), |
147 | controllers.NewAPICredentialsHandler(aws), | 147 | rateLimit, |
148 | rateLimit, | 148 | ) |
149 | ) | 149 | account.GET( |
150 | (&controllers.APIAccountHandler{ | 150 | "/:account/credentials/:region", |
151 | Store: as, | 151 | controllers.NewAPICredentialsHandler(aws), |
152 | AdminStore: adminAccountStore, | 152 | rateLimit, |
153 | }).Register("/:account", api) | 153 | ) |
154 | (&controllers.APIAccountHandler{ | ||
155 | Store: as, | ||
156 | AdminStore: adminAccountStore, | ||
157 | }).Register("/:account", account) | ||
158 | } | ||
154 | } | 159 | } |
155 | s.GET("/favicon.ico", echo.NotFoundHandler) | 160 | s.GET("/favicon.ico", echo.NotFoundHandler) |
156 | s.GET("/logout", controllers.LogoutHandler) | 161 | s.GET("/logout", controllers.LogoutHandler) |