Skip to content

Commit

Permalink
Update rule.go
Browse files Browse the repository at this point in the history
  • Loading branch information
liamg authored Jan 13, 2022
1 parent 85ded94 commit 8e2586a
Showing 1 changed file with 46 additions and 11 deletions.
57 changes: 46 additions & 11 deletions rules/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,39 +44,74 @@ func (r Rule) ShortCodeDisplayName() string {
}

var acronyms = []string{
"acl",
"alb",
"api",
"arn",
"aws",
"cidr",
"db",
"dns",
"ebs",
"ec2",
"ecr",
"eks",
"ecs",
"efs",
"kms",
"https",
"ssh",
"eks",
"elb",
"gke",
"http",
"http2",
"https",
"iam",
"im",
"imds",
"ip",
"ips",
"kms",
"lb",
"md5",
"mfa",
"mq",
"msk",
"rbac",
"rdp",
"rds",
"rsa",
"sam",
"sgr",
"sha1",
"sha256",
"sns",
"sql",
"sqs",
"iam",
"alb",
"lb",
"elb",
"ssh",
"ssm",
"tls",
"ubla",
"vm",
"vpc",
"vtpm",
"waf",
}

var specials = map[string]string{
"dynamodb": "DynamoDB",
"documentdb": "DocumentDB",
"mysql": "MySQL",
"postgresql": "PostgreSQL",
"acls": "ACLs",
"ips": "IPs",
"bigquery": "BigQuery",
}

func nicify(input string) string {
input = strings.ToLower(input)
for _, acronym := range acronyms {
input = regexp.MustCompile(fmt.Sprintf("\\b%s\\b", acronym)).ReplaceAllString(input, strings.ToUpper(acronym))
}
for replace, with := range specials {
input = regexp.MustCompile(fmt.Sprintf("\\b%s\\b", replace)).ReplaceAllString(input, with)
}
for _, acronym := range acronyms {
input = regexp.MustCompile(fmt.Sprintf("\\b%s\\b", acronym)).ReplaceAllString(input, strings.ToUpper(acronym))
}
return strings.Title(strings.ReplaceAll(input, "-", " "))
}

0 comments on commit 8e2586a

Please sign in to comment.