Skip to content

Commit

Permalink
Fix golint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sks committed Oct 26, 2020
1 parent 551cb9f commit 9b16f7e
Show file tree
Hide file tree
Showing 25 changed files with 48 additions and 46 deletions.
6 changes: 3 additions & 3 deletions build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func main() {
for _, f := range files {
if strings.HasPrefix(f.Name(), filePrefix) {
if !strings.HasPrefix(f.Name(), filePrefix+provider+fileSuffix) {
providerName := strings.Replace(f.Name(), filePrefix, "", -1)
providerName = strings.Replace(providerName, fileSuffix, "", -1)
providerName := strings.ReplaceAll(f.Name(), filePrefix, "")
providerName = strings.ReplaceAll(providerName, fileSuffix, "")
deletedProvider = append(deletedProvider, providerName)
}
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func main() {
}
fmt.Println(outb.String())

//revert code and files
// revert code and files
err = ioutil.WriteFile(packageCmdPath+"/root.go", rootCode, os.ModePerm)
if err != nil {
log.Println(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func printService(provider terraformutils.ProviderGenerator, serviceName string,
}
variables["data"]["terraform_remote_state"][k] = map[string]interface{}{
"backend": "gcs",
"config": bucket.BucketGetTfData(strings.Replace(path, serviceName, k, -1)),
"config": bucket.BucketGetTfData(strings.ReplaceAll(path, serviceName, k)),
}
}
} else {
Expand All @@ -234,7 +234,7 @@ func printService(provider terraformutils.ProviderGenerator, serviceName string,
variables["data"]["terraform_remote_state"][k] = map[string]interface{}{
"backend": "local",
"config": [1]interface{}{map[string]interface{}{
"path": strings.Repeat("../", strings.Count(path, "/")) + strings.Replace(path, serviceName, k, -1) + "terraform.tfstate",
"path": strings.Repeat("../", strings.Count(path, "/")) + strings.ReplaceAll(path, serviceName, k) + "terraform.tfstate",
}},
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/provider_cmd_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func newCmdGithubImporter(options ImportOptions) *cobra.Command {
for _, organization := range organizations {
provider := newGitHubProvider()
options.PathPattern = originalPathPattern
options.PathPattern = strings.Replace(options.PathPattern, "{provider}", "{provider}/"+organization, -1)
options.PathPattern = strings.ReplaceAll(options.PathPattern, "{provider}", "{provider}/"+organization)
log.Println(provider.GetName() + " importing organization " + organization)
err := Import(provider, options, []string{organization, token})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/provider_cmd_google.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newCmdGoogleImporter(options ImportOptions) *cobra.Command {
for _, region := range options.Regions {
provider := newGoogleProvider()
options.PathPattern = originalPathPattern
options.PathPattern = strings.Replace(options.PathPattern, "{provider}/{service}", "{provider}/"+project+"/{service}/"+region, -1)
options.PathPattern = strings.ReplaceAll(options.PathPattern, "{provider}/{service}", "{provider}/"+project+"/{service}/"+region)
log.Println(provider.GetName() + " importing project " + project + " region " + region)
err := Import(provider, options, []string{region, project})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/provider_cmd_keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func newCmdKeycloakImporter(options ImportOptions) *cobra.Command {
provider := newKeycloakProvider()
log.Println(provider.GetName() + " importing realm " + target)
options.PathPattern = originalPathPattern
options.PathPattern = strings.Replace(options.PathPattern, "{provider}", "{provider}/"+target, -1)
options.PathPattern = strings.ReplaceAll(options.PathPattern, "{provider}", "{provider}/"+target)
err := Import(provider, options, []string{url, clientID, clientSecret, realm, strconv.FormatInt(clientTimeout, 10), caCert, strconv.FormatBool(tlsInsecureSkipVerify), target})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/provider_cmd_yandex.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func newCmdYandexImporter(options ImportOptions) *cobra.Command {
for _, folderID := range options.Projects {
provider := newYandexProvider()
options.PathPattern = originalPathPattern
options.PathPattern = strings.Replace(options.PathPattern, "{provider}/{service}", "{provider}/"+folderID+"/{service}", -1)
options.PathPattern = strings.ReplaceAll(options.PathPattern, "{provider}/{service}", "{provider}/"+folderID+"/{service}")
log.Println(provider.GetName() + " importing folder id " + folderID)
err := Import(provider, options, []string{folderID})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion providers/alicloud/connectivity/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (
DDOSBGPCode = ServiceCode("DDOSBGP")
)

//xml
// xml
type Endpoints struct {
Endpoint []Endpoint `xml:"Endpoint"`
}
Expand Down
2 changes: 1 addition & 1 deletion providers/aws/autoscaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (g *AutoScalingGenerator) loadLaunchConfigurations(svc *autoscaling.Client)
attributes := map[string]string{}
// only for LaunchConfigurations with userdata, we want get user_data_base64
if aws.StringValue(lc.UserData) != "" {
attributes["user_data_base64"] = "=" //need set not empty string to get user_data_base64 from provider
attributes["user_data_base64"] = "=" // need set not empty string to get user_data_base64 from provider
}
g.Resources = append(g.Resources, terraformutils.NewResource(
resourceName,
Expand Down
2 changes: 1 addition & 1 deletion providers/aws/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (g *IamGenerator) getUserPolices(svc *iam.Client, userName *string) error {
for p.Next(context.Background()) {
for _, policy := range p.CurrentPage().PolicyNames {
resourceName := aws.StringValue(userName) + "_" + policy
resourceName = strings.Replace(resourceName, "@", "", -1)
resourceName = strings.ReplaceAll(resourceName, "@", "")
policyID := aws.StringValue(userName) + ":" + policy
g.Resources = append(g.Resources, terraformutils.NewSimpleResource(
policyID,
Expand Down
1 change: 1 addition & 0 deletions providers/datadog/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package datadog
import (
"context"
"fmt"

datadogV1 "github.com/DataDog/datadog-api-client-go/api/v1/datadog"

"github.com/GoogleCloudPlatform/terraformer/terraformutils"
Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/clouddns.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (g *CloudDNSGenerator) PostConvertHook() error {
if zoneID == resourceZone.InstanceState.ID {
g.Resources[i].Item["managed_zone"] = "${google_dns_managed_zone." + resourceZone.ResourceName + ".name}"
name := g.Resources[i].Item["name"].(string)
name = strings.Replace(name, resourceZone.Item["dns_name"].(string), "", -1)
name = strings.ReplaceAll(name, resourceZone.Item["dns_name"].(string), "")
g.Resources[i].Item["name"] = name + "${google_dns_managed_zone." + resourceZone.ResourceName + ".dns_name}"
}
}
Expand Down
4 changes: 2 additions & 2 deletions providers/gcp/dataproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ func (g *DataprocGenerator) InitResources() error {
clusterList := dataprocService.Projects.Regions.Clusters.List(g.GetArgs()["project"].(string), g.GetArgs()["region"].(compute.Region).Name)
g.Resources = g.createClusterResources(ctx, clusterList)

//jobList := dataprocService.Projects.Regions.Jobs.List(g.GetArgs()["project"].(string), g.GetArgs()["region"])
//g.Resources = append(g.Resources, g.createJobResources(jobList, ctx)...)
// jobList := dataprocService.Projects.Regions.Jobs.List(g.GetArgs()["project"].(string), g.GetArgs()["region"])
// g.Resources = append(g.Resources, g.createJobResources(jobList, ctx)...)

return nil
}
2 changes: 1 addition & 1 deletion providers/gcp/gcp_compute_code_generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ var ComputeServices = map[string]terraformutils.ServiceGenerator{
`

func main() {
computeAPIData, err := ioutil.ReadFile(os.Getenv("GOPATH") + "/src/google.golang.org/api/compute/v1/compute-api.json") //TODO delete this hack
computeAPIData, err := ioutil.ReadFile(os.Getenv("GOPATH") + "/src/google.golang.org/api/compute/v1/compute-api.json") // TODO delete this hack
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions providers/gcp/gcp_compute_code_generator/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ var terraformResources = map[string]gcpResourceRenderable{
terraformName: "google_compute_global_forwarding_rule",
},
},
//"globalNetworkEndpointGroups": basicGCPResource{
// terraformName: "google_compute_global_network_endpoint",
//},
// "globalNetworkEndpointGroups": basicGCPResource{
// terraformName: "google_compute_global_network_endpoint",
// },
"healthChecks": basicGCPResource{
terraformName: "google_compute_health_check",
},
Expand Down
12 changes: 6 additions & 6 deletions providers/gcp/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ func (g *GcsGenerator) InitResources() error {
g.Resources = g.createBucketsResources(ctx, gcsService)

// TODO find bug with storageTransferService.TransferJobs.List().Pages
//storageTransferService, err := storagetransfer.NewService(ctx)
//if err != nil {
// log.Print(err)
// return err
// }
//g.Resources = append(g.Resources, g.createTransferJobsResources(ctx, storageTransferService)...)
// storageTransferService, err := storagetransfer.NewService(ctx)
// if err != nil {
// log.Print(err)
// return err
// }
// g.Resources = append(g.Resources, g.createTransferJobsResources(ctx, storageTransferService)...)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/gke.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (g *GkeGenerator) initClusters(clusters *container.ListClustersResponse) []
"^node_config\\.(.*)", // delete node_config config from google_container_cluster
"^ip_allocation_policy\\.[0-9]\\.cluster_secondary_range_name$", // conflict with cluster_ipv4_cidr_block
"^ip_allocation_policy\\.[0-9]\\.services_secondary_range_name$", // conflict with services_ipv4_cidr_block
"^ip_allocation_policy\\.[0-9]\\.create_subnetwork") //only for create new cluster conflict with others ip_allocation_policy fields
"^ip_allocation_policy\\.[0-9]\\.create_subnetwork") // only for create new cluster conflict with others ip_allocation_policy fields
resources = append(resources, resource)
resources = append(resources, g.initNodePools(cluster.NodePools, cluster.Name, cluster.Location)...)
}
Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (g InstancesGenerator) createResources(ctx context.Context, instancesList *
resources := []terraformutils.Resource{}
if err := instancesList.Pages(ctx, func(page *compute.InstanceList) error {
for _, obj := range page.Items {
if strings.HasPrefix("gke-", obj.Name) {
if strings.HasPrefix(obj.Name, "gke-") {
continue
}
resources = append(resources, terraformutils.NewResource(
Expand Down
2 changes: 1 addition & 1 deletion providers/github/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (g *RepositoriesGenerator) InitResources() error {
opt := &githubAPI.RepositoryListByOrgOptions{
ListOptions: githubAPI.ListOptions{PerPage: 100},
}
//list all repositories for the authenticated user
// list all repositories for the authenticated user
for {
repos, resp, err := client.Repositories.ListByOrg(ctx, g.GetArgs()["organization"].(string), opt)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion providers/gmailfilter/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (g LabelGenerator) createResources(labels []*gmail.Label) []terraformutils.
}
resources = append(resources, terraformutils.NewResource(
l.Id,
strings.Replace(l.Name, "/", "_", -1),
strings.ReplaceAll(l.Name, "/", "_"),
"gmailfilter_label",
"gmailfilter",
map[string]string{},
Expand Down
10 changes: 5 additions & 5 deletions providers/keycloak/openid_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,23 @@ func (g RealmGenerator) createOpenIDProtocolMapperResources(clientID string, ope
resources = append(resources, g.createOpenIDGenericProtocolMapperResource("user_session_note", protocolMapper.Id, protocolMapper.Name, openidClient.RealmId, openidClient.ClientId, clientID))
case "oidc-address-mapper":
// Not supported for the moment
//resources = append(resources, g.createOpenIDGenericProtocolMapperResource("address", protocolMapper.Id, protocolMapper.Name, openidClient.RealmId, openidClient.ClientId, clientID))
// resources = append(resources, g.createOpenIDGenericProtocolMapperResource("address", protocolMapper.Id, protocolMapper.Name, openidClient.RealmId, openidClient.ClientId, clientID))
continue
case "oidc-role-name-mapper":
// Not supported for the moment
//resources = append(resources, g.createOpenIDGenericProtocolMapperResource("role_name", protocolMapper.Id, protocolMapper.Name, openidClient.RealmId, openidClient.ClientId, clientID))
// resources = append(resources, g.createOpenIDGenericProtocolMapperResource("role_name", protocolMapper.Id, protocolMapper.Name, openidClient.RealmId, openidClient.ClientId, clientID))
continue
case "oidc-sha256-pairwise-sub-mapper":
// Not supported for the moment
//resources = append(resources, g.createOpenIDGenericProtocolMapperResource("pairwise_subject_identifier", protocolMapper.Id, protocolMapper.Name, openidClient.RealmId, openidClient.ClientId, clientID))
// resources = append(resources, g.createOpenIDGenericProtocolMapperResource("pairwise_subject_identifier", protocolMapper.Id, protocolMapper.Name, openidClient.RealmId, openidClient.ClientId, clientID))
continue
case "oidc-allowed-origins-mapper":
// Not supported for the moment
//resources = append(resources, g.createOpenIDGenericProtocolMapperResource("allowed_web_origins", protocolMapper.Id, protocolMapper.Name, openidClient.RealmId, openidClient.ClientId, clientID))
// resources = append(resources, g.createOpenIDGenericProtocolMapperResource("allowed_web_origins", protocolMapper.Id, protocolMapper.Name, openidClient.RealmId, openidClient.ClientId, clientID))
continue
case "oidc-audience-resolve-mapper":
// Not supported for the moment
//resources = append(resources, g.createOpenIDGenericProtocolMapperResource("audience_resolve", protocolMapper.Id, protocolMapper.Name, openidClient.RealmId, openidClient.ClientId, clientID))
// resources = append(resources, g.createOpenIDGenericProtocolMapperResource("audience_resolve", protocolMapper.Id, protocolMapper.Name, openidClient.RealmId, openidClient.ClientId, clientID))
continue
}
}
Expand Down
2 changes: 1 addition & 1 deletion providers/openstack/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (g *ComputeGenerator) createResources(list *pagination.Pager, volclient *go
tv["depends_on"] = []string{dependsOn}
}

name := s.Name + strings.Replace(v.Attachments[0].Device, "/dev/", "", -1)
name := s.Name + strings.ReplaceAll(v.Attachments[0].Device, "/dev/", "")
rid := s.ID + "/" + v.ID
resource := terraformutils.NewResource(
rid,
Expand Down
13 changes: 7 additions & 6 deletions terraformutils/hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package terraformutils
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"log"
"regexp"
Expand Down Expand Up @@ -86,15 +87,15 @@ func (v *astSanitizer) visitObjectItem(o *ast.ObjectItem) {
if strings.HasPrefix(t.Token.Text, `"<<`) {
t.Token.Text = t.Token.Text[1:]
t.Token.Text = t.Token.Text[:len(t.Token.Text)-1]
t.Token.Text = strings.Replace(t.Token.Text, `\n`, "\n", -1)
t.Token.Text = strings.Replace(t.Token.Text, `\t`, "", -1)
t.Token.Text = strings.ReplaceAll(t.Token.Text, `\n`, "\n")
t.Token.Text = strings.ReplaceAll(t.Token.Text, `\t`, "")
t.Token.Type = 10
// check if text json for Unquote and Indent
tmp := map[string]interface{}{}
jsonTest := t.Token.Text
lines := strings.Split(jsonTest, "\n")
jsonTest = strings.Join(lines[1:len(lines)-1], "\n")
jsonTest = strings.Replace(jsonTest, "\\\"", "\"", -1)
jsonTest = strings.ReplaceAll(jsonTest, "\\\"", "\"")
// it's json we convert to heredoc back
err := json.Unmarshal([]byte(jsonTest), &tmp)
if err == nil {
Expand Down Expand Up @@ -126,7 +127,7 @@ func Print(data interface{}, mapsObjects map[string]struct{}, format string) ([]
case "json":
return jsonPrint(data)
}
return []byte{}, fmt.Errorf("error: unknown output format")
return []byte{}, errors.New("error: unknown output format")
}

func hclPrint(data interface{}, mapsObjects map[string]struct{}) ([]byte, error) {
Expand All @@ -151,10 +152,10 @@ func hclPrint(data interface{}, mapsObjects map[string]struct{}) ([]byte, error)
s := b.String()

// Remove extra whitespace...
s = strings.Replace(s, "\n\n", "\n", -1)
s = strings.ReplaceAll(s, "\n\n", "\n")

// ...but leave whitespace between resources
s = strings.Replace(s, "}\nresource", "}\n\nresource", -1)
s = strings.ReplaceAll(s, "}\nresource", "}\n\nresource")

// Apply Terraform style (alignment etc.)
formatted, err := hclPrinter.Format([]byte(s))
Expand Down
4 changes: 2 additions & 2 deletions terraformutils/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func jsonPrint(data interface{}) ([]byte, error) {
return []byte{}, fmt.Errorf("error marshalling terraform data to json: %v", err)
}
// We don't need to escape > or <
s := strings.Replace(string(dataJSONBytes), "\\u003c", "<", -1)
s := strings.ReplaceAll(string(dataJSONBytes), "\\u003c", "<")
s = OpeningBracketRegexp.ReplaceAllStringFunc(s, escapingBackslashReplacer("<"))
s = strings.Replace(s, "\\u003e", ">", -1)
s = strings.ReplaceAll(s, "\\u003e", ">")
s = ClosingBracketRegexp.ReplaceAllStringFunc(s, escapingBackslashReplacer(">"))
return []byte(s), nil
}
Expand Down
4 changes: 2 additions & 2 deletions terraformutils/terraformoutput/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type BucketState struct {
}

func (b BucketState) BucketGetTfData(path string) interface{} {
name := strings.Replace(b.Name, "gs://", "", -1)
name := strings.ReplaceAll(b.Name, "gs://", "")
bucketStateData := map[string]interface{}{
"terraform": map[string]interface{}{
"backend": []map[string]interface{}{
Expand All @@ -52,7 +52,7 @@ func (b BucketState) BucketUpload(path string, file []byte) error {
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
name := strings.Replace(b.Name, "gs://", "", -1)
name := strings.ReplaceAll(b.Name, "gs://", "")
wc := client.Bucket(name).Object(b.BucketPrefix(path) + "/default.tfstate").NewWriter(ctx)
if _, err = wc.Write(file); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion terraformutils/terraformoutput/hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func OutputHclFiles(resources []terraformutils.Resource, provider terraformutils
}
} else {
for k, v := range typeOfServices {
fileName := strings.Replace(k, strings.Split(k, "_")[0]+"_", "", -1)
fileName := strings.ReplaceAll(k, strings.Split(k, "_")[0]+"_", "")
err := printFile(v, fileName, path, output)
if err != nil {
return err
Expand Down

0 comments on commit 9b16f7e

Please sign in to comment.