Skip to content

Commit

Permalink
Fix lints by golangci-lint and revive
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgajard committed May 3, 2024
1 parent 109d59e commit 6af1e0b
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 239 deletions.
140 changes: 0 additions & 140 deletions pagerduty/resource_pagerduty_addon_test.go

This file was deleted.

18 changes: 9 additions & 9 deletions pagerdutyplugin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ type Config struct {
mu sync.Mutex

// The PagerDuty API URL
ApiUrl string
APIURL string

// Override default PagerDuty API URL
ApiUrlOverride string
APIURLOverride string

// The PagerDuty APP URL
AppUrl string
AppURL string

// The PagerDuty API V2 token
Token string
Expand All @@ -52,7 +52,7 @@ type Config struct {
}

type AppOauthScopedToken struct {
ClientId, ClientSecret, Subdomain string
ClientID, ClientSecret, Subdomain string
}

const invalidCreds = `
Expand All @@ -75,17 +75,17 @@ func (c *Config) Client(ctx context.Context) (*pagerduty.Client, error) {
httpClient.Timeout = 1 * time.Minute
httpClient.Transport = logging.NewTransport("PagerDuty", http.DefaultTransport)

apiUrl := c.ApiUrl
if c.ApiUrlOverride != "" {
apiUrl = c.ApiUrlOverride
apiURL := c.APIURL
if c.APIURLOverride != "" {
apiURL = c.APIURLOverride
}

maxRetries := 1
retryInterval := 60 // seconds

clientOpts := []pagerduty.ClientOptions{
WithHTTPClient(httpClient),
pagerduty.WithAPIEndpoint(apiUrl),
pagerduty.WithAPIEndpoint(apiURL),
pagerduty.WithTerraformProvider(c.TerraformVersion),
pagerduty.WithRetryPolicy(maxRetries, retryInterval),
}
Expand All @@ -97,7 +97,7 @@ func (c *Config) Client(ctx context.Context) (*pagerduty.Client, error) {
accountAndScopes = append(accountAndScopes, availableOauthScopes()...)
opt := pagerduty.WithScopedOAuthAppTokenSource(pagerduty.NewFileTokenSource(
ctx,
c.AppOauthScopedToken.ClientId,
c.AppOauthScopedToken.ClientID,
c.AppOauthScopedToken.ClientSecret,
accountAndScopes,
tokenFile,
Expand Down
6 changes: 3 additions & 3 deletions pagerdutyplugin/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestConfigSkipCredsValidation(t *testing.T) {
func TestConfigCustomApiUrl(t *testing.T) {
config := Config{
Token: "foo",
ApiUrl: "https://api.domain.tld",
APIURL: "https://api.domain.tld",
SkipCredsValidation: true,
}

Expand All @@ -45,7 +45,7 @@ func TestConfigCustomApiUrl(t *testing.T) {
func TestConfigCustomApiUrlOverride(t *testing.T) {
config := Config{
Token: "foo",
ApiUrlOverride: "https://api.domain-override.tld",
APIURLOverride: "https://api.domain-override.tld",
SkipCredsValidation: true,
}

Expand All @@ -58,7 +58,7 @@ func TestConfigCustomApiUrlOverride(t *testing.T) {
func TestConfigCustomAppUrl(t *testing.T) {
config := Config{
Token: "foo",
AppUrl: "https://app.domain.tld",
AppURL: "https://app.domain.tld",
SkipCredsValidation: true,
}

Expand Down
6 changes: 3 additions & 3 deletions pagerdutyplugin/data_source_pagerduty_business_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ type dataSourceBusinessService struct{ client *pagerduty.Client }

var _ datasource.DataSourceWithConfigure = (*dataSourceBusinessService)(nil)

func (*dataSourceBusinessService) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (*dataSourceBusinessService) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = "pagerduty_business_service"
}

func (*dataSourceBusinessService) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (*dataSourceBusinessService) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{Computed: true},
Expand All @@ -33,7 +33,7 @@ func (*dataSourceBusinessService) Schema(ctx context.Context, req datasource.Sch
}
}

func (d *dataSourceBusinessService) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (d *dataSourceBusinessService) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
resp.Diagnostics.Append(ConfigurePagerdutyClient(&d.client, req.ProviderData)...)
}

Expand Down
6 changes: 3 additions & 3 deletions pagerdutyplugin/data_source_pagerduty_extension_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type dataSourceExtensionSchema struct{ client *pagerduty.Client }

var _ datasource.DataSourceWithConfigure = (*dataSourceExtensionSchema)(nil)

func (*dataSourceExtensionSchema) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (*dataSourceExtensionSchema) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = "pagerduty_extension_schema"
}

func (*dataSourceExtensionSchema) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (*dataSourceExtensionSchema) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{Computed: true},
Expand All @@ -34,7 +34,7 @@ func (*dataSourceExtensionSchema) Schema(ctx context.Context, req datasource.Sch
}
}

func (d *dataSourceExtensionSchema) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (d *dataSourceExtensionSchema) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
resp.Diagnostics.Append(ConfigurePagerdutyClient(&d.client, req.ProviderData)...)
}

Expand Down
12 changes: 6 additions & 6 deletions pagerdutyplugin/data_source_pagerduty_standards.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ type dataSourceStandards struct {

var _ datasource.DataSourceWithConfigure = (*dataSourceStandards)(nil)

func (d *dataSourceStandards) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (d *dataSourceStandards) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = "pagerduty_standards"
}

func (d *dataSourceStandards) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *dataSourceStandards) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"resource_type": schema.StringAttribute{Optional: true},
Expand All @@ -33,6 +33,10 @@ func (d *dataSourceStandards) Schema(ctx context.Context, req datasource.SchemaR
}
}

func (d *dataSourceStandards) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
resp.Diagnostics.Append(ConfigurePagerdutyClient(&d.client, req.ProviderData)...)
}

func (d *dataSourceStandards) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data dataSourceStandardsModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
Expand All @@ -54,10 +58,6 @@ func (d *dataSourceStandards) Read(ctx context.Context, req datasource.ReadReque
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

func (d *dataSourceStandards) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
resp.Diagnostics.Append(ConfigurePagerdutyClient(&d.client, req.ProviderData)...)
}

func flattenStandards(ctx context.Context, list []pagerduty.Standard) (types.List, diag.Diagnostics) {
var diagnostics diag.Diagnostics
mapList := make([]types.Object, 0, len(list))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ type dataSourceStandardsResourceScores struct {

var _ datasource.DataSource = (*dataSourceStandardsResourceScores)(nil)

func (d *dataSourceStandardsResourceScores) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (d *dataSourceStandardsResourceScores) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = "pagerduty_standards_resource_scores"
}

func (d *dataSourceStandardsResourceScores) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *dataSourceStandardsResourceScores) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{Required: true},
Expand All @@ -45,7 +45,7 @@ func (d *dataSourceStandardsResourceScores) Schema(ctx context.Context, req data
}
}

func (d *dataSourceStandardsResourceScores) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (d *dataSourceStandardsResourceScores) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
resp.Diagnostics.Append(ConfigurePagerdutyClient(&d.client, req.ProviderData)...)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ type dataSourceStandardsResourcesScores struct {

var _ datasource.DataSource = (*dataSourceStandardsResourcesScores)(nil)

func (d *dataSourceStandardsResourcesScores) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (d *dataSourceStandardsResourcesScores) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = "pagerduty_standards_resources_scores"
}

func (d *dataSourceStandardsResourcesScores) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *dataSourceStandardsResourcesScores) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"ids": schema.ListAttribute{
Expand All @@ -44,7 +44,7 @@ func (d *dataSourceStandardsResourcesScores) Schema(ctx context.Context, req dat
}
}

func (d *dataSourceStandardsResourcesScores) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (d *dataSourceStandardsResourcesScores) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
resp.Diagnostics.Append(ConfigurePagerdutyClient(&d.client, req.ProviderData)...)
}

Expand Down
6 changes: 3 additions & 3 deletions pagerdutyplugin/data_source_pagerduty_standards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func testStandards(a map[string]string) error {
}

for _, att := range testAttrs {
required_sub_attr := fmt.Sprintf("standards.0.%s", att)
if _, ok := a[required_sub_attr]; !ok {
return fmt.Errorf("Expected the required attribute %s to exist", required_sub_attr)
requiredSubAttr := fmt.Sprintf("standards.0.%s", att)
if _, ok := a[requiredSubAttr]; !ok {
return fmt.Errorf("Expected the required attribute %s to exist", requiredSubAttr)
}
}

Expand Down
12 changes: 6 additions & 6 deletions pagerdutyplugin/data_source_pagerduty_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@ type dataSourceTag struct {

var _ datasource.DataSourceWithConfigure = (*dataSourceStandards)(nil)

func (d *dataSourceTag) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
resp.Diagnostics.Append(ConfigurePagerdutyClient(&d.client, req.ProviderData)...)
}

func (d *dataSourceTag) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (d *dataSourceTag) Metadata(_ context.Context, _ datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = "pagerduty_tag"
}

func (d *dataSourceTag) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *dataSourceTag) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"label": schema.StringAttribute{
Expand All @@ -41,6 +37,10 @@ func (d *dataSourceTag) Schema(ctx context.Context, req datasource.SchemaRequest
}
}

func (d *dataSourceTag) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
resp.Diagnostics.Append(ConfigurePagerdutyClient(&d.client, req.ProviderData)...)
}

func (d *dataSourceTag) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var searchTag string
if d := req.Config.GetAttribute(ctx, path.Root("label"), &searchTag); d.HasError() {
Expand Down
Loading

0 comments on commit 6af1e0b

Please sign in to comment.