Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Adressed #228 (Storing resume filename in registration object) and #283 (More descriptive configloader error messages) #321

Open
wants to merge 5 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions common/configloader/configloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ package configloader
import (
"encoding/json"
"errors"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"io/ioutil"
"net/http"
"net/url"
"os"
)

var ErrNotSet = errors.New("The value for the given key was not set")
var ErrDecodeFailed = errors.New("The value for the given key could not be decoded")
var ErrLoadFailed = errors.New("Unable to load config")
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
)

/*
Used to load a key value configuration
Expand All @@ -33,24 +30,32 @@ func Load(config_path string) (*ConfigLoader, error) {
uri, err := url.Parse(config_path)

if err != nil {
return nil, ErrLoadFailed
return nil, errors.New("Unable to parse '" + config_path + "' into URI structure")
}

var config_contents []byte

switch uri.Scheme {
case "s3":
config_contents, err = loadFromS3(config_path)

if err != nil {
return nil, errors.New("Unable to load '" + config_path + "' as s3")
}
case "file":
config_contents, err = loadFromFile(config_path)

if err != nil {
return nil, errors.New("Unable to load '" + config_path + "' as file")
}
case "https":
config_contents, err = loadFromHttps(config_path)
default:
return nil, ErrLoadFailed
}

if err != nil {
return nil, ErrLoadFailed
if err != nil {
return nil, errors.New("Unable to load '" + config_path + "' as https")
}
default:
return nil, errors.New("URI scheme of '" + config_path + "' unsupported. Must be s3, file, or https")
}

loader := ConfigLoader{
Expand All @@ -60,7 +65,7 @@ func Load(config_path string) (*ConfigLoader, error) {
err = json.Unmarshal(config_contents, &loader.parsedConfig)

if err != nil {
return nil, ErrLoadFailed
return nil, errors.New("Unable to load contents of '" + config_path + "' into json")
}

return &loader, nil
Expand All @@ -80,13 +85,13 @@ func (loader *ConfigLoader) Get(key string) (string, error) {
raw_value, exists := loader.parsedConfig[key]

if !exists {
return "", ErrNotSet
return "", errors.New("Value for key '" + key + "' not set")
}

err := json.Unmarshal(*raw_value, &value)

if err != nil {
return "", ErrDecodeFailed
return "", errors.New("Value for key '" + key + "' couldn't be decoded")
}

return value, nil
Expand All @@ -106,7 +111,7 @@ func (loader *ConfigLoader) ParseInto(key string, out interface{}) error {
raw_value, exists := loader.parsedConfig[key]

if !exists {
return ErrNotSet
return errors.New("Value for key '" + key + "' not set")
}

return json.Unmarshal(*raw_value, out)
Expand Down
9 changes: 8 additions & 1 deletion config/dev_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
"gender",
"interests",
"isBeginner",
"priorAttendance"
"priorAttendance",
"resumeName"
],

"REGISTRATION_DEFINITION": {
Expand Down Expand Up @@ -214,6 +215,12 @@
"validations": "",
"fields": []
},
{
"name": "resumeName",
"type": "string",
"validations": "required",
"fields": []
},
{
"name": "isBeginner",
"type": "boolean",
Expand Down