Skip to content

Commit

Permalink
Merge pull request #23588 from hashicorp/b/fixing-nits-in-update-go-a…
Browse files Browse the repository at this point in the history
…zure-sdk-tooling

`tools/update-go-azure-sdk`: fixing a couple of nits
  • Loading branch information
tombuildsstuff authored Oct 17, 2023
2 parents a4e9c91 + f606659 commit 7574d90
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion internal/tools/update-go-azure-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ func main() {
log.Fatalf("validating input: %+v", err)
}

absolutePathToAzureRMProvider, err := filepath.Abs(input.azurermRepoPath)
if err != nil {
log.Fatalf("determining absolute path to the AzureRM Provider at %q: %+v", input.azurermRepoPath, err)
}
input.azurermRepoPath = absolutePathToAzureRMProvider

if input.goSdkRepoPath != "" {
absolutePathToGoSdk, err := filepath.Abs(input.goSdkRepoPath)
if err != nil {
log.Fatalf("determining absolute path to the Go SDK at %q: %+v", input.goSdkRepoPath, err)
}
input.goSdkRepoPath = absolutePathToGoSdk
}

if err := run(context.Background(), input); err != nil {
log.Fatalf(err.Error())
}
Expand Down Expand Up @@ -376,12 +390,36 @@ func determineApiVersionsCurrentlyUsedForService(workingDirectory string, servic
for _, line := range *imports {
logger.Trace(fmt.Sprintf("Parsing import line %q..", line))

// if there's an import alias, we need to remove that to determine the correct API version
if !strings.HasPrefix(line, `"`) {
// if the import is (force) imported (even if unused)
if strings.HasPrefix(line, "_") {
line = strings.TrimPrefix(line, "_")
line = strings.TrimSpace(line)
}

if !strings.Contains(line, " ") {
return nil, fmt.Errorf("the import line %q looks like an import alias but didn't parse in the format `alias \"importpath\"`", line)
}
components := strings.Split(line, " ")
if len(components) != 2 {
return nil, fmt.Errorf("expected the import alias to be in the format `alias \"path\"` but got %q which was %d segments: %+v", line, len(components), components)
}
line = strings.TrimSpace(components[1])
}
serviceImportPath := fmt.Sprintf("github.com/hashicorp/go-azure-sdk/resource-manager/%s/", serviceName)
if !strings.Contains(line, serviceImportPath) {
logger.Trace(fmt.Sprintf("Skipping line %q since it's not for this SDK..", line))
continue
}

// pull out the api version, which is predictable
line = strings.TrimPrefix(line, `"`)
line = strings.TrimPrefix(line, fmt.Sprintf("github.com/hashicorp/go-azure-sdk/resource-manager/%s/", serviceName))
line = strings.TrimPrefix(line, serviceImportPath)
line = strings.TrimSuffix(line, `"`)
components := strings.Split(line, "/")
apiVersion := components[0]
logger.Trace(fmt.Sprintf("Found API Version %q from %q", apiVersion, line))
apiVersions[apiVersion] = struct{}{}
}

Expand Down

0 comments on commit 7574d90

Please sign in to comment.