Specify AWS Functions as list
to conform with the yaml standard of list definition.
This commit is contained in:

committed by
Sebastian Serth

parent
d80761a973
commit
0f8a1fa25a
@ -48,8 +48,11 @@ aws:
|
|||||||
enabled: false
|
enabled: false
|
||||||
# The endpoint of the WebSocket API
|
# The endpoint of the WebSocket API
|
||||||
endpoint: wss://abcdef1234.execute-api.eu-central-1.amazonaws.com/production
|
endpoint: wss://abcdef1234.execute-api.eu-central-1.amazonaws.com/production
|
||||||
# Currently, only static AWS environments are supported. You can list them here separated by spaces.
|
# Currently, only static AWS environments are supported.
|
||||||
functions: "java11Exec go118Exec"
|
# For setting this via environment variables you have to use a string separated by spaces, like: POSEIDON_AWS_FUNCTIONS="java11Exec go118Exec".
|
||||||
|
functions:
|
||||||
|
- java11Exec
|
||||||
|
- go118Exec
|
||||||
|
|
||||||
# Configuration of the logger
|
# Configuration of the logger
|
||||||
logger:
|
logger:
|
||||||
|
@ -47,7 +47,7 @@ var (
|
|||||||
AWS: AWS{
|
AWS: AWS{
|
||||||
Enabled: false,
|
Enabled: false,
|
||||||
Endpoint: "",
|
Endpoint: "",
|
||||||
Functions: "",
|
Functions: []string{},
|
||||||
},
|
},
|
||||||
Logger: logger{
|
Logger: logger{
|
||||||
Level: "INFO",
|
Level: "INFO",
|
||||||
@ -105,7 +105,7 @@ func (n *Nomad) URL() *url.URL {
|
|||||||
type AWS struct {
|
type AWS struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
Endpoint string
|
Endpoint string
|
||||||
Functions string
|
Functions []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// TLS configures TLS on a connection.
|
// TLS configures TLS on a connection.
|
||||||
@ -235,6 +235,12 @@ func loadValue(prefix string, value reflect.Value, logEntry *logrus.Entry) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
value.SetBool(boolean)
|
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:
|
default:
|
||||||
// ignore this field
|
// ignore this field
|
||||||
logEntry.WithField("type", value.Type().Name()).
|
logEntry.WithField("type", value.Type().Name()).
|
||||||
|
@ -16,6 +16,7 @@ var (
|
|||||||
getServerPort = func(c *configuration) interface{} { return c.Server.Port }
|
getServerPort = func(c *configuration) interface{} { return c.Server.Port }
|
||||||
getNomadToken = func(c *configuration) interface{} { return c.Nomad.Token }
|
getNomadToken = func(c *configuration) interface{} { return c.Nomad.Token }
|
||||||
getNomadTLSActive = func(c *configuration) interface{} { return c.Nomad.TLS.Active }
|
getNomadTLSActive = func(c *configuration) interface{} { return c.Nomad.TLS.Active }
|
||||||
|
getAWSFunctions = func(c *configuration) interface{} { return c.AWS.Functions }
|
||||||
)
|
)
|
||||||
|
|
||||||
func newTestConfiguration() *configuration {
|
func newTestConfiguration() *configuration {
|
||||||
@ -91,6 +92,7 @@ func TestReadEnvironmentVariables(t *testing.T) {
|
|||||||
{"NOMAD_TOKEN", "ACCESS", "ACCESS", getNomadToken},
|
{"NOMAD_TOKEN", "ACCESS", "ACCESS", getNomadToken},
|
||||||
{"NOMAD_TLS_ACTIVE", "true", true, getNomadTLSActive},
|
{"NOMAD_TLS_ACTIVE", "true", true, getNomadTLSActive},
|
||||||
{"NOMAD_TLS_ACTIVE", "hello", false, getNomadTLSActive},
|
{"NOMAD_TLS_ACTIVE", "hello", false, getNomadTLSActive},
|
||||||
|
{"AWS_FUNCTIONS", "java11Exec go118Exec", []string{"java11Exec", "go118Exec"}, getAWSFunctions},
|
||||||
}
|
}
|
||||||
prefix := "POSEIDON_TEST"
|
prefix := "POSEIDON_TEST"
|
||||||
for _, testCase := range environmentTests {
|
for _, testCase := range environmentTests {
|
||||||
@ -136,6 +138,8 @@ func TestReadYamlConfigFile(t *testing.T) {
|
|||||||
{[]byte("nomad:\n tls:\n active: true\n"), true, getNomadTLSActive},
|
{[]byte("nomad:\n tls:\n active: true\n"), true, getNomadTLSActive},
|
||||||
{[]byte(""), false, getNomadTLSActive},
|
{[]byte(""), false, getNomadTLSActive},
|
||||||
{[]byte("nomad:\n token:\n"), "SECRET", getNomadToken},
|
{[]byte("nomad:\n token:\n"), "SECRET", getNomadToken},
|
||||||
|
{[]byte("aws:\n functions:\n - java11Exec\n - go118Exec\n"),
|
||||||
|
[]string{"java11Exec", "go118Exec"}, getAWSFunctions},
|
||||||
}
|
}
|
||||||
for _, testCase := range yamlTests {
|
for _, testCase := range yamlTests {
|
||||||
config := newTestConfiguration()
|
config := newTestConfiguration()
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"github.com/openHPI/poseidon/internal/config"
|
"github.com/openHPI/poseidon/internal/config"
|
||||||
"github.com/openHPI/poseidon/internal/runner"
|
"github.com/openHPI/poseidon/internal/runner"
|
||||||
"github.com/openHPI/poseidon/pkg/dto"
|
"github.com/openHPI/poseidon/pkg/dto"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AWSEnvironmentManager contains no functionality at the moment.
|
// AWSEnvironmentManager contains no functionality at the moment.
|
||||||
@ -60,7 +59,7 @@ func (a *AWSEnvironmentManager) CreateOrUpdate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isAWSEnvironment(request dto.ExecutionEnvironmentRequest) bool {
|
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 {
|
if request.Image == function {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ func TestAWSEnvironmentManager_CreateOrUpdate(t *testing.T) {
|
|||||||
uniqueImage := "java11Exec"
|
uniqueImage := "java11Exec"
|
||||||
|
|
||||||
t.Run("can create default Java environment", func(t *testing.T) {
|
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})
|
_, err := m.CreateOrUpdate(tests.AnotherEnvironmentIDAsInteger, dto.ExecutionEnvironmentRequest{Image: uniqueImage})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -65,7 +64,7 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initAWS() {
|
func initAWS() {
|
||||||
for i, function := range strings.Fields(config.Config.AWS.Functions) {
|
for i, function := range config.Config.AWS.Functions {
|
||||||
id := dto.EnvironmentID(tests.DefaultEnvironmentIDAsInteger + i + 1)
|
id := dto.EnvironmentID(tests.DefaultEnvironmentIDAsInteger + i + 1)
|
||||||
path := helpers.BuildURL(api.BasePath, api.EnvironmentsPath, id.ToString())
|
path := helpers.BuildURL(api.BasePath, api.EnvironmentsPath, id.ToString())
|
||||||
request := dto.ExecutionEnvironmentRequest{Image: function}
|
request := dto.ExecutionEnvironmentRequest{Image: function}
|
||||||
|
@ -323,7 +323,7 @@ func createEnvironment(t *testing.T, environmentID string, aws bool) {
|
|||||||
ExposedPorts: nil,
|
ExposedPorts: nil,
|
||||||
}
|
}
|
||||||
if aws {
|
if aws {
|
||||||
functions := strings.Fields(config.Config.AWS.Functions)
|
functions := config.Config.AWS.Functions
|
||||||
require.NotZero(t, len(functions))
|
require.NotZero(t, len(functions))
|
||||||
request.Image = functions[0]
|
request.Image = functions[0]
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user