-
Notifications
You must be signed in to change notification settings - Fork 1
/
configFile.go
80 lines (72 loc) · 1.94 KB
/
configFile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"errors"
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"strings"
)
/* Interface with the yaml configuration file */
type Config struct {
Username string `yaml:"username,omitempty"`
Password string `yaml:"password,omitempty"`
LoginBaseURL string `yaml:"unsolicited_login_baseurl,omitempty"`
UseLocalStorage bool `yaml:"use_local_storage,omitempty"`
ProviderId string `yaml:"provider_id,omitempty"`
Shire string `yaml:"shire,omitempty"`
}
func retrieveValues(file string) (Config, error) {
c := Config{}
// Read it
data, err := ioutil.ReadFile(file)
if err != nil {
return c, err
}
// Unmarshall it
err = yaml.Unmarshal(data, &c)
if err != nil {
return c, err
}
// Sanity check
missing := make([]string, 0, 0)
switch {
case c.Username == "":
missing = append(missing, "username")
fallthrough
case c.Password == "":
missing = append(missing, "password")
fallthrough
case c.LoginBaseURL == "":
missing = append(missing, "unsolicited_login_baseurl")
fallthrough
case c.ProviderId == "":
missing = append(missing, "provider_id")
fallthrough
case c.Shire == "":
missing = append(missing, "shire")
}
if len(missing) > 0 {
err = errors.New("Missing configuration entries: " + strings.Join(missing, ", ") + ".")
return c, err
}
return c, nil
}
func printSampleConfig() {
sampleConf :=
`---
### check-shib3idp-login configuration ###
# Login information
username: "some_user"
password: "some_password"
# Base URL for unsolicited login
unsolicited_login_baseurl: "https://idp.example.com/idp/profile/SAML2/Unsolicited/SSO"
# Use HTML5 Local storage as ClientStoage ("idp.storage.htmlLocalStorage" in idp.properties).
# Defaults to false (use cookies).
#use_local_storage: true
# Entity ID of a service provider to login
provider_id: "https://sp.example.com"
# ACS url of a service provider to login
shire: "https://sp.example.com/Shibboleth.sso/SAML2/POST"
`
fmt.Println(sampleConf)
}