Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project info text and URL made configurable #319

Merged
merged 6 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions charts/sda-svc/templates/auth-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ spec:
{{- end }}
- name: S3INBOX
value: {{ .Values.global.ingress.hostName.s3Inbox }}
- name: INFOTEXT
value: {{ .Values.global.auth.infoText }}
- name: INFOURL
value: {{ .Values.global.auth.inforURL }}
ports:
- name: auth
containerPort: 8080
Expand Down
4 changes: 4 additions & 0 deletions charts/sda-svc/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ global:
corsMethods: ""
# @param corsCreds, allow credentials in the request, cors is disabled if false
corsCreds: false
# @param infoText, name of the project
infoText: "About Federated EGA"
# @param inforURL, URL of the project
inforURL: "https://ega-archive.org/about/projects-and-funders/federated-ega/"

broker:
durable: true
Expand Down
4 changes: 4 additions & 0 deletions sda-auth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type Config struct {
Server ServerConfig
S3Inbox string
ResignJwt bool
InfoURL string
InfoText string
}

// NewConfig initializes and parses the config file and/or environment using
Expand Down Expand Up @@ -90,6 +92,8 @@ func (c *Config) readConfig() error {
c.JwtPrivateKey = viper.GetString("JwtPrivateKey")
c.JwtSignatureAlg = viper.GetString("JwtSignatureAlg")
c.JwtIssuer = viper.GetString("jwtIssuer")
c.InfoURL = viper.GetString("infoUrl")
c.InfoText = viper.GetString("infoText")

viper.SetDefault("ResignJwt", true)
c.ResignJwt = viper.GetBool("resignJwt")
Expand Down
2 changes: 2 additions & 0 deletions sda-auth/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ jwtIssuer: "http://auth:8080"
jwtPrivateKey: "keys/sign-jwt.key"
jwtSignatureAlg: "ES256"
resignJwt: true
infoText: "About Federated EGA"
infoUrl: "https://ega-archive.org/about/projects-and-funders/federated-ega/"
16 changes: 16 additions & 0 deletions sda-auth/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type ConfigTests struct {
JwtPrivateKeyFile *os.File
JwtSignatureAlg string
ResignJwt bool
InfoURL string
InfoText string
}

func TestConfigTestSuite(t *testing.T) {
Expand Down Expand Up @@ -85,6 +87,8 @@ func (suite *ConfigTests) SetupTest() {
suite.JwtPrivateKey = suite.JwtPrivateKeyFile.Name()
suite.JwtSignatureAlg = "RS256"
suite.ResignJwt = true
suite.InfoURL = "https://test.info"
suite.InfoText = "About LEGA"

// Write config to temp config file
configYaml, err := yaml.Marshal(Config{
Expand All @@ -96,6 +100,8 @@ func (suite *ConfigTests) SetupTest() {
JwtPrivateKey: suite.JwtPrivateKey,
JwtSignatureAlg: suite.JwtSignatureAlg,
ResignJwt: suite.ResignJwt,
InfoURL: suite.InfoURL,
InfoText: suite.InfoText,
})
if err != nil {
log.Errorf("Error marshalling config yaml: %v", err)
Expand Down Expand Up @@ -147,6 +153,10 @@ func (suite *ConfigTests) TestConfig() {
assert.Equal(suite.T(), suite.JwtSignatureAlg, config.JwtSignatureAlg, "JwtSignatureAlg misread from config file")
assert.Equal(suite.T(), suite.ResignJwt, config.ResignJwt, "ResignJwt misread from config file")

// Check project info values
assert.Equal(suite.T(), suite.InfoText, config.InfoText, "Project info test misread from config file")
assert.Equal(suite.T(), suite.InfoURL, config.InfoURL, "Project info URL misread from config file")

// sanitycheck without config file or ENVs
// this should fail
os.Remove(suite.ConfigFile.Name())
Expand Down Expand Up @@ -174,6 +184,9 @@ func (suite *ConfigTests) TestConfig() {
os.Setenv("JWTSIGNATUREALG", fmt.Sprintf("env_%v", suite.JwtSignatureAlg))
os.Setenv("RESIGNJWT", fmt.Sprintf("%t", suite.ResignJwt))

os.Setenv("INFOTEXT", fmt.Sprintf("env_%v", suite.InfoText))
os.Setenv("INFOURL", fmt.Sprintf("env_%v", suite.InfoURL))

// re-read the config
config, err = NewConfig()
assert.NoError(suite.T(), err)
Expand All @@ -197,6 +210,9 @@ func (suite *ConfigTests) TestConfig() {
assert.Equal(suite.T(), fmt.Sprintf("env_%v", suite.JwtSignatureAlg), config.JwtSignatureAlg, "JwtSignatureAlg misread from environment variable")
assert.Equal(suite.T(), fmt.Sprintf("%t", suite.ResignJwt), strconv.FormatBool(config.ResignJwt), "ResignJwt misread from environment variable")

assert.Equal(suite.T(), fmt.Sprintf("env_%v", suite.InfoText), config.InfoText, "Project info text misread from environment variable")
assert.Equal(suite.T(), fmt.Sprintf("env_%v", suite.InfoURL), config.InfoURL, "Project info text misread from environment variable")

// Check missing private key
os.Setenv("JWTPRIVATEKEY", "nonexistent-key-file")

Expand Down
2 changes: 1 addition & 1 deletion sda-auth/frontend/templates/ega.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://elixir-europe.org/about-us/staff-exchange-programme/localfederated-ega">About LocalEGA</a>
<a class="nav-link" href="{{.infoUrl}}">{{.infoText}}</a>
</li>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion sda-auth/frontend/templates/elixir.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://elixir-europe.org/about-us/staff-exchange-programme/localfederated-ega">About LocalEGA</a>
<a class="nav-link" href="{{.infoUrl}}">{{.infoText}}</a>
</li>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion sda-auth/frontend/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://elixir-europe.org/about-us/staff-exchange-programme/localfederated-ega">About LocalEGA</a>
<a class="nav-link" href="{{.infoUrl}}">{{.infoText}}</a>
</li>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion sda-auth/frontend/templates/loginform.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://elixir-europe.org/about-us/staff-exchange-programme/localfederated-ega">About LocalEGA</a>
<a class="nav-link" href="{{.infoUrl}}">{{.infoText}}</a>
</li>
</ul>
</div>
Expand Down
10 changes: 10 additions & 0 deletions sda-auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func (auth AuthHandler) getInboxConfig(ctx iris.Context, authType string) {
// getMain returns the index.html page
func (auth AuthHandler) getMain(ctx iris.Context) {

ctx.ViewData("infoUrl", auth.Config.InfoURL)
ctx.ViewData("infoText", auth.Config.InfoText)
err := ctx.View("index.html")
if err != nil {
log.Error("Failed to view index page: ", err)
Expand Down Expand Up @@ -150,6 +152,8 @@ func (auth AuthHandler) postEGA(ctx iris.Context) {
s3conf := getS3ConfigMap(token, auth.Config.S3Inbox, username)
idStruct := EGAIdentity{User: username, Token: token, ExpDate: expDate}
s.SetFlash("ega", s3conf)
ctx.ViewData("infoUrl", auth.Config.InfoURL)
ctx.ViewData("infoText", auth.Config.InfoText)
err = ctx.View("ega.html", idStruct)
if err != nil {
log.Error("Failed to parse response: ", err)
Expand Down Expand Up @@ -181,6 +185,8 @@ func (auth AuthHandler) getEGALogin(ctx iris.Context) {
s := sessions.Get(ctx)
message := s.GetFlashString("message")
if message == "" {
ctx.ViewData("infoUrl", auth.Config.InfoURL)
ctx.ViewData("infoText", auth.Config.InfoText)
err := ctx.View("loginform.html")
if err != nil {
log.Error("Failed to return to login form: ", err)
Expand All @@ -190,6 +196,8 @@ func (auth AuthHandler) getEGALogin(ctx iris.Context) {

return
}
ctx.ViewData("infoUrl", auth.Config.InfoURL)
ctx.ViewData("infoText", auth.Config.InfoText)
err := ctx.View("loginform.html", EGALoginError{Reason: message})
if err != nil {
log.Error("Failed to view invalid credentials form: ", err)
Expand Down Expand Up @@ -284,6 +292,8 @@ func (auth AuthHandler) getElixirLogin(ctx iris.Context) {

s := sessions.Get(ctx)
s.SetFlash("elixir", oidcData.S3Conf)
ctx.ViewData("infoUrl", auth.Config.InfoURL)
ctx.ViewData("infoText", auth.Config.InfoText)
err := ctx.View("elixir.html", oidcData.ElixirID)
if err != nil {
log.Error("Failed to view login form: ", err)
Expand Down
Loading