-
Notifications
You must be signed in to change notification settings - Fork 66
/
privateendpoint.go
71 lines (62 loc) · 2.53 KB
/
privateendpoint.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
package v1
import (
"errors"
"go.mongodb.org/atlas/mongodbatlas"
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/provider"
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status"
"github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/compat"
)
type PrivateEndpoint struct {
// Cloud provider for which you want to retrieve a private endpoint service. Atlas accepts AWS or AZURE.
// +kubebuilder:validation:Enum=AWS;GCP;AZURE;TENANT
Provider provider.ProviderName `json:"provider"`
// Cloud provider region for which you want to create the private endpoint service.
Region string `json:"region"`
// Unique identifier of the private endpoint you created in your AWS VPC or Azure Vnet.
// +optional
ID string `json:"id,omitempty"`
// Private IP address of the private endpoint network interface you created in your Azure VNet.
// +optional
IP string `json:"ip,omitempty"`
// Unique identifier of the Google Cloud project in which you created your endpoints.
// +optional
GCPProjectID string `json:"gcpProjectId,omitempty"`
// Unique identifier of the endpoint group. The endpoint group encompasses all of the endpoints that you created in Google Cloud.
// +optional
EndpointGroupName string `json:"endpointGroupName,omitempty"`
// Collection of individual private endpoints that comprise your endpoint group.
// +optional
Endpoints GCPEndpoints `json:"endpoints,omitempty"`
}
type GCPEndpoints []GCPEndpoint
type GCPEndpoint struct {
// Forwarding rule that corresponds to the endpoint you created in Google Cloud.
EndpointName string `json:"endpointName,omitempty"`
// Private IP address of the endpoint you created in Google Cloud.
IPAddress string `json:"ipAddress,omitempty"`
}
// ToAtlas converts the PrivateEndpoint to native Atlas client format.
func (i PrivateEndpoint) ToAtlas() (*mongodbatlas.PrivateEndpoint, error) {
result := &mongodbatlas.PrivateEndpoint{}
err := compat.JSONCopy(result, i)
return result, err
}
// Identifier is required to satisfy "Identifiable" iterface
func (i PrivateEndpoint) Identifier() interface{} {
return string(i.Provider) + status.TransformRegionToID(i.Region)
}
func (endpoints GCPEndpoints) ConvertToAtlas() ([]*mongodbatlas.GCPEndpoint, error) {
if len(endpoints) == 0 {
return nil, errors.New("list of endpoints is empty")
}
result := make([]*mongodbatlas.GCPEndpoint, 0)
for _, e := range endpoints {
endpoint := &mongodbatlas.GCPEndpoint{}
err := compat.JSONCopy(endpoint, e)
if err != nil {
return nil, err
}
result = append(result, endpoint)
}
return result, nil
}