-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bohdan Siryk
authored and
Bohdan Siryk
committed
Feb 1, 2024
1 parent
cebcb52
commit 4509df8
Showing
24 changed files
with
725 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package v1beta1 | ||
|
||
import ( | ||
"github.com/instaclustr/operator/pkg/models" | ||
) | ||
|
||
type GenericClusterSpec struct { | ||
// Name [ 3 .. 32 ] characters. | ||
Name string `json:"name,omitempty"` | ||
|
||
Version string `json:"version,omitempty"` | ||
|
||
// The PCI compliance standards relate to the security of user data and transactional information. | ||
// Can only be applied clusters provisioned on AWS_VPC, running Cassandra, Kafka, Elasticsearch and Redis. | ||
PCICompliance bool `json:"pciCompliance,omitempty"` | ||
|
||
PrivateNetwork bool `json:"privateNetwork,omitempty"` | ||
|
||
// Non-production clusters may receive lower priority support and reduced SLAs. | ||
// Production tier is not available when using Developer class nodes. See SLA Tier for more information. | ||
// Enum: "PRODUCTION" "NON_PRODUCTION". | ||
SLATier string `json:"slaTier,omitempty"` | ||
|
||
Description string `json:"description,omitempty"` | ||
|
||
TwoFactorDelete []*TwoFactorDelete `json:"twoFactorDelete,omitempty"` | ||
} | ||
|
||
func (s *GenericClusterSpec) Equals(o *GenericClusterSpec) bool { | ||
return s.Name == o.Name && | ||
s.Version == o.Version && | ||
s.PCICompliance == o.PCICompliance && | ||
s.PrivateNetwork == o.PrivateNetwork && | ||
s.SLATier == o.SLATier && | ||
s.Description == o.Description && | ||
s.TwoFactorDeleteEquals(o) | ||
} | ||
|
||
func (s *GenericClusterSpec) TwoFactorDeleteEquals(o *GenericClusterSpec) bool { | ||
if len(s.TwoFactorDelete) != len(o.TwoFactorDelete) { | ||
return false | ||
} | ||
|
||
if len(s.TwoFactorDelete) > 0 { | ||
return *s.TwoFactorDelete[0] == *o.TwoFactorDelete[0] | ||
} | ||
|
||
return true | ||
} | ||
|
||
func (s *GenericClusterSpec) FromInstAPI(model *models.GenericClusterFields) { | ||
s.Name = model.Name | ||
s.PCICompliance = model.PCIComplianceMode | ||
s.PrivateNetwork = model.PrivateNetworkCluster | ||
s.SLATier = model.SLATier | ||
s.Description = model.Description | ||
s.TwoFactorDeleteFromInstAPI(model.TwoFactorDelete) | ||
} | ||
|
||
func (s *GenericClusterSpec) TwoFactorDeleteFromInstAPI(instaModels []*models.TwoFactorDelete) { | ||
s.TwoFactorDelete = make([]*TwoFactorDelete, 0, len(instaModels)) | ||
for _, instaModel := range instaModels { | ||
s.TwoFactorDelete = append(s.TwoFactorDelete, &TwoFactorDelete{ | ||
Email: instaModel.ConfirmationEmail, | ||
Phone: instaModel.ConfirmationPhoneNumber, | ||
}) | ||
} | ||
} | ||
|
||
func (s *GenericClusterSpec) ToInstAPI() models.GenericClusterFields { | ||
return models.GenericClusterFields{ | ||
Name: s.Name, | ||
Description: s.Description, | ||
PCIComplianceMode: s.PCICompliance, | ||
PrivateNetworkCluster: s.PrivateNetwork, | ||
SLATier: s.SLATier, | ||
TwoFactorDelete: s.TwoFactorDeleteToInstAPI(), | ||
} | ||
} | ||
|
||
func (s *GenericClusterSpec) TwoFactorDeleteToInstAPI() []*models.TwoFactorDelete { | ||
tfd := make([]*models.TwoFactorDelete, 0, len(s.TwoFactorDelete)) | ||
for _, t := range s.TwoFactorDelete { | ||
tfd = append(tfd, &models.TwoFactorDelete{ | ||
ConfirmationPhoneNumber: t.Phone, | ||
ConfirmationEmail: t.Email, | ||
}) | ||
} | ||
|
||
return tfd | ||
} | ||
|
||
func (s *GenericClusterSpec) ClusterSettingsNeedUpdate(iCluster *GenericClusterSpec) bool { | ||
return len(s.TwoFactorDelete) != 0 && len(iCluster.TwoFactorDelete) == 0 || | ||
s.Description != iCluster.Description | ||
} | ||
|
||
func (s *GenericClusterSpec) ClusterSettingsUpdateToInstAPI() *models.ClusterSettings { | ||
instaModels := &models.ClusterSettings{} | ||
if s.TwoFactorDelete != nil { | ||
instaModel := &models.TwoFactorDelete{} | ||
for _, tfd := range s.TwoFactorDelete { | ||
instaModel = tfd.ToInstAPI() | ||
} | ||
instaModels.TwoFactorDelete = instaModel | ||
} | ||
instaModels.Description = s.Description | ||
|
||
return instaModels | ||
} | ||
|
||
type GenericDataCentreSpec struct { | ||
Name string `json:"name,omitempty"` | ||
Region string `json:"region"` | ||
CloudProvider string `json:"cloudProvider"` | ||
ProviderAccountName string `json:"accountName,omitempty"` | ||
Network string `json:"network"` | ||
Tags map[string]string `json:"tags,omitempty"` | ||
CloudProviderSettings []*CloudProviderSettings `json:"cloudProviderSettings,omitempty"` | ||
} | ||
|
||
func (s *GenericDataCentreSpec) Equals(o *GenericDataCentreSpec) bool { | ||
return s.Name == o.Name && | ||
s.Region == o.Region && | ||
s.CloudProvider == o.CloudProvider && | ||
s.ProviderAccountName == o.ProviderAccountName && | ||
s.Network == o.Network && | ||
areTagsEqual(s.Tags, o.Tags) && | ||
areCloudProviderSettingsEqual(s.CloudProviderSettings, o.CloudProviderSettings) | ||
} | ||
|
||
func (s *GenericDataCentreSpec) FromInstAPI(model *models.GenericDataCentreFields) { | ||
s.Name = model.Name | ||
s.Region = model.Region | ||
s.CloudProvider = model.CloudProvider | ||
s.ProviderAccountName = model.ProviderAccountName | ||
s.Network = model.Network | ||
s.Tags = tagsFromInstAPI(model.Tags) | ||
s.CloudProviderSettings = cloudProviderSettingsFromInstAPI(model) | ||
} | ||
|
||
func (dc *GenericDataCentreSpec) CloudProviderSettingsToInstAPI() models.CloudProviderSettings { | ||
instModel := models.CloudProviderSettings{} | ||
|
||
switch dc.CloudProvider { | ||
case models.AWSVPC: | ||
for _, providerSettings := range dc.CloudProviderSettings { | ||
instModel.AWSSettings = append(instModel.AWSSettings, providerSettings.AWSToInstAPI()) | ||
} | ||
case models.AZUREAZ: | ||
for _, providerSettings := range dc.CloudProviderSettings { | ||
instModel.AzureSettings = append(instModel.AzureSettings, providerSettings.AzureToInstAPI()) | ||
} | ||
case models.GCP: | ||
for _, providerSettings := range dc.CloudProviderSettings { | ||
instModel.GCPSettings = append(instModel.GCPSettings, providerSettings.GCPToInstAPI()) | ||
} | ||
} | ||
|
||
return instModel | ||
} | ||
|
||
func (s *GenericDataCentreSpec) ToInstAPI() models.GenericDataCentreFields { | ||
return models.GenericDataCentreFields{ | ||
Name: s.Name, | ||
Network: s.Network, | ||
CloudProvider: s.CloudProvider, | ||
Region: s.Region, | ||
ProviderAccountName: s.ProviderAccountName, | ||
Tags: tagsToInstAPI(s.Tags), | ||
CloudProviderSettings: s.CloudProviderSettingsToInstAPI(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.