63 lines
2.0 KiB
Go
63 lines
2.0 KiB
Go
// Package config provides utilities for reading and storing configuration
|
|
// values.
|
|
package config
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
// A Config holds all of the configuration values needed for the program.
|
|
type Config struct {
|
|
CloudstackApiKey string
|
|
CloudstackSecretKey string
|
|
CloudstackApiBaseUrl string
|
|
CloudstackZoneName string
|
|
CloudstackServiceOfferingName string
|
|
CloudstackKeypairName string
|
|
UploadDirectory string
|
|
UploadBaseUrl string
|
|
MirrorHost string
|
|
EmailServer string
|
|
EmailSender string
|
|
EmailSenderName string
|
|
EmailRecipient string
|
|
EmailReplyTo string
|
|
}
|
|
|
|
// New returns a Config filled with values read from environment variables.
|
|
// It panics if a required environment variable is empty or not set.
|
|
func New() *Config {
|
|
cfg := &Config{
|
|
CloudstackApiKey: os.Getenv("CLOUDSTACK_API_KEY"),
|
|
CloudstackSecretKey: os.Getenv("CLOUDSTACK_SECRET_KEY"),
|
|
UploadDirectory: os.Getenv("UPLOAD_DIRECTORY"),
|
|
UploadBaseUrl: os.Getenv("UPLOAD_BASE_URL"),
|
|
}
|
|
if cfg.CloudstackApiKey == "" {
|
|
panic("CLOUDSTACK_API_KEY is empty or not set")
|
|
}
|
|
if cfg.CloudstackSecretKey == "" {
|
|
panic("CLOUDSTACK_SECRET_KEY is empty or not set")
|
|
}
|
|
if cfg.UploadDirectory == "" {
|
|
panic("UPLOAD_DIRECTORY is empty or not set")
|
|
}
|
|
if cfg.UploadBaseUrl == "" {
|
|
panic("UPLOAD_BASE_URL is empty or not set")
|
|
}
|
|
|
|
// These should never change
|
|
cfg.CloudstackApiBaseUrl = "https://cloud.csclub.uwaterloo.ca/client/api"
|
|
cfg.CloudstackZoneName = "Zone1"
|
|
cfg.CloudstackServiceOfferingName = "Small Instance"
|
|
cfg.CloudstackKeypairName = "management-keypair"
|
|
cfg.MirrorHost = "mirror.csclub.uwaterloo.ca"
|
|
cfg.EmailServer = "mail.csclub.uwaterloo.ca:25"
|
|
cfg.EmailSender = "cloudbuild@csclub.uwaterloo.ca"
|
|
cfg.EmailSenderName = "cloudbuild"
|
|
// TODO: change recipient to syscom
|
|
cfg.EmailRecipient = "merenber@csclub.uwaterloo.ca"
|
|
cfg.EmailReplyTo = "no-reply@csclub.uwaterloo.ca"
|
|
return cfg
|
|
}
|