Skip to content

Commit

Permalink
Standardize logs (integrations#1053)
Browse files Browse the repository at this point in the history
* First batch of changes

* Another batch of changes

* More changes, maybe fix build

* More log cleanup

* Final changes

* Fix one additional error message
  • Loading branch information
kfcampbell authored Feb 18, 2022
1 parent 3f90b55 commit 7d6c12a
Show file tree
Hide file tree
Showing 56 changed files with 78 additions and 260 deletions.
4 changes: 2 additions & 2 deletions github/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ func (c *Config) Meta() (interface{}, error) {
owner.v3client = v3client

if c.Anonymous() {
log.Printf("[DEBUG] No token present; configuring anonymous owner.")
log.Printf("[INFO] No token present; configuring anonymous owner.")
return &owner, nil
} else {
_, err = c.ConfigureOwner(&owner)
if err != nil {
return &owner, err
}
log.Printf("[DEBUG] Token present; configuring authenticated owner: %s", owner.name)
log.Printf("[INFO] Token present; configuring authenticated owner: %s", owner.name)
return &owner, nil
}
}
2 changes: 0 additions & 2 deletions github/data_source_github_actions_public_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package github

import (
"context"
"log"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
Expand Down Expand Up @@ -31,7 +30,6 @@ func dataSourceGithubActionsPublicKey() *schema.Resource {
func dataSourceGithubActionsPublicKeyRead(d *schema.ResourceData, meta interface{}) error {
repository := d.Get("repository").(string)
owner := meta.(*Owner).name
log.Printf("[INFO] Refreshing GitHub Actions Public Key from: %s/%s", owner, repository)

client := meta.(*Owner).v3client
ctx := context.Background()
Expand Down
3 changes: 1 addition & 2 deletions github/data_source_github_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ func dataSourceGithubBranchRead(d *schema.ResourceData, meta interface{}) error
branchName := d.Get("branch").(string)
branchRefName := "refs/heads/" + branchName

log.Printf("[DEBUG] Reading GitHub branch reference %s/%s (%s)", orgName, repoName, branchRefName)
ref, resp, err := client.Git.GetRef(context.TODO(), orgName, repoName, branchRefName)
if err != nil {
if err, ok := err.(*github.ErrorResponse); ok {
if err.Response.StatusCode == http.StatusNotFound {
log.Printf("Error reading GitHub branch reference %s/%s (%s): %s", orgName, repoName, branchRefName, err)
log.Printf("[INFO] Error reading GitHub branch reference %s/%s (%s): %s", orgName, repoName, branchRefName, err)
d.SetId("")
return nil
}
Expand Down
4 changes: 1 addition & 3 deletions github/data_source_github_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package github

import (
"context"
"log"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
Expand Down Expand Up @@ -34,11 +33,10 @@ func dataSourceGithubMembership() *schema.Resource {

func dataSourceGithubMembershipRead(d *schema.ResourceData, meta interface{}) error {
username := d.Get("username").(string)
log.Printf("[INFO] Refreshing GitHub membership: %s", username)

client := meta.(*Owner).v3client

orgName := meta.(*Owner).name

if configuredOrg := d.Get("organization").(string); configuredOrg != "" {
orgName = configuredOrg
}
Expand Down
2 changes: 0 additions & 2 deletions github/data_source_github_organization.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package github

import (
"log"
"strconv"

"github.com/google/go-github/v42/github"
Expand Down Expand Up @@ -53,7 +52,6 @@ func dataSourceGithubOrganization() *schema.Resource {

func dataSourceGithubOrganizationRead(d *schema.ResourceData, meta interface{}) error {
name := d.Get("name").(string)
log.Printf("[INFO] Refreshing GitHub Organization: %s", name)

client := meta.(*Owner).v3client
ctx := meta.(*Owner).StopContext
Expand Down
3 changes: 0 additions & 3 deletions github/data_source_github_organization_team_sync_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package github
import (
"context"
"fmt"
"log"

"github.com/google/go-github/v42/github"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -39,8 +38,6 @@ func dataSourceGithubOrganizationTeamSyncGroups() *schema.Resource {
}

func dataSourceGithubOrganizationTeamSyncGroupsRead(d *schema.ResourceData, meta interface{}) error {
log.Print("[INFO] Refreshing GitHub Organization Team-Sync Groups")

client := meta.(*Owner).v3client
ctx := context.Background()

Expand Down
3 changes: 0 additions & 3 deletions github/data_source_github_organization_teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package github
import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/shurcooL/githubv4"
"log"
)

func dataSourceGithubOrganizationTeams() *schema.Resource {
Expand Down Expand Up @@ -72,8 +71,6 @@ func dataSourceGithubOrganizationTeamsRead(d *schema.ResourceData, meta interfac
orgName := meta.(*Owner).name
rootTeamsOnly := d.Get("root_teams_only").(bool)

log.Print("[INFO] Refreshing GitHub Teams for Organization: ", orgName)

var query TeamsQuery
variables := map[string]interface{}{
"first": githubv4.Int(100),
Expand Down
4 changes: 0 additions & 4 deletions github/data_source_github_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package github
import (
"context"
"fmt"
"log"
"strconv"
"strings"

Expand Down Expand Up @@ -111,23 +110,20 @@ func dataSourceGithubReleaseRead(d *schema.ResourceData, meta interface{}) error

switch retrieveBy := strings.ToLower(d.Get("retrieve_by").(string)); retrieveBy {
case "latest":
log.Printf("[INFO] Refreshing GitHub latest release from repository %s", repository)
release, _, err = client.Repositories.GetLatestRelease(ctx, owner, repository)
case "id":
releaseID := int64(d.Get("release_id").(int))
if releaseID == 0 {
return fmt.Errorf("`release_id` must be set when `retrieve_by` = `id`")
}

log.Printf("[INFO] Refreshing GitHub release by id %d from repository %s", releaseID, repository)
release, _, err = client.Repositories.GetRelease(ctx, owner, repository, releaseID)
case "tag":
tag := d.Get("release_tag").(string)
if tag == "" {
return fmt.Errorf("`release_tag` must be set when `retrieve_by` = `tag`")
}

log.Printf("[INFO] Refreshing GitHub release by tag %s from repository %s", tag, repository)
release, _, err = client.Repositories.GetReleaseByTag(ctx, owner, repository, tag)
default:
return fmt.Errorf("one of: `latest`, `id`, `tag` must be set for `retrieve_by`")
Expand Down
2 changes: 0 additions & 2 deletions github/data_source_github_repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package github

import (
"context"
"log"

"github.com/google/go-github/v42/github"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -53,7 +52,6 @@ func dataSourceGithubRepositoriesRead(d *schema.ResourceData, meta interface{})
},
}

log.Printf("[DEBUG] Searching for GitHub repositories: %q", query)
fullNames, names, err := searchGithubRepositories(client, query, opt)
if err != nil {
return err
Expand Down
4 changes: 1 addition & 3 deletions github/data_source_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package github
import (
"context"
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -199,10 +198,9 @@ func dataSourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) er
}

if repoName == "" {
return fmt.Errorf("One of %q or %q has to be provided", "full_name", "name")
return fmt.Errorf("one of %q or %q has to be provided", "full_name", "name")
}

log.Printf("[DEBUG] Reading GitHub repository %s/%s", owner, repoName)
repo, _, err := client.Repositories.Get(context.TODO(), owner, repoName)
if err != nil {
return err
Expand Down
1 change: 0 additions & 1 deletion github/data_source_github_repository_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func dataSourceGithubRepositoryFileRead(d *schema.ResourceData, meta interface{}
return err
}

log.Printf("[DEBUG] Data Source reading repository file: %s/%s/%s, branch: %s", owner, repo, file, branch)
opts := &github.RepositoryContentGetOptions{Ref: branch}
fc, _, _, err := client.Repositories.GetContents(ctx, owner, repo, file, opts)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions github/data_source_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package github

import (
"context"
"log"
"strconv"

"github.com/google/go-github/v42/github"
Expand Down Expand Up @@ -55,7 +54,6 @@ func dataSourceGithubTeam() *schema.Resource {

func dataSourceGithubTeamRead(d *schema.ResourceData, meta interface{}) error {
slug := d.Get("slug").(string)
log.Printf("[INFO] Refreshing GitHub Team: %s", slug)

client := meta.(*Owner).v3client
orgId := meta.(*Owner).id
Expand Down
2 changes: 0 additions & 2 deletions github/data_source_github_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package github

import (
"context"
"log"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -101,7 +100,6 @@ func dataSourceGithubUser() *schema.Resource {

func dataSourceGithubUserRead(d *schema.ResourceData, meta interface{}) error {
username := d.Get("username").(string)
log.Printf("[INFO] Refreshing GitHub User: %s", username)

client := meta.(*Owner).v3client
ctx := context.Background()
Expand Down
7 changes: 3 additions & 4 deletions github/data_source_github_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package github
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/shurcooL/githubv4"
"log"
"reflect"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/shurcooL/githubv4"
)

func dataSourceGithubUsers() *schema.Resource {
Expand Down Expand Up @@ -69,7 +69,6 @@ func dataSourceGithubUsersRead(d *schema.ResourceData, meta interface{}) error {
query := reflect.New(reflect.StructOf(fields)).Elem()

if len(usernames) > 0 {
log.Printf("[INFO] Refreshing GitHub Users: %s", strings.Join(usernames, ", "))
ctx := context.WithValue(context.Background(), ctxId, d.Id())
client := meta.(*Owner).v4client
err := client.Query(ctx, query.Addr().Interface(), variables)
Expand Down
7 changes: 3 additions & 4 deletions github/migrate_github_repository_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import (
func resourceGithubWebhookMigrateState(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) {
switch v {
case 0:
log.Println("[INFO] Found GitHub Webhook State v0; migrating to v1")
log.Printf("[INFO] Found GitHub Webhook State v0; migrating to v1")
return migrateGithubWebhookStateV0toV1(is)
default:
return is, fmt.Errorf("Unexpected schema version: %d", v)
return is, fmt.Errorf("unexpected schema version: %d", v)
}
}

func migrateGithubWebhookStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) {
if is.Empty() {
log.Println("[DEBUG] Empty InstanceState; nothing to migrate.")
log.Printf("[DEBUG] Empty InstanceState; nothing to migrate.")
return is, nil
}

Expand Down Expand Up @@ -48,7 +48,6 @@ func migrateGithubWebhookStateV0toV1(is *terraform.InstanceState) (*terraform.In
}

is.Attributes[prefix+"#"] = "1"

log.Printf("[DEBUG] GitHub Webhook Attributes after State Migration: %#v", is.Attributes)

return is, nil
Expand Down
4 changes: 2 additions & 2 deletions github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {

org := d.Get("organization").(string)
if org != "" {
log.Printf("[DEBUG] Selecting organization attribute as owner: %s", org)
log.Printf("[INFO] Selecting organization attribute as owner: %s", org)
owner = org
}

Expand Down Expand Up @@ -246,7 +246,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
if writeDelay <= 0 {
return nil, fmt.Errorf("write_delay_ms must be greater than 0ms")
}
log.Printf("[DEBUG] Setting write_delay_ms to %d", writeDelay)
log.Printf("[INFO] Setting write_delay_ms to %d", writeDelay)

config := Config{
Token: token,
Expand Down
4 changes: 2 additions & 2 deletions github/provider_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ func testAccCheckOrganization() error {

func OwnerOrOrgEnvDefaultFunc() (interface{}, error) {
if organization := os.Getenv("GITHUB_ORGANIZATION"); organization != "" {
log.Printf("[DEBUG] Selecting owner %s from GITHUB_ORGANIZATION environment variable", organization)
log.Printf("[INFO] Selecting owner %s from GITHUB_ORGANIZATION environment variable", organization)
return organization, nil
}
owner := os.Getenv("GITHUB_OWNER")
log.Printf("[DEBUG] Selecting owner %s from GITHUB_OWNER environment variable", owner)
log.Printf("[INFO] Selecting owner %s from GITHUB_OWNER environment variable", owner)
return owner, nil
}

Expand Down
8 changes: 3 additions & 5 deletions github/repository_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package github
import (
"context"
"fmt"
"log"
"net/http"
"strings"

Expand All @@ -17,7 +16,7 @@ func checkRepositoryBranchExists(client *github.Client, owner, repo, branch stri
if err != nil {
if ghErr, ok := err.(*github.ErrorResponse); ok {
if ghErr.Response.StatusCode == http.StatusNotFound {
return fmt.Errorf("Branch %s not found in repository %s/%s or repository is not readable", branch, owner, repo)
return fmt.Errorf("branch %s not found in repository %s/%s or repository is not readable", branch, owner, repo)
}
}
return err
Expand All @@ -34,7 +33,7 @@ func checkRepositoryFileExists(client *github.Client, owner, repo, file, branch
return nil
}
if fc == nil {
return fmt.Errorf("File %s not a file in in repository %s/%s or repository is not readable", file, owner, repo)
return fmt.Errorf("file %s not a file in in repository %s/%s or repository is not readable", file, owner, repo)
}

return nil
Expand Down Expand Up @@ -77,11 +76,10 @@ func getFileCommit(client *github.Client, owner, repo, file, branch string) (*gi

for _, f := range rc.Files {
if f.GetFilename() == file && f.GetStatus() != "removed" {
log.Printf("[DEBUG] Found file: %s in commit: %s", file, sha)
return rc, nil
}
}
}

return nil, fmt.Errorf("Cannot find file %s in repo %s/%s", file, owner, repo)
return nil, fmt.Errorf("cannot find file %s in repo %s/%s", file, owner, repo)
}
6 changes: 3 additions & 3 deletions github/resource_github_actions_environment_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func resourceGithubActionsEnvironmentSecretRead(d *schema.ResourceData, meta int
if err != nil {
if ghErr, ok := err.(*github.ErrorResponse); ok {
if ghErr.Response.StatusCode == http.StatusNotFound {
log.Printf("[WARN] Removing environment secret %s from state because it no longer exists in GitHub",
log.Printf("[INFO] Removing environment secret %s from state because it no longer exists in GitHub",
d.Id())
d.SetId("")
return nil
Expand Down Expand Up @@ -156,7 +156,7 @@ func resourceGithubActionsEnvironmentSecretRead(d *schema.ResourceData, meta int
// as deleted (unset the ID) in order to fix potential drift by recreating
// the resource.
if updatedAt, ok := d.GetOk("updated_at"); ok && updatedAt != secret.UpdatedAt.String() {
log.Printf("[WARN] The environment secret %s has been externally updated in GitHub", d.Id())
log.Printf("[INFO] The environment secret %s has been externally updated in GitHub", d.Id())
d.SetId("")
} else if !ok {
d.Set("updated_at", secret.UpdatedAt.String())
Expand All @@ -178,7 +178,7 @@ func resourceGithubActionsEnvironmentSecretDelete(d *schema.ResourceData, meta i
if err != nil {
return err
}
log.Printf("[DEBUG] Deleting environment secret: %s", d.Id())
log.Printf("[INFO] Deleting environment secret: %s", d.Id())
_, err = client.Actions.DeleteEnvSecret(ctx, int(repo.GetID()), envName, secretName)

return err
Expand Down
2 changes: 0 additions & 2 deletions github/resource_github_actions_organization_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package github
import (
"context"
"errors"
"log"

"github.com/google/go-github/v42/github"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -110,7 +109,6 @@ func resourceGithubActionsEnabledRepositoriesObject(d *schema.ResourceData) ([]i
var enabled []int64

config := d.Get("enabled_repositories_config").([]interface{})
log.Printf("[help] length of config in actopms enabled is %v", len(config))
if len(config) > 0 {
data := config[0].(map[string]interface{})
switch x := data["repository_ids"].(type) {
Expand Down
Loading

0 comments on commit 7d6c12a

Please sign in to comment.