Specify AWS Functions as list

to conform with the yaml standard of list definition.
This commit is contained in:
Maximilian Paß
2022-05-28 23:27:56 +02:00
committed by Sebastian Serth
parent d80761a973
commit 0f8a1fa25a
7 changed files with 21 additions and 10 deletions

View File

@ -47,7 +47,7 @@ var (
AWS: AWS{
Enabled: false,
Endpoint: "",
Functions: "",
Functions: []string{},
},
Logger: logger{
Level: "INFO",
@ -105,7 +105,7 @@ func (n *Nomad) URL() *url.URL {
type AWS struct {
Enabled bool
Endpoint string
Functions string
Functions []string
}
// TLS configures TLS on a connection.
@ -235,6 +235,12 @@ func loadValue(prefix string, value reflect.Value, logEntry *logrus.Entry) {
return
}
value.SetBool(boolean)
case reflect.Slice:
if len(content) > 0 && content[0] == '"' && content[len(content)-1] == '"' {
content = content[1 : len(content)-1] // remove wrapping quotes
}
parts := strings.Fields(content)
value.Set(reflect.AppendSlice(value, reflect.ValueOf(parts)))
default:
// ignore this field
logEntry.WithField("type", value.Type().Name()).

View File

@ -16,6 +16,7 @@ var (
getServerPort = func(c *configuration) interface{} { return c.Server.Port }
getNomadToken = func(c *configuration) interface{} { return c.Nomad.Token }
getNomadTLSActive = func(c *configuration) interface{} { return c.Nomad.TLS.Active }
getAWSFunctions = func(c *configuration) interface{} { return c.AWS.Functions }
)
func newTestConfiguration() *configuration {
@ -91,6 +92,7 @@ func TestReadEnvironmentVariables(t *testing.T) {
{"NOMAD_TOKEN", "ACCESS", "ACCESS", getNomadToken},
{"NOMAD_TLS_ACTIVE", "true", true, getNomadTLSActive},
{"NOMAD_TLS_ACTIVE", "hello", false, getNomadTLSActive},
{"AWS_FUNCTIONS", "java11Exec go118Exec", []string{"java11Exec", "go118Exec"}, getAWSFunctions},
}
prefix := "POSEIDON_TEST"
for _, testCase := range environmentTests {
@ -136,6 +138,8 @@ func TestReadYamlConfigFile(t *testing.T) {
{[]byte("nomad:\n tls:\n active: true\n"), true, getNomadTLSActive},
{[]byte(""), false, getNomadTLSActive},
{[]byte("nomad:\n token:\n"), "SECRET", getNomadToken},
{[]byte("aws:\n functions:\n - java11Exec\n - go118Exec\n"),
[]string{"java11Exec", "go118Exec"}, getAWSFunctions},
}
for _, testCase := range yamlTests {
config := newTestConfiguration()

View File

@ -5,7 +5,6 @@ import (
"github.com/openHPI/poseidon/internal/config"
"github.com/openHPI/poseidon/internal/runner"
"github.com/openHPI/poseidon/pkg/dto"
"strings"
)
// AWSEnvironmentManager contains no functionality at the moment.
@ -60,7 +59,7 @@ func (a *AWSEnvironmentManager) CreateOrUpdate(
}
func isAWSEnvironment(request dto.ExecutionEnvironmentRequest) bool {
for _, function := range strings.Fields(config.Config.AWS.Functions) {
for _, function := range config.Config.AWS.Functions {
if request.Image == function {
return true
}

View File

@ -17,7 +17,7 @@ func TestAWSEnvironmentManager_CreateOrUpdate(t *testing.T) {
uniqueImage := "java11Exec"
t.Run("can create default Java environment", func(t *testing.T) {
config.Config.AWS.Functions = uniqueImage
config.Config.AWS.Functions = []string{uniqueImage}
_, err := m.CreateOrUpdate(tests.AnotherEnvironmentIDAsInteger, dto.ExecutionEnvironmentRequest{Image: uniqueImage})
assert.NoError(t, err)
})