diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2020-01-27 23:29:05 -0600 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2020-08-20 20:27:40 +0200 |
commit | efdeba8e994669ccd21c50d2b7491905b47a217e (patch) | |
tree | 3decd5d0f4364e0b9bcfcf4e7506df4359c8210b /pkg/vpn/bonafide/bonafide.go | |
parent | c236dfcfdd60ea700e5f50ed2568398cd161dd4c (diff) |
[test] sip integration test
Diffstat (limited to 'pkg/vpn/bonafide/bonafide.go')
-rw-r--r-- | pkg/vpn/bonafide/bonafide.go | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go index 16a900d..1bc6072 100644 --- a/pkg/vpn/bonafide/bonafide.go +++ b/pkg/vpn/bonafide/bonafide.go @@ -30,23 +30,29 @@ import ( ) const ( - certAPI = config.APIURL + "1/cert" - certAPI3 = config.APIURL + "3/cert" - authAPI = config.APIURL + "3/auth" secondsPerHour = 60 * 60 retryFetchJSONSeconds = 15 ) -// Bonafide exposes all the methods needed to communicate with the LEAP server. +const ( + certPathv1 = "1/cert" + certPathv3 = "3/cert" + authPathv3 = "3/auth" + + certAPI = config.APIURL + certPathv1 + certAPI3 = config.APIURL + certPathv3 + authAPI = config.APIURL + authPathv3 +) + type Bonafide struct { client httpClient eip *eipService tzOffsetHours int auth Authentication credentials *Credentials + apiURL string } -// A Gateway is each one of the remotes we can pass to OpenVPN. It contains a description of all the fields that the eip-service advertises. type Gateway struct { Host string IPAddress string @@ -106,7 +112,33 @@ func (b *Bonafide) SetCredentials(username, password string) { b.credentials = &Credentials{username, password} } +func (b *Bonafide) GetURL(object string) (string, error) { + if b.apiURL == "" { + switch object { + case "cert": + return certAPI, nil + case "certv3": + return certAPI3, nil + case "auth": + return authAPI, nil + } + } else { + switch object { + case "cert": + return b.apiURL + certPathv1, nil + case "certv3": + return b.apiURL + certPathv3, nil + case "auth": + return b.apiURL + authPathv3, nil + } + } + return "", fmt.Errorf("ERROR: unknown object for api url") +} + func (b *Bonafide) GetPemCertificate() ([]byte, error) { + if b.auth == nil { + log.Fatal("ERROR: bonafide did not initialize auth") + } cert, err := b.auth.GetPemCertificate() return cert, err } |