157 lines
5.1 KiB
Go
157 lines
5.1 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"os"
|
|
|
|
"github.com/nyaruka/phonenumbers"
|
|
)
|
|
|
|
var (
|
|
Bind string
|
|
ClientID string
|
|
ClientSecret string
|
|
DomainRMO string
|
|
DomainNidus string
|
|
DomainTegola string
|
|
Environment string
|
|
FilesDirectoryLogo string
|
|
FilesDirectoryPublic string
|
|
FilesDirectoryUser string
|
|
FieldseekerSchemaDirectory string
|
|
ForwardEmailAPIToken string
|
|
ForwardEmailReportAddress string
|
|
ForwardEmailReportPassword string
|
|
ForwardEmailReportUsername string
|
|
MapboxToken string
|
|
PGDSN string
|
|
RMOPhoneNumber phonenumbers.PhoneNumber
|
|
TwilioAuthToken string
|
|
TwilioAccountSID string
|
|
TwilioMessagingServiceSID string
|
|
)
|
|
|
|
func IsProductionEnvironment() bool {
|
|
return Environment == "PRODUCTION"
|
|
}
|
|
|
|
func makeURL(domain, path string, args ...string) string {
|
|
to_add := make([]any, 0)
|
|
for _, a := range args {
|
|
to_add = append(to_add, url.QueryEscape(a))
|
|
}
|
|
pattern := "https://" + domain + path
|
|
return fmt.Sprintf(pattern, to_add...)
|
|
}
|
|
|
|
func MakeURLNidus(path string, args ...string) string {
|
|
return makeURL(DomainNidus, path, args...)
|
|
}
|
|
func MakeURLReport(path string, args ...string) string {
|
|
return makeURL(DomainRMO, path, args...)
|
|
}
|
|
func MakeURLTegola(path string, args ...string) string {
|
|
return makeURL(DomainTegola, path, args...)
|
|
}
|
|
|
|
func Parse() (err error) {
|
|
Bind = os.Getenv("BIND")
|
|
if Bind == "" {
|
|
Bind = ":9001"
|
|
}
|
|
ClientID = os.Getenv("ARCGIS_CLIENT_ID")
|
|
if ClientID == "" {
|
|
return fmt.Errorf("You must specify a non-empty ARCGIS_CLIENT_ID")
|
|
}
|
|
ClientSecret = os.Getenv("ARCGIS_CLIENT_SECRET")
|
|
if ClientSecret == "" {
|
|
return fmt.Errorf("You must specify a non-empty ARCGIS_CLIENT_SECRET")
|
|
}
|
|
DomainNidus = os.Getenv("DOMAIN_NIDUS")
|
|
if DomainNidus == "" {
|
|
return fmt.Errorf("You must specify a non-empty DOMAIN_NIDUS")
|
|
}
|
|
DomainRMO = os.Getenv("DOMAIN_RMO")
|
|
if DomainRMO == "" {
|
|
return fmt.Errorf("You must specify a non-empty DOMAIN_RMO")
|
|
}
|
|
DomainTegola = os.Getenv("DOMAIN_TEGOLA")
|
|
if DomainTegola == "" {
|
|
return fmt.Errorf("You must specify a non-empty DOMAIN_TEGOLA")
|
|
}
|
|
Environment = os.Getenv("ENVIRONMENT")
|
|
if Environment == "" {
|
|
return fmt.Errorf("You must specify a non-empty ENVIRONMENT")
|
|
}
|
|
if !(Environment == "PRODUCTION" || Environment == "DEVELOPMENT") {
|
|
return fmt.Errorf("ENVIRONMENT should be either DEVELOPMENT or PRODUCTION")
|
|
}
|
|
FieldseekerSchemaDirectory = os.Getenv("FIELDSEEKER_SCHEMA_DIRECTORY")
|
|
if FieldseekerSchemaDirectory == "" {
|
|
return fmt.Errorf("You must specify a non-empty FIELDSEEKER_SCHEMA_DIRECTORY")
|
|
}
|
|
FilesDirectoryLogo = os.Getenv("FILES_DIRECTORY_LOGO")
|
|
if FilesDirectoryLogo == "" {
|
|
return fmt.Errorf("You must specify a non-empty FILES_DIRECTORY_LOGO")
|
|
}
|
|
FilesDirectoryPublic = os.Getenv("FILES_DIRECTORY_PUBLIC")
|
|
if FilesDirectoryPublic == "" {
|
|
return fmt.Errorf("You must specify a non-empty FILES_DIRECTORY_PUBLIC")
|
|
}
|
|
FilesDirectoryUser = os.Getenv("FILES_DIRECTORY_USER")
|
|
if FilesDirectoryUser == "" {
|
|
return fmt.Errorf("You must specify a non-empty FILES_DIRECTORY_USER")
|
|
}
|
|
ForwardEmailReportAddress = os.Getenv("FORWARDEMAIL_REPORT_ADDRESS")
|
|
if ForwardEmailReportAddress == "" {
|
|
return fmt.Errorf("You must specify a non-empty FORWARDEMAIL_REPORT_ADDRESS")
|
|
}
|
|
ForwardEmailAPIToken = os.Getenv("FORWARDEMAIL_API_TOKEN")
|
|
if ForwardEmailAPIToken == "" {
|
|
return fmt.Errorf("You must specify a non-empty FORWARDEMAIL_API_TOKEN")
|
|
}
|
|
ForwardEmailReportUsername = os.Getenv("FORWARDEMAIL_REPORT_USERNAME")
|
|
if ForwardEmailReportUsername == "" {
|
|
return fmt.Errorf("You must specify a non-empty FORWARDEMAIL_REPORT_USERNAME")
|
|
}
|
|
ForwardEmailReportPassword = os.Getenv("FORWARDEMAIL_REPORT_PASSWORD")
|
|
if ForwardEmailReportPassword == "" {
|
|
return fmt.Errorf("You must specify a non-empty FORWARDEMAIL_REPORT_PASSWORD")
|
|
}
|
|
MapboxToken = os.Getenv("MAPBOX_TOKEN")
|
|
if MapboxToken == "" {
|
|
return fmt.Errorf("You must specify a non-empty MAPBOX_TOKEN")
|
|
}
|
|
PGDSN = os.Getenv("POSTGRES_DSN")
|
|
if PGDSN == "" {
|
|
return fmt.Errorf("You must specify a non-empty POSTGRES_DSN")
|
|
}
|
|
rmo_phone_number := os.Getenv("RMO_PHONE_NUMBER")
|
|
if rmo_phone_number == "" {
|
|
return fmt.Errorf("You must specify a non-empty RMO_PHONE_NUMBER")
|
|
}
|
|
p, err := phonenumbers.Parse(rmo_phone_number, "US")
|
|
if err != nil {
|
|
return fmt.Errorf("Failed to parse '%s' as a valid phone number: %w", rmo_phone_number, err)
|
|
}
|
|
RMOPhoneNumber = *p
|
|
|
|
TwilioAccountSID = os.Getenv("TWILIO_ACCOUNT_SID")
|
|
if TwilioAccountSID == "" {
|
|
return fmt.Errorf("You must specify a non-empty TWILIO_ACCOUNT_SID")
|
|
}
|
|
TwilioAuthToken = os.Getenv("TWILIO_AUTH_TOKEN")
|
|
if TwilioAuthToken == "" {
|
|
return fmt.Errorf("You must specify a non-empty TWILIO_AUTH_TOKEN")
|
|
}
|
|
TwilioMessagingServiceSID = os.Getenv("TWILIO_MESSAGING_SERVICE_SID")
|
|
if TwilioMessagingServiceSID == "" {
|
|
return fmt.Errorf("You must specify a non-empty TWILIO_MESSAGING_SERVICE_SID")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func ArcGISOauthRedirectURL() string {
|
|
return MakeURLNidus("/arcgis/oauth/callback")
|
|
}
|