-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_onc_profile.go
48 lines (38 loc) · 1.03 KB
/
create_onc_profile.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
package client
import (
"fmt"
"github.com/dpb587/go-onc/onc"
"github.com/dpb587/go-openvpn/ovpn"
ovpnonc "github.com/dpb587/go-openvpn/ovpn/onc"
"github.com/pkg/errors"
)
type CreateONCProfileOptions struct {
SkipAuthRetry bool
Name string
}
func (s Service) CreateONCProfile(opts CreateONCProfileOptions) (*onc.ONC, error) {
profile, err := s.CreateProfile(CreateProfileOptions{
SkipAuthRetry: opts.SkipAuthRetry,
})
if err != nil {
return nil, err
}
parsedProfile, err := ovpn.Parse([]byte(profile.StaticConfig()))
if err != nil {
return nil, errors.Wrap(err, "parsing profile")
}
oncEncoded, err := ovpnonc.Encode(parsedProfile)
if err != nil {
return nil, errors.Wrap(err, "building ONC")
}
name := opts.Name
if name == "" {
name = s.runtime.GetEnvironmentName()
if s.name != "openvpn" {
name = fmt.Sprintf("%s-%s", name, s.name)
}
}
oncEncoded.NetworkConfigurations[0].Name = name
oncEncoded.NetworkConfigurations[0].VPN.OpenVPN.UserAuthenticationType = "None"
return oncEncoded, nil
}