Skip to content

Commit

Permalink
Add auth
Browse files Browse the repository at this point in the history
  • Loading branch information
olevitt committed Mar 21, 2024
1 parent 7baf611 commit 9a43def
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
24 changes: 18 additions & 6 deletions cmd/public-handler.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"fmt"
"net/http"

"runtime/debug"
Expand All @@ -15,8 +14,14 @@ type BuildInfo struct {
CommitDate string `json:"commitDate,omitempty"`
}
type PublicConfiguration struct {
Build BuildInfo `json:"build"`
Regions interface{} `json:"regions"`
Build BuildInfo `json:"build"`
Regions interface{} `json:"regions"`
OIDCConfiguration *OIDCConfiguration `json:"oidcConfiguration,omitempty"`
}
type OIDCConfiguration struct {
IssuerURI string `json:"issuerURI,omitempty"`
ClientID string `json:"clientID,omitempty"`
ExtraQueryParams string `json:"extraQueryParams,omitempty"`
}

// PingExample godoc
Expand All @@ -41,18 +46,25 @@ func getConfiguration(c *gin.Context) {
info, _ := debug.ReadBuildInfo()
var buildInfo = BuildInfo{}
for _, kv := range info.Settings {
fmt.Println(kv.Key)
if kv.Key == "vcs.time" {
buildInfo.CommitDate = kv.Value
}
if kv.Key == "vcs.revision" {
buildInfo.Commit = kv.Value
}
}
c.JSON(http.StatusOK, PublicConfiguration{
var publicConfiguration = PublicConfiguration{
Build: buildInfo,
Regions: configuration.Config.Regions,
})
}
if configuration.IsAuthenticationEnabled() {
publicConfiguration.OIDCConfiguration = &OIDCConfiguration{
IssuerURI: configuration.Config.OIDC.IssuerURI,
ClientID: configuration.Config.OIDC.ClientID,
ExtraQueryParams: configuration.Config.OIDC.ExtraQueryParams,
}
}
c.JSON(http.StatusOK, publicConfiguration)
}

func registerPublicHandlers(r *gin.RouterGroup) {
Expand Down
6 changes: 6 additions & 0 deletions internal/configuration/configuration.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package configuration

import "strings"

type Configuration struct {
Authentication Authentication
RootPath string
Expand Down Expand Up @@ -182,3 +184,7 @@ type Region struct {
URL string `json:"URL"`
} `json:"git"`
}

func IsAuthenticationEnabled() bool {
return strings.EqualFold(Config.Authentication.Mode, "openidconnect")
}

0 comments on commit 9a43def

Please sign in to comment.