Commit 49ed9f4e authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Merge branch 'config' into dev

Closes #5
parents 640d6075 78321492
Pipeline #57030 failed with stages
......@@ -8,7 +8,10 @@ import (
"log"
"net/http"
"regexp"
"strings"
"time"
"gopkg.in/yaml.v2"
)
type (
......@@ -17,84 +20,84 @@ type (
// Service for which we do deployments
Service struct {
Name string `json:"name"`
Command string `json:"command"`
Description string `json:"description"`
Name string `json:"name" yaml:"name"`
Command string `json:"command" yaml:"command"`
Description string `json:"description" yaml:"description"`
}
// RabbitMQConfig is used for the amqp source
RabbitMQConfig struct {
Exchanges []string `json:"exchanges"`
Vhost string `json:"vhost"`
Exchanges []string `json:"exchanges" yaml:"exchanges"`
Vhost string `json:"vhost" yaml:"vhost"`
}
fetchedConfig struct {
RabbitMQConfig RabbitMQConfig `json:"rabbitmq_config"`
Site string `json:"site"`
RabbitMQConfig RabbitMQConfig `json:"rabbitmq_config" yaml:"rabbitmq_config"`
Site string `json:"site" yaml:"site"`
}
// The DebugConfig sets the debuging levels for components of the client.
DebugConfig struct {
// Sequential causes the execution of only one deployment at a time for debugging purposes
Sequential bool `json:"sequential_execution"`
Scripts bool `json:"scripts"`
Backend bool `json:"backend"`
Sequential bool `json:"sequential_execution" yaml:"sequential_execution"`
Scripts bool `json:"scripts" yaml:"scripts"`
Backend bool `json:"backend" yaml:"backend"`
}
// Config is the structure of our config file
Config struct {
// The Hostname of the feudal backends host
Hostname string `json:"feudal_backend_host"`
Hostname string `json:"feudal_backend_host" yaml:"feudal_backend_host"`
// The Username of this client, registered at the backend.
Username string `json:"username"`
Username string `json:"username" yaml:"username"`
// The Password of this client, registered at the backend.
Password string `json:"password"`
Password string `json:"password" yaml:"password"`
// Services maps an (arbitrary) service identifier to service structs
// the service identifiers are referenced in GroupToServiceIDs and EntitlementToServiceIDs
Services map[ServiceID]Service `json:"services"`
Services map[ServiceID]Service `json:"services" yaml:"services"`
// GroupToServiceIDs determines which services are provided for users of the
// group
// maps a group name to service identifiers of the services
// services are declared in Config.Services
GroupToServiceIDs map[string][]ServiceID `json:"group_to_service_ids"`
GroupToServiceIDs map[string][]ServiceID `json:"group_to_service_ids" yaml:"group_to_service_ids"`
// EntitlementToServiceIDs determines which services are provided for users of the
// entitlement
// maps an entitlement to service identifiers of the services
// services are declared in Config.Services
EntitlementToServiceIDs map[string][]ServiceID `json:"entitlement_to_service_ids"`
EntitlementToServiceIDs map[string][]ServiceID `json:"entitlement_to_service_ids" yaml:"entitlement_to_service_ids"`
// FetchIntervalString gets parsed by time.ParseDuration
FetchIntervalString string `json:"fetch_interval,omitempty"`
FetchIntervalString string `json:"fetch_interval,omitempty" yaml:"fetch_interval,omitempty"`
// ReconnectTimeout gets parsed by time.ParseDuration
ReconnectTimeoutString string `json:"reconnect_timeout,omitempty"`
ReconnectTimeoutString string `json:"reconnect_timeout,omitempty" yaml:"reconnect_timeout,omitempty"`
// Debug flags control the log levels of the client.
Debug DebugConfig `json:"debug,omitempty"`
Debug DebugConfig `json:"debug,omitempty" yaml:"debug,omitempty"`
// After the duration of FetchInterval the client will fetch updates using the REST
// interface.
FetchInterval time.Duration `json:"-"`
FetchInterval time.Duration `json:"-" yaml:"-"`
// We reconnect to RabbitMQ after ReconnectTimeout.
ReconnectTimeout time.Duration `json:"-"`
ReconnectTimeout time.Duration `json:"-" yaml:"-"`
RabbitMQConfig RabbitMQConfig `json:"-"`
RabbitMQConfig RabbitMQConfig `json:"-" yaml:"-"`
// The Site is the name of the site of this client. It is fetched from the backend.
Site string `json:"-"`
Site string `json:"-" yaml:"-"`
}
// strippedConfig is sent to the backend on startup
strippedConfig struct {
Services map[ServiceID]Service `json:"services"`
GroupToServiceIDs map[string][]ServiceID `json:"group_to_service_ids"`
EntitlementToServiceIDs map[string][]ServiceID `json:"entitlement_to_service_ids"`
Services map[ServiceID]Service `json:"services" yaml:"services"`
GroupToServiceIDs map[string][]ServiceID `json:"group_to_service_ids" yaml:"group_to_service_ids"`
EntitlementToServiceIDs map[string][]ServiceID `json:"entitlement_to_service_ids" yaml:"entitlement_to_service_ids"`
}
)
......@@ -274,8 +277,21 @@ func ReadConfig(configFile string) (conf *Config, err error) {
}
conf = new(Config)
err = json.Unmarshal(configBytes, conf)
if err != nil {
if strings.HasSuffix(configFile, ".yaml") {
err = yaml.Unmarshal(configBytes, conf)
if err != nil {
err = fmt.Errorf("Error decoding yaml: %s", err)
return
}
} else if strings.HasSuffix(configFile, ".json") {
err = json.Unmarshal(configBytes, conf)
if err != nil {
err = fmt.Errorf("Error decoding json: %s", err)
return
}
} else {
err = fmt.Errorf("Incompatible config format, supported are: YAML or JSON")
return
}
......
# the host
feudal_backend_host: "<hostname>"
username: '<username registerred at the portal>'
password: '<password registerred at the portal>'
services:
'<local identifier>':
name: <service name>
description: This is the foo service
command: ./fooService
group_to_service_ids:
'<group name>':
- '<local identifier>'
entitlement_to_service_ids:
'<entitlement string>':
- '<local identifier>'
......@@ -12,4 +12,7 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.1.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/yaml.v2 v2.2.5
)
go 1.13
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment