Skip to content

Commit

Permalink
Merge pull request #74 from padok-team/fix/fault-tolerance
Browse files Browse the repository at this point in the history
fix(getters): made all getters fault tolerant by returning empty stru…
  • Loading branch information
StanGirard authored Feb 23, 2023
2 parents b16af46 + 7c4336b commit 51c8f9f
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 0 deletions.
4 changes: 4 additions & 0 deletions aws/acm/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func GetCertificates(svc ACMGetObjectAPI) []types.CertificateDetail {
result, err := svc.ListCertificates(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list of certificates
return []types.CertificateDetail{}
}
var certificatesArn []*string
var certificates []types.CertificateDetail
Expand All @@ -32,6 +34,7 @@ func GetCertificates(svc ACMGetObjectAPI) []types.CertificateDetail {
result, err = svc.ListCertificates(context.TODO(), input)
if err != nil {
fmt.Println(err)
return []types.CertificateDetail{}
}
for _, r := range result.CertificateSummaryList {
certificatesArn = append(certificatesArn, r.CertificateArn)
Expand All @@ -45,6 +48,7 @@ func GetCertificates(svc ACMGetObjectAPI) []types.CertificateDetail {
result, err := svc.DescribeCertificate(context.TODO(), input)
if err != nil {
fmt.Println(err)
return []types.CertificateDetail{}
}
certificates = append(certificates, *result.Certificate)
}
Expand Down
4 changes: 4 additions & 0 deletions aws/cloudfront/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func GetAllCloudfront(svc CloudfrontGetObjectApi) []types.DistributionSummary {
result, err := svc.ListDistributions(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list of certificates
return []types.DistributionSummary{}
}
return result.DistributionList.Items
}
Expand All @@ -36,6 +38,8 @@ func GetAllDistributionConfig(svc CloudfrontGetObjectApi, ds []types.Distributio
result, err := svc.GetDistributionConfig(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list of certificates
return []SummaryToConfig{}
}
d = append(d, SummaryToConfig{summary: cc, config: *result.DistributionConfig})
}
Expand Down
2 changes: 2 additions & 0 deletions aws/cloudtrail/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func GetCloudtrails(s aws.Config) []types.Trail {
result, err := svc.DescribeTrails(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list
return []types.Trail{}
}
return result.TrailList
}
4 changes: 4 additions & 0 deletions aws/cognito/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func GetCognitoPools(s aws.Config) []types.IdentityPoolShortDescription {
result, err := svc.ListIdentityPools(context.TODO(), cognitoInput)
if err != nil {
fmt.Println(err)
// Return an empty list of certificates
return []types.IdentityPoolShortDescription{}
}
fmt.Println("Hello")
return result.IdentityPools
Expand All @@ -32,6 +34,8 @@ func GetDetailedCognitoPool(s aws.Config, pools []types.IdentityPoolShortDescrip
result, err := svc.DescribeIdentityPool(context.TODO(), cognitoInput)
if err != nil {
fmt.Println(err)
// Return an empty list of certificates
return []cognitoidentity.DescribeIdentityPoolOutput{}
}
detailedPools = append(detailedPools, *result)
}
Expand Down
6 changes: 6 additions & 0 deletions aws/dynamodb/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ func GetDynamodbs(s aws.Config) []string {
result, err := svc.ListTables(context.TODO(), dynamodbInput)
if err != nil {
fmt.Println(err)
// Return an empty list
return []string{}
}
return result.TableNames
}
Expand All @@ -29,6 +31,8 @@ func GetTables(s aws.Config, dynamodbs []string) []*dynamodb.DescribeTableOutput
resp, err := svc.DescribeTable(context.TODO(), params)
if err != nil {
fmt.Println(err)
// Return an empty list of certificates
return []*dynamodb.DescribeTableOutput{}
}
tables = append(tables, resp)

Expand All @@ -51,6 +55,8 @@ func GetContinuousBackups(s aws.Config, tables []string) []TableBackups {
resp, err := svc.DescribeContinuousBackups(context.TODO(), params)
if err != nil {
fmt.Println(err)
// Return an empty list of certificates
return []TableBackups{}
}
continuousBackups = append(continuousBackups, TableBackups{d, *resp.ContinuousBackupsDescription})
}
Expand Down
4 changes: 4 additions & 0 deletions aws/ec2/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func GetEC2s(svc EC2GetObjectAPI) []types.Instance {
result, err := svc.DescribeInstances(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list
return []types.Instance{}
}
var instances []types.Instance
for _, r := range result.Reservations {
Expand All @@ -30,6 +32,8 @@ func GetEC2s(svc EC2GetObjectAPI) []types.Instance {
result, err = svc.DescribeInstances(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list of instances
return []types.Instance{}
}
for _, r := range result.Reservations {
instances = append(instances, r.Instances...)
Expand Down
4 changes: 4 additions & 0 deletions aws/ecr/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func GetECRs(s aws.Config) []types.Repository {
ecrRepositories = append(ecrRepositories, result.Repositories...)
if err != nil {
fmt.Println(err)
// Return an empty list
return []types.Repository{}
}
for {
if result.NextToken != nil {
Expand All @@ -27,6 +29,8 @@ func GetECRs(s aws.Config) []types.Repository {
ecrRepositories = append(ecrRepositories, result.Repositories...)
if err != nil {
fmt.Println(err)
// Return an empty list
return []types.Repository{}
}
} else {
break
Expand Down
6 changes: 6 additions & 0 deletions aws/eks/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func GetClusters(svc EKSGetObjectAPI) []types.Cluster {
result, err := svc.ListClusters(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list
return []types.Cluster{}
}
var clusters []string
var clustersDetails []types.Cluster
Expand All @@ -33,6 +35,8 @@ func GetClusters(svc EKSGetObjectAPI) []types.Cluster {
result, err = svc.ListClusters(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list of instances
return []types.Cluster{}
}
for _, r := range result.Clusters {
clusters = append(clusters, r)
Expand All @@ -46,6 +50,8 @@ func GetClusters(svc EKSGetObjectAPI) []types.Cluster {
result, err := svc.DescribeCluster(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list of instances
return []types.Cluster{}
}
clustersDetails = append(clustersDetails, *result.Cluster)
}
Expand Down
2 changes: 2 additions & 0 deletions aws/guardduty/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ func GetDetectors(s aws.Config) []string {
result, err := svc.ListDetectors(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list
return []string{}
}
return result.DetectorIds
}
22 changes: 22 additions & 0 deletions aws/iam/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func GetAllUsers(s aws.Config) []types.User {
users = append(users, result.Users...)
if err != nil {
fmt.Println(err)
// Return an empty list
return []types.User{}
}
for {
if result.IsTruncated {
Expand All @@ -26,6 +28,8 @@ func GetAllUsers(s aws.Config) []types.User {
users = append(users, result.Users...)
if err != nil {
fmt.Println(err)
// Return an empty list
return []types.User{}
}
} else {
break
Expand All @@ -42,6 +46,8 @@ func GetAllRoles(s aws.Config) []types.Role {
roles = append(roles, result.Roles...)
if err != nil {
fmt.Println(err)
// Return an empty list
return []types.Role{}
}
for {
if result.IsTruncated {
Expand All @@ -50,6 +56,8 @@ func GetAllRoles(s aws.Config) []types.Role {
roles = append(roles, result.Roles...)
if err != nil {
fmt.Println(err)
// Return an empty list
return []types.Role{}
}
} else {
break
Expand All @@ -74,6 +82,8 @@ func GetMfaForUsers(s aws.Config, u []types.User) []MFAForUser {
result, err := svc.ListMFADevices(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list of mfa devices
return []MFAForUser{}
}
mfaForUsers = append(mfaForUsers, MFAForUser{
UserName: *user.UserName,
Expand All @@ -89,6 +99,8 @@ func GetMfaForUsers(s aws.Config, u []types.User) []MFAForUser {
})
if err != nil {
fmt.Println(err)
// Return an empty list of mfa devices
return []MFAForUser{}
}
} else {
break
Expand All @@ -114,6 +126,8 @@ func GetAccessKeysForUsers(s aws.Config, u []types.User) []AccessKeysForUser {
result, err := svc.ListAccessKeys(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list of access keys
return []AccessKeysForUser{}
}
accessKeysForUsers = append(accessKeysForUsers, AccessKeysForUser{
UserName: *user.UserName,
Expand All @@ -129,6 +143,8 @@ func GetAccessKeysForUsers(s aws.Config, u []types.User) []AccessKeysForUser {
})
if err != nil {
fmt.Println(err)
// Return an empty list of access keys
return []AccessKeysForUser{}
}
} else {
break
Expand Down Expand Up @@ -221,6 +237,8 @@ func GetPolicyAttachedToUser(s aws.Config, user types.User) []types.AttachedPoli
result, err := svc.ListAttachedUserPolicies(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list of attached policies
return []types.AttachedPolicy{}
}
return result.AttachedPolicies
}
Expand All @@ -233,6 +251,8 @@ func GetAllPolicyVersions(s aws.Config, policyArn *string) []types.PolicyVersion
result, err := svc.ListPolicyVersions(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list of policy versions
return []types.PolicyVersion{}
}

return result.Versions
Expand Down Expand Up @@ -306,6 +326,8 @@ func GetPolicyAttachedToRole(s aws.Config, role types.Role) []types.AttachedPoli
result, err := svc.ListAttachedRolePolicies(context.TODO(), input)
if err != nil {
fmt.Println(err)
// Return an empty list of attached policies
return []types.AttachedPolicy{}
}
return result.AttachedPolicies
}
4 changes: 4 additions & 0 deletions aws/lambda/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func GetLambdas(s aws.Config) []types.FunctionConfiguration {
lambdas = append(lambdas, result.Functions...)
if err != nil {
fmt.Println(err)
// Return an empty list
return []types.FunctionConfiguration{}
}
for {
if result.NextMarker != nil {
Expand All @@ -27,6 +29,8 @@ func GetLambdas(s aws.Config) []types.FunctionConfiguration {
lambdas = append(lambdas, result.Functions...)
if err != nil {
fmt.Println(err)
// Return an empty list
return []types.FunctionConfiguration{}
}
} else {
break
Expand Down
6 changes: 6 additions & 0 deletions aws/loadbalancers/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func GetLoadBalancersAttributes(s aws.Config, loadbalancers []types.LoadBalancer
result, err := svc.DescribeLoadBalancerAttributes(context.TODO(), input)
if err != nil {
fmt.Println(err)
// return empty struct
return []LoadBalancerAttributes{}
}
loadBalancerAttributes = append(loadBalancerAttributes, LoadBalancerAttributes{
LoadBalancerArn: *loadbalancer.LoadBalancerArn,
Expand All @@ -44,6 +46,8 @@ func GetElasticLoadBalancers(s aws.Config) []types.LoadBalancer {
result, err := svc.DescribeLoadBalancers(context.TODO(), input)
if err != nil {
fmt.Println(err)
// return empty struct
return []types.LoadBalancer{}
}
loadBalancers = append(loadBalancers, result.LoadBalancers...)
for {
Expand All @@ -52,6 +56,8 @@ func GetElasticLoadBalancers(s aws.Config) []types.LoadBalancer {
result, err = svc.DescribeLoadBalancers(context.TODO(), input)
if err != nil {
fmt.Println(err)
// return empty struct
return []types.LoadBalancer{}
}
loadBalancers = append(loadBalancers, result.LoadBalancers...)
} else {
Expand Down
8 changes: 8 additions & 0 deletions aws/rds/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func GetListRDS(svc RDSGetObjectAPI) []types.DBInstance {
instances = append(instances, resp.DBInstances...)
if err != nil {
fmt.Println(err)
// Return an empty list of instances
return []types.DBInstance{}
}
for {
if resp.Marker != nil {
Expand All @@ -29,6 +31,8 @@ func GetListRDS(svc RDSGetObjectAPI) []types.DBInstance {
instances = append(instances, resp.DBInstances...)
if err != nil {
fmt.Println(err)
// Return an empty list of instances
return []types.DBInstance{}
}
} else {
break
Expand All @@ -46,6 +50,8 @@ func GetListDBClusters(svc RDSGetObjectAPI) []types.DBCluster {
clusters = append(clusters, resp.DBClusters...)
if err != nil {
fmt.Println(err)
// Return an empty list of instances
return []types.DBCluster{}
}
for {
if resp.Marker != nil {
Expand All @@ -54,6 +60,8 @@ func GetListDBClusters(svc RDSGetObjectAPI) []types.DBCluster {
clusters = append(clusters, resp.DBClusters...)
if err != nil {
fmt.Println(err)
// Return an empty list of instances
return []types.DBCluster{}
}
} else {
break
Expand Down
6 changes: 6 additions & 0 deletions aws/s3/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func GetListS3(s aws.Config) []types.Bucket {
resp, err := svc.ListBuckets(context.TODO(), params)
if err != nil {
fmt.Println(err)
// Return an empty list
return []types.Bucket{}
}

return resp.Buckets
Expand All @@ -31,6 +33,8 @@ func GetListS3NotInRegion(s aws.Config, region string) []types.Bucket {
resp, err := svc.ListBuckets(context.TODO(), params)
if err != nil {
fmt.Println(err)
// Return an empty list
return []types.Bucket{}
}

var buckets []types.Bucket
Expand Down Expand Up @@ -116,6 +120,8 @@ func GetS3ToVersioning(s aws.Config, b []types.Bucket) []S3ToVersioning {
resp, err := svc.GetBucketVersioning(context.TODO(), params)
if err != nil {
fmt.Println(err)
// return empty struct
return []S3ToVersioning{}
}
if resp.Status != types.BucketVersioningStatusEnabled {
s3toVersioning = append(s3toVersioning, S3ToVersioning{*bucket.Name, false})
Expand Down
Loading

0 comments on commit 51c8f9f

Please sign in to comment.