Skip to content

Commit

Permalink
Merge pull request #43 from haooliveira84/nil-objects
Browse files Browse the repository at this point in the history
Add check for nil objects; add handler if not S3OriginConfig
  • Loading branch information
sergenyalcin authored Dec 15, 2023
2 parents 4e91b66 + dda611f commit a548482
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 25 deletions.
33 changes: 27 additions & 6 deletions converters/provider-aws/cloudfront/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,34 @@ func DistributionResource(mg resource.Managed) ([]resource.Managed, error) {
target.Spec.ForProvider.ViewerCertificate[0].MinimumProtocolVersion = source.Spec.ForProvider.DistributionConfig.ViewerCertificate.MinimumProtocolVersion

target.Spec.ForProvider.WebACLID = source.Spec.ForProvider.DistributionConfig.WebACLID
if source.Spec.ForProvider.DistributionConfig.Origins != nil {
for _, i := range source.Spec.ForProvider.DistributionConfig.Origins.Items {
if i.S3OriginConfig != nil {
target.Spec.ForProvider.Origin = append(target.Spec.ForProvider.Origin, targetv1beta1.OriginParameters{
DomainName: i.DomainName,
OriginAccessControlID: i.ID,
S3OriginConfig: []targetv1beta1.S3OriginConfigParameters{{OriginAccessIdentity: i.S3OriginConfig.OriginAccessIdentity}},
})
} else {
convertHttpPort := float64(*i.CustomOriginConfig.HTTPPort)
convertHttpsPort := float64(*i.CustomOriginConfig.HTTPSPort)
convertOriginKeepaliveTimeout := float64(*i.CustomOriginConfig.OriginKeepaliveTimeout)
convertOriginReadTimeout := float64(*i.CustomOriginConfig.OriginReadTimeout)

for _, i := range source.Spec.ForProvider.DistributionConfig.Origins.Items {
target.Spec.ForProvider.Origin = append(target.Spec.ForProvider.Origin, targetv1beta1.OriginParameters{
DomainName: i.DomainName,
OriginAccessControlID: i.ID,
S3OriginConfig: []targetv1beta1.S3OriginConfigParameters{{OriginAccessIdentity: i.S3OriginConfig.OriginAccessIdentity}},
})
target.Spec.ForProvider.Origin = append(target.Spec.ForProvider.Origin, targetv1beta1.OriginParameters{
DomainName: i.DomainName,
OriginID: i.ID,
CustomOriginConfig: []targetv1beta1.CustomOriginConfigParameters{{
HTTPPort: &convertHttpPort,
HTTPSPort: &convertHttpsPort,
OriginKeepaliveTimeout: &convertOriginKeepaliveTimeout,
OriginReadTimeout: &convertOriginReadTimeout,
OriginProtocolPolicy: i.CustomOriginConfig.OriginProtocolPolicy,
OriginSSLProtocols: i.CustomOriginConfig.OriginSSLProtocols.Items,
}},
})
}
}
}

return []resource.Managed{
Expand Down
33 changes: 17 additions & 16 deletions converters/provider-aws/dynamodb/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,23 @@ func TableResource(mg resource.Managed) ([]resource.Managed, error) {
}
}
for _, t := range source.Spec.ForProvider.GlobalSecondaryIndexes {
parameter := &targetv1beta1.GlobalSecondaryIndexParameters{
Name: t.IndexName,
NonKeyAttributes: t.Projection.NonKeyAttributes,
ProjectionType: t.Projection.ProjectionType,
}
for _, a := range t.KeySchema {
if *a.KeyType == "HASH" {
parameter.HashKey = a.AttributeName
if t.IndexName != nil {
parameter := &targetv1beta1.GlobalSecondaryIndexParameters{
Name: t.IndexName,
NonKeyAttributes: t.Projection.NonKeyAttributes,
ProjectionType: t.Projection.ProjectionType,
}
if *a.KeyType == "RANGE" {
parameter.RangeKey = a.AttributeName
for _, a := range t.KeySchema {
if *a.KeyType == "HASH" {
parameter.HashKey = a.AttributeName
}
if *a.KeyType == "RANGE" {
parameter.RangeKey = a.AttributeName
}
}
target.Spec.ForProvider.GlobalSecondaryIndex = append(target.Spec.ForProvider.GlobalSecondaryIndex, *parameter)
}
target.Spec.ForProvider.GlobalSecondaryIndex = append(target.Spec.ForProvider.GlobalSecondaryIndex, *parameter)
}

for _, t := range source.Spec.ForProvider.LocalSecondaryIndexes {
parameter := &targetv1beta1.LocalSecondaryIndexParameters{
Name: t.IndexName,
Expand All @@ -78,13 +79,13 @@ func TableResource(mg resource.Managed) ([]resource.Managed, error) {
target.Spec.ForProvider.LocalSecondaryIndex = append(target.Spec.ForProvider.LocalSecondaryIndex, *parameter)
}

if source.Spec.ForProvider.ProvisionedThroughput.ReadCapacityUnits != nil {
convert := float64(*source.Spec.ForProvider.ProvisionedThroughput.ReadCapacityUnits)
target.Spec.ForProvider.ReadCapacity = &convert
if source.Spec.ForProvider.ProvisionedThroughput.WriteCapacityUnits != nil {
convert := float64(*source.Spec.ForProvider.ProvisionedThroughput.WriteCapacityUnits)
target.Spec.ForProvider.WriteCapacity = &convert
}
if source.Spec.ForProvider.ProvisionedThroughput.ReadCapacityUnits != nil {
convert := float64(*source.Spec.ForProvider.ProvisionedThroughput.ReadCapacityUnits)
target.Spec.ForProvider.WriteCapacity = &convert
target.Spec.ForProvider.ReadCapacity = &convert
}
target.Spec.ForProvider.StreamEnabled = source.Spec.ForProvider.StreamSpecification.StreamEnabled
target.Spec.ForProvider.StreamViewType = source.Spec.ForProvider.StreamSpecification.StreamViewType
Expand Down
1 change: 1 addition & 0 deletions converters/provider-aws/rds/rdsinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func InstanceResource(mg resource.Managed) ([]resource.Managed, error) {
target.Spec.ForProvider.IAMDatabaseAuthenticationEnabled = source.Spec.ForProvider.EnableIAMDatabaseAuthentication
target.Spec.ForProvider.PerformanceInsightsEnabled = source.Spec.ForProvider.EnablePerformanceInsights
target.Spec.ForProvider.FinalSnapshotIdentifier = source.Spec.ForProvider.FinalDBSnapshotIdentifier
target.Spec.ForProvider.InstanceClass = &source.Spec.ForProvider.DBInstanceClass
target.Spec.ForProvider.Username = source.Spec.ForProvider.MasterUsername

return []resource.Managed{
Expand Down
7 changes: 4 additions & 3 deletions converters/provider-aws/sns/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
func TopicResource(mg resource.Managed) ([]resource.Managed, error) {
source := mg.(*srcv1beta1.Topic)
target := &targetv1beta1.Topic{}
if _, err := migration.CopyInto(source, target, targetv1beta1.TopicPolicy_GroupVersionKind, "spec.forProvider.tags"); err != nil {
if _, err := migration.CopyInto(source, target, targetv1beta1.Topic_GroupVersionKind, "spec.forProvider.tags"); err != nil {
return nil, errors.Wrap(err, "failed to copy source into target")
}
target.Spec.ForProvider.Tags = make(map[string]*string, len(source.Spec.ForProvider.Tags))
Expand All @@ -36,8 +36,9 @@ func TopicResource(mg resource.Managed) ([]resource.Managed, error) {
target.Spec.ForProvider.Region = &source.Spec.ForProvider.Region
target.Spec.ForProvider.DisplayName = source.Spec.ForProvider.DisplayName
target.Spec.ForProvider.FifoTopic = source.Spec.ForProvider.FifoTopic
target.Spec.ForProvider.KMSMasterKeyID = source.Spec.ForProvider.KMSMasterKeyID

if source.Spec.ForProvider.KMSMasterKeyID != nil {
target.Spec.ForProvider.KMSMasterKeyID = source.Spec.ForProvider.KMSMasterKeyID
}
return []resource.Managed{
target,
}, nil
Expand Down

0 comments on commit a548482

Please sign in to comment.