From 7bb676887fa62d7a5056f7f9ab4f4f8af88dcc4e Mon Sep 17 00:00:00 2001 From: Bennett Wetters Date: Sat, 13 Jan 2024 23:16:10 +0100 Subject: [PATCH] Add type definitions for new config format --- config/types.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 config/types.go diff --git a/config/types.go b/config/types.go new file mode 100644 index 0000000..a6a3728 --- /dev/null +++ b/config/types.go @@ -0,0 +1,41 @@ +package config + +import ( + "gitlab.hamburg.ccc.de/ccchh/spaceapid/types" +) + +type HTTPBACredentialID string + +type HTTPBACredentials map[HTTPBACredentialID]HTTPBACredential + +type HTTPBACredential struct { + Username string `json:"username"` + Password string `json:"password"` +} + +type EnvironmentSensorConfig struct { + SensorData types.EnvironmentSensor `json:"sensor_data"` + AllowedCredentials []HTTPBACredentialID `json:"allowed_credentials"` +} + +type DynamicStateConfig struct { + Sensors struct { + Temperature []EnvironmentSensorConfig `json:"temperature"` + Humidity []EnvironmentSensorConfig `json:"humidity"` + } `json:"sensors"` + State struct { + Open struct { + AllowedCredentials []HTTPBACredentialID `json:"allowed_credentials"` + } `json:"open"` + } `json:"state"` +} + +// SpaceapidConfig is the representation of the config.json file +type SpaceapidConfig struct { + // A list of username/password pairs for BasicAuth endpoints + Credentials HTTPBACredentials `json:"credentials"` + // The dynamic part of the spaceapi JSON + Dynamic DynamicStateConfig `json:"dynamic"` + // The static part of the spaceapi JSON + Response types.SpaceAPIResponseV14 `json:"static"` +}