Skip to content

Commit e1c7c13

Browse files
authored
Merge pull request #68 from OpenVPN/feature/ipsec-connectors
Add support for ipsec connectors
2 parents af649c6 + 0f8ba72 commit e1c7c13

File tree

4 files changed

+85
-209
lines changed

4 files changed

+85
-209
lines changed

cloudconnexa/network_connectors.go

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,65 @@ import (
1111

1212
// NetworkConnector represents a network connector configuration.
1313
type NetworkConnector struct {
14-
ID string `json:"id,omitempty"`
15-
Name string `json:"name"`
16-
Description string `json:"description,omitempty"`
17-
NetworkItemID string `json:"networkItemId"`
18-
NetworkItemType string `json:"networkItemType"`
19-
VpnRegionID string `json:"vpnRegionId"`
20-
IPv4Address string `json:"ipV4Address"`
21-
IPv6Address string `json:"ipV6Address"`
22-
Profile string `json:"profile"`
23-
ConnectionStatus string `json:"connectionStatus"`
14+
ID string `json:"id,omitempty"`
15+
Name string `json:"name"`
16+
Description string `json:"description,omitempty"`
17+
NetworkItemID string `json:"networkItemId"`
18+
NetworkItemType string `json:"networkItemType"`
19+
VpnRegionID string `json:"vpnRegionId"`
20+
IPv4Address string `json:"ipV4Address"`
21+
IPv6Address string `json:"ipV6Address"`
22+
Profile string `json:"profile"`
23+
ConnectionStatus string `json:"connectionStatus"`
24+
IPSecConfig *IPSecConfig `json:"IPSecConfig,omitempty"`
25+
TunnelingProtocol string `json:"tunnelingProtocol"`
26+
}
27+
28+
// IPSecConfig represents a network connector ipsec configuration.
29+
type IPSecConfig struct {
30+
Platform string `json:"platform,omitempty"`
31+
AuthenticationType string `json:"authenticationType,omitempty"`
32+
RemoteSitePublicIP string `json:"remoteSitePublicIp,omitempty"`
33+
PreSharedKey string `json:"preSharedKey,omitempty"`
34+
CaCertificate string `json:"caCertificate,omitempty"`
35+
PeerCertificate string `json:"peerCertificate,omitempty"`
36+
RemoteGatewayCertificate string `json:"remoteGatewayCertificate,omitempty"`
37+
PeerCertificatePrivateKey string `json:"peerCertificatePrivateKey,omitempty"`
38+
PeerCertificateKeyPassphrase string `json:"peerCertificateKeyPassphrase,omitempty"`
39+
IkeProtocol IkeProtocol `json:"ikeProtocol,omitempty"`
40+
Hostname string `json:"hostname,omitempty"`
41+
Domain string `json:"domain,omitempty"`
42+
}
43+
44+
// IkeProtocol represents an ike protocol configuration for ipsec config.
45+
type IkeProtocol struct {
46+
ProtocolVersion string `json:"protocolVersion,omitempty"`
47+
Phase1 Phase `json:"phase1,omitempty"`
48+
Phase2 Phase `json:"phase2,omitempty"`
49+
Rekey Rekey `json:"rekey,omitempty"`
50+
DeadPeerDetection DeadPeerDetection `json:"deadPeerDetection,omitempty"`
51+
StartupAction string `json:"startupAction,omitempty"`
52+
}
53+
54+
// Phase represents a phase configuration used in ipsec.
55+
type Phase struct {
56+
EncryptionAlgorithms []string `json:"encryptionAlgorithms,omitempty"`
57+
IntegrityAlgorithms []string `json:"integrityAlgorithms,omitempty"`
58+
DiffieHellmanGroups []string `json:"diffieHellmanGroups,omitempty"`
59+
LifetimeSec int `json:"lifetimeSec"`
60+
}
61+
62+
// Rekey represents a rekey configuration used in ipsec.
63+
type Rekey struct {
64+
MarginTimeSec int `json:"marginTimeSec"`
65+
FuzzPercent int `json:"fuzzPercent"`
66+
ReplayWindowSize int `json:"replayWindowSize"`
67+
}
68+
69+
// DeadPeerDetection represents a dead peer detection configuration used in ipsec.
70+
type DeadPeerDetection struct {
71+
TimeoutSec int `json:"timeoutSec,omitempty"`
72+
DeadPeerHandling string `json:"deadPeerHandling,omitempty"`
2473
}
2574

2675
// NetworkConnectorPageResponse represents a paginated response of network connectors.
@@ -224,60 +273,33 @@ func (c *NetworkConnectorsService) Delete(connectorID string, networkID string)
224273
return err
225274
}
226275

227-
// IPsecStartResponse represents the response from starting an IPsec tunnel.
228-
type IPsecStartResponse struct {
229-
Success bool `json:"success"`
230-
Message string `json:"message,omitempty"`
231-
Status string `json:"status,omitempty"`
232-
}
233-
234-
// IPsecStopResponse represents the response from stopping an IPsec tunnel.
235-
type IPsecStopResponse struct {
236-
Success bool `json:"success"`
237-
Message string `json:"message,omitempty"`
238-
Status string `json:"status,omitempty"`
239-
}
240-
241276
// StartIPsec starts an IPsec tunnel for the specified network connector.
242-
func (c *NetworkConnectorsService) StartIPsec(connectorID string) (*IPsecStartResponse, error) {
277+
func (c *NetworkConnectorsService) StartIPsec(connectorID string) error {
243278
endpoint := fmt.Sprintf("%s/networks/connectors/%s/ipsec/start", c.client.GetV1Url(), connectorID)
244279
req, err := http.NewRequest(http.MethodPost, endpoint, nil)
245280
if err != nil {
246-
return nil, err
247-
}
248-
249-
body, err := c.client.DoRequest(req)
250-
if err != nil {
251-
return nil, err
281+
return err
252282
}
253283

254-
var response IPsecStartResponse
255-
err = json.Unmarshal(body, &response)
284+
_, err = c.client.DoRequest(req)
256285
if err != nil {
257-
return nil, err
286+
return err
258287
}
259-
260-
return &response, nil
288+
return nil
261289
}
262290

263291
// StopIPsec stops an IPsec tunnel for the specified network connector.
264-
func (c *NetworkConnectorsService) StopIPsec(connectorID string) (*IPsecStopResponse, error) {
292+
func (c *NetworkConnectorsService) StopIPsec(connectorID string) error {
265293
endpoint := fmt.Sprintf("%s/networks/connectors/%s/ipsec/stop", c.client.GetV1Url(), connectorID)
266294
req, err := http.NewRequest(http.MethodPost, endpoint, nil)
267295
if err != nil {
268-
return nil, err
269-
}
270-
271-
body, err := c.client.DoRequest(req)
272-
if err != nil {
273-
return nil, err
296+
return err
274297
}
275298

276-
var response IPsecStopResponse
277-
err = json.Unmarshal(body, &response)
299+
_, err = c.client.DoRequest(req)
278300
if err != nil {
279-
return nil, err
301+
return err
280302
}
281303

282-
return &response, nil
304+
return nil
283305
}

cloudconnexa/network_connectors_ipsec_test.go

Lines changed: 0 additions & 148 deletions
This file was deleted.

cloudconnexa/networks.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ const (
1818

1919
// Network represents a network in CloudConnexa.
2020
type Network struct {
21-
Connectors []NetworkConnector `json:"connectors"`
22-
Description string `json:"description"`
23-
Egress bool `json:"egress"`
24-
ID string `json:"id"`
25-
InternetAccess string `json:"internetAccess"`
26-
Name string `json:"name"`
27-
Routes []Route `json:"routes"`
28-
SystemSubnets []string `json:"systemSubnets"`
29-
NetworkItemID string `json:"NetworkItemID"`
21+
Connectors []NetworkConnector `json:"connectors"`
22+
Description string `json:"description"`
23+
Egress bool `json:"egress"`
24+
ID string `json:"id"`
25+
InternetAccess string `json:"internetAccess"`
26+
Name string `json:"name"`
27+
Routes []Route `json:"routes"`
28+
SystemSubnets []string `json:"systemSubnets"`
29+
NetworkItemID string `json:"NetworkItemID"`
30+
TunnelingProtocol string `json:"tunnelingProtocol"`
3031
}
3132

3233
// NetworkPageResponse represents a paginated response of networks.

e2e/client_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,12 @@ func TestCreateNetwork(t *testing.T) {
121121
Subnet: fmt.Sprintf("10.%d.%d.0/24", timestamp%256, (timestamp/256)%256),
122122
}
123123
network := cloudconnexa.Network{
124-
Description: "test",
125-
Egress: false,
126-
Name: testName,
127-
InternetAccess: cloudconnexa.InternetAccessSplitTunnelOn,
128-
Connectors: []cloudconnexa.NetworkConnector{connector},
124+
Description: "test",
125+
Egress: false,
126+
Name: testName,
127+
InternetAccess: cloudconnexa.InternetAccessSplitTunnelOn,
128+
Connectors: []cloudconnexa.NetworkConnector{connector},
129+
TunnelingProtocol: "OPENVPN",
129130
}
130131
response, err := c.Networks.Create(network)
131132
require.NoError(t, err)

0 commit comments

Comments
 (0)