|
| 1 | +package cloud |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + |
| 6 | + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/provider" |
| 7 | + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status" |
| 8 | +) |
| 9 | + |
| 10 | +type CloudActions interface { |
| 11 | + createPrivateEndpoint(pe status.ProjectPrivateEndpoint, name string) (string, error) |
| 12 | + deletePrivateEndpoint(pe status.ProjectPrivateEndpoint, name string) error |
| 13 | + statusPrivateEndpointPending(region, privateID string) bool |
| 14 | + statusPrivateEndpointAvailable(region, privateID string) bool |
| 15 | +} |
| 16 | + |
| 17 | +type PEActions struct { |
| 18 | + CloudActions CloudActions |
| 19 | + PrivateEndpoint status.ProjectPrivateEndpoint |
| 20 | +} |
| 21 | + |
| 22 | +func CreatePEActions(pe status.ProjectPrivateEndpoint) PEActions { |
| 23 | + return PEActions{PrivateEndpoint: pe} |
| 24 | +} |
| 25 | + |
| 26 | +func (peActions *PEActions) CreatePrivateEndpoint(name string) (string, error) { |
| 27 | + switch peActions.PrivateEndpoint.Provider { |
| 28 | + case provider.ProviderAWS: |
| 29 | + peActions.CloudActions = &awsAction{} |
| 30 | + return peActions.CloudActions.createPrivateEndpoint(peActions.PrivateEndpoint, name) |
| 31 | + case provider.ProviderAzure: |
| 32 | + peActions.CloudActions = &azureAction{} |
| 33 | + return peActions.CloudActions.createPrivateEndpoint(peActions.PrivateEndpoint, name) |
| 34 | + case provider.ProviderGCP: |
| 35 | + peActions.CloudActions = &gcpAction{} |
| 36 | + return peActions.CloudActions.createPrivateEndpoint(peActions.PrivateEndpoint, name) |
| 37 | + } |
| 38 | + return "", errors.New("Check Provider") |
| 39 | +} |
| 40 | + |
| 41 | +func (peActions *PEActions) DeletePrivateEndpoint(name string) error { |
| 42 | + switch peActions.PrivateEndpoint.Provider { |
| 43 | + case provider.ProviderAWS: |
| 44 | + peActions.CloudActions = &awsAction{} |
| 45 | + return peActions.CloudActions.deletePrivateEndpoint(peActions.PrivateEndpoint, name) |
| 46 | + case provider.ProviderAzure: |
| 47 | + peActions.CloudActions = &azureAction{} |
| 48 | + return peActions.CloudActions.deletePrivateEndpoint(peActions.PrivateEndpoint, name) |
| 49 | + case provider.ProviderGCP: |
| 50 | + peActions.CloudActions = &gcpAction{} |
| 51 | + return peActions.CloudActions.deletePrivateEndpoint(peActions.PrivateEndpoint, name) |
| 52 | + } |
| 53 | + return errors.New("Check Provider") |
| 54 | +} |
| 55 | + |
| 56 | +func (peActions *PEActions) IsStatusPrivateEndpointPending(privateID string) bool { |
| 57 | + switch peActions.PrivateEndpoint.Provider { |
| 58 | + case provider.ProviderAWS: |
| 59 | + peActions.CloudActions = &awsAction{} |
| 60 | + return peActions.CloudActions.statusPrivateEndpointPending(peActions.PrivateEndpoint.Region, privateID) |
| 61 | + case provider.ProviderAzure: |
| 62 | + peActions.CloudActions = &azureAction{} |
| 63 | + return peActions.CloudActions.statusPrivateEndpointPending(peActions.PrivateEndpoint.Region, privateID) |
| 64 | + case provider.ProviderGCP: |
| 65 | + peActions.CloudActions = &gcpAction{} |
| 66 | + return peActions.CloudActions.statusPrivateEndpointPending(peActions.PrivateEndpoint.Region, privateID) |
| 67 | + } |
| 68 | + return false |
| 69 | +} |
| 70 | + |
| 71 | +func (peActions *PEActions) IsStatusPrivateEndpointAvailable(privateID string) bool { |
| 72 | + switch peActions.PrivateEndpoint.Provider { |
| 73 | + case provider.ProviderAWS: |
| 74 | + peActions.CloudActions = &awsAction{} |
| 75 | + return peActions.CloudActions.statusPrivateEndpointAvailable(peActions.PrivateEndpoint.Region, privateID) |
| 76 | + case provider.ProviderAzure: |
| 77 | + peActions.CloudActions = &azureAction{} |
| 78 | + return peActions.CloudActions.statusPrivateEndpointAvailable(peActions.PrivateEndpoint.Region, privateID) |
| 79 | + case provider.ProviderGCP: |
| 80 | + peActions.CloudActions = &gcpAction{} |
| 81 | + return peActions.CloudActions.statusPrivateEndpointAvailable(peActions.PrivateEndpoint.Region, privateID) |
| 82 | + } |
| 83 | + return false |
| 84 | +} |
0 commit comments