aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/api.go
blob: 39fc227557942456f8bbb392954645bd4f21aaf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package controllers

import (
	"net/http"

	"code.crute.us/mcrute/cloud-identity-broker/app/middleware"

	glecho "code.crute.us/mcrute/golib/echo"
	"github.com/labstack/echo/v4"
)

const (
	contentTypeV1              = "application/vnd.broker.v1+json"               // Original type
	contentTypeV2              = "application/vnd.broker.v2+json"               // Start of migration to multi-cloud
	contentTypeV2AWSBash       = "application/vnd.broker.v2.credential.aws.sh"  // Bash Formatted Credential for AWS
	contentTypeV2AWSPowershell = "application/vnd.broker.v2.credential.aws.psl" // Powershell Formatted Credential for AWS
	contentTypeV2AWSConfig     = "application/vnd.broker.v2.credential.aws.ini" // INI Formatted Credential for AWS
)

func APIIndexHandler(c echo.Context) error {
	p, err := middleware.GetAuthorizedPrincipal(c)
	if err != nil {
		return echo.ErrUnauthorized
	}

	out := map[string]string{
		"accounts": glecho.URLFor(c, "/api/account").String(),
	}

	if p.IsAdmin {
		out["users"] = glecho.URLFor(c, "/api/user").String()
	}

	return c.JSON(http.StatusOK, out)
}