Skip to content

Commit 68971d3

Browse files
committed
fix lint
1 parent 913903f commit 68971d3

File tree

8 files changed

+55
-52
lines changed

8 files changed

+55
-52
lines changed

.golangci.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ linters:
1717
- dogsled
1818
- errcheck
1919
- errorlint
20-
- exportloopref
20+
- copyloopvar
2121
# - gci # https://github.com/daixiang0/gci/issues/209
2222
- gocheckcompilerdirectives
2323
- gofumpt
@@ -50,6 +50,10 @@ issues:
5050
- "SA1019"
5151

5252
exclude-rules:
53+
# allow tls skip verify
54+
- path: internal/provider/provider.go
55+
linters:
56+
- gosec
5357
# Exclude some linters from running on test files.
5458
- path: _test\.go$|^test/|^examples/|templates\.go$
5559
linters:

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
.PHONY: lint
3+
lint:
4+
@echo "@==> $@"
5+
@VERSION=$$(go run github.com/mikefarah/yq/[email protected] '.jobs.lint.steps[] | select(.uses == "golangci/golangci-lint-action*") | .with.version' .github/workflows/test.yml) && \
6+
go run github.com/golangci/golangci-lint/cmd/golangci-lint@$$VERSION run --fix --timeout=20m ./...

internal/provider/namespace.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import (
1818
)
1919

2020
// Ensure provider-defined types fully satisfy framework interfaces.
21-
var _ resource.Resource = &NamespaceResource{}
22-
var _ resource.ResourceWithImportState = &NamespaceResource{}
21+
var (
22+
_ resource.Resource = &NamespaceResource{}
23+
_ resource.ResourceWithImportState = &NamespaceResource{}
24+
)
2325

2426
// NewNamespaceResource creates a new NamespaceResource.
2527
func NewNamespaceResource() resource.Resource {
@@ -38,11 +40,11 @@ type NamespaceResourceModel struct {
3840
ParentID types.String `tfsdk:"parent_id"`
3941
}
4042

41-
func (r *NamespaceResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
43+
func (r *NamespaceResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
4244
resp.TypeName = req.ProviderTypeName + "_namespace"
4345
}
4446

45-
func (r *NamespaceResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
47+
func (r *NamespaceResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
4648
resp.Schema = schema.Schema{
4749
MarkdownDescription: "Namespace resource for Pomerium.",
4850

@@ -66,7 +68,7 @@ func (r *NamespaceResource) Schema(ctx context.Context, req resource.SchemaReque
6668
}
6769
}
6870

69-
func (r *NamespaceResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
71+
func (r *NamespaceResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
7072
if req.ProviderData == nil {
7173
return
7274
}
@@ -188,7 +190,7 @@ func (r *NamespaceResource) ImportState(ctx context.Context, req resource.Import
188190
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
189191
}
190192

191-
func ConvertNamespaceToPB(ctx context.Context, src *NamespaceResourceModel) (*pb.Namespace, diag.Diagnostics) {
193+
func ConvertNamespaceToPB(_ context.Context, src *NamespaceResourceModel) (*pb.Namespace, diag.Diagnostics) {
192194
var diagnostics diag.Diagnostics
193195

194196
pbNamespace := &pb.Namespace{

internal/provider/policy.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import (
1818
)
1919

2020
// Ensure provider-defined types fully satisfy framework interfaces.
21-
var _ resource.Resource = &PolicyResource{}
22-
var _ resource.ResourceWithImportState = &PolicyResource{}
21+
var (
22+
_ resource.Resource = &PolicyResource{}
23+
_ resource.ResourceWithImportState = &PolicyResource{}
24+
)
2325

2426
// NewPolicyResource creates a new PolicyResource.
2527
func NewPolicyResource() resource.Resource {
@@ -39,11 +41,11 @@ type PolicyResourceModel struct {
3941
PPL types.String `tfsdk:"ppl"`
4042
}
4143

42-
func (r *PolicyResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
44+
func (r *PolicyResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
4345
resp.TypeName = req.ProviderTypeName + "_policy"
4446
}
4547

46-
func (r *PolicyResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
48+
func (r *PolicyResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
4749
resp.Schema = schema.Schema{
4850
MarkdownDescription: "Policy resource for Pomerium.",
4951

@@ -71,7 +73,7 @@ func (r *PolicyResource) Schema(ctx context.Context, req resource.SchemaRequest,
7173
}
7274
}
7375

74-
func (r *PolicyResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
76+
func (r *PolicyResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
7577
if req.ProviderData == nil {
7678
return
7779
}
@@ -194,7 +196,7 @@ func (r *PolicyResource) ImportState(ctx context.Context, req resource.ImportSta
194196
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp)
195197
}
196198

197-
func ConvertPolicyToPB(ctx context.Context, src *PolicyResourceModel) (*pb.Policy, diag.Diagnostics) {
199+
func ConvertPolicyToPB(_ context.Context, src *PolicyResourceModel) (*pb.Policy, diag.Diagnostics) {
198200
var diagnostics diag.Diagnostics
199201

200202
pbPolicy := &pb.Policy{

internal/provider/provider.go

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
3-
41
package provider
52

63
import (
@@ -18,9 +15,10 @@ import (
1815
client "github.com/pomerium/enterprise-client-go"
1916
)
2017

21-
// Ensure ScaffoldingProvider satisfies various provider interfaces.
22-
var _ provider.Provider = &PomeriumProvider{}
23-
var _ provider.ProviderWithFunctions = &PomeriumProvider{}
18+
var (
19+
_ provider.Provider = &PomeriumProvider{}
20+
_ provider.ProviderWithFunctions = &PomeriumProvider{}
21+
)
2422

2523
// PomeriumProvider defines the provider implementation.
2624
type PomeriumProvider struct {
@@ -32,17 +30,17 @@ type PomeriumProvider struct {
3230

3331
// PomeriumProviderModel describes the provider data model.
3432
type PomeriumProviderModel struct {
35-
ApiURL types.String `tfsdk:"api_url"`
33+
APIURL types.String `tfsdk:"api_url"`
3634
ServiceAccountToken types.String `tfsdk:"service_account_token"`
3735
TLSInsecureSkipVerify types.Bool `tfsdk:"tls_insecure_skip_verify"`
3836
}
3937

40-
func (p *PomeriumProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
38+
func (p *PomeriumProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) {
4139
resp.TypeName = "pomerium"
4240
resp.Version = p.version
4341
}
4442

45-
func (p *PomeriumProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
43+
func (p *PomeriumProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
4644
resp.Schema = schema.Schema{
4745
Attributes: map[string]schema.Attribute{
4846
"api_url": schema.StringAttribute{
@@ -71,12 +69,12 @@ func (p *PomeriumProvider) Configure(ctx context.Context, req provider.Configure
7169
return
7270
}
7371

74-
if data.ApiURL.IsNull() {
72+
if data.APIURL.IsNull() {
7573
resp.Diagnostics.AddError("api_url is required", "api_url is required")
7674
return
7775
}
7876

79-
apiURL, err := url.Parse(data.ApiURL.ValueString())
77+
apiURL, err := url.Parse(data.APIURL.ValueString())
8078
if err != nil {
8179
resp.Diagnostics.AddError("failed to parse api_url", err.Error())
8280
return
@@ -105,19 +103,19 @@ func (p *PomeriumProvider) Configure(ctx context.Context, req provider.Configure
105103
resp.ResourceData = c
106104
}
107105

108-
func (p *PomeriumProvider) Resources(ctx context.Context) []func() resource.Resource {
106+
func (p *PomeriumProvider) Resources(_ context.Context) []func() resource.Resource {
109107
return []func() resource.Resource{
110108
NewNamespaceResource,
111109
NewRouteResource,
112110
NewPolicyResource,
113111
}
114112
}
115113

116-
func (p *PomeriumProvider) DataSources(ctx context.Context) []func() datasource.DataSource {
114+
func (p *PomeriumProvider) DataSources(_ context.Context) []func() datasource.DataSource {
117115
return []func() datasource.DataSource{}
118116
}
119117

120-
func (p *PomeriumProvider) Functions(ctx context.Context) []func() function.Function {
118+
func (p *PomeriumProvider) Functions(_ context.Context) []func() function.Function {
121119
return []func() function.Function{}
122120
}
123121

internal/provider/route.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import (
1818
)
1919

2020
// Ensure provider defined types fully satisfy framework interfaces.
21-
var _ resource.Resource = &RouteResource{}
22-
var _ resource.ResourceWithImportState = &RouteResource{}
21+
var (
22+
_ resource.Resource = &RouteResource{}
23+
_ resource.ResourceWithImportState = &RouteResource{}
24+
)
2325

2426
func NewRouteResource() resource.Resource {
2527
return &RouteResource{}
@@ -35,16 +37,16 @@ type RouteResourceModel struct {
3537
From types.String `tfsdk:"from"`
3638
To types.List `tfsdk:"to"`
3739
Name types.String `tfsdk:"name"`
38-
Id types.String `tfsdk:"id"`
40+
ID types.String `tfsdk:"id"`
3941
NamespaceID types.String `tfsdk:"namespace_id"`
4042
Policies types.List `tfsdk:"policies"`
4143
}
4244

43-
func (r *RouteResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
45+
func (r *RouteResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
4446
resp.TypeName = req.ProviderTypeName + "_route"
4547
}
4648

47-
func (r *RouteResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
49+
func (r *RouteResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
4850
resp.Schema = schema.Schema{
4951
// This description is used by the documentation generator and the language server.
5052
MarkdownDescription: "Route",
@@ -83,7 +85,7 @@ func (r *RouteResource) Schema(ctx context.Context, req resource.SchemaRequest,
8385
}
8486
}
8587

86-
func (r *RouteResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
88+
func (r *RouteResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
8789
if req.ProviderData == nil {
8890
return
8991
}
@@ -124,10 +126,10 @@ func (r *RouteResource) Create(ctx context.Context, req resource.CreateRequest,
124126
return
125127
}
126128

127-
plan.Id = types.StringValue(respRoute.Route.Id)
129+
plan.ID = types.StringValue(respRoute.Route.Id)
128130

129131
tflog.Trace(ctx, "Created a route", map[string]interface{}{
130-
"id": plan.Id.ValueString(),
132+
"id": plan.ID.ValueString(),
131133
"name": plan.Name.ValueString(),
132134
})
133135

@@ -143,7 +145,7 @@ func (r *RouteResource) Read(ctx context.Context, req resource.ReadRequest, resp
143145
}
144146

145147
respRoute, err := r.client.RouteService.GetRoute(ctx, &pb.GetRouteRequest{
146-
Id: state.Id.ValueString(),
148+
Id: state.ID.ValueString(),
147149
})
148150
if err != nil {
149151
resp.Diagnostics.AddError("get route", err.Error())
@@ -193,7 +195,7 @@ func (r *RouteResource) Delete(ctx context.Context, req resource.DeleteRequest,
193195
}
194196

195197
_, err := r.client.RouteService.DeleteRoute(ctx, &pb.DeleteRouteRequest{
196-
Id: data.Id.ValueString(),
198+
Id: data.ID.ValueString(),
197199
})
198200
if err != nil {
199201
resp.Diagnostics.AddError("delete route", err.Error())
@@ -214,7 +216,7 @@ func ConvertRouteToPB(
214216
pbRoute := new(pb.Route)
215217
var diagnostics diag.Diagnostics
216218

217-
pbRoute.Id = src.Id.ValueString()
219+
pbRoute.Id = src.ID.ValueString()
218220
pbRoute.Name = src.Name.ValueString()
219221
pbRoute.From = src.From.ValueString()
220222
pbRoute.NamespaceId = src.NamespaceID.ValueString()
@@ -235,7 +237,7 @@ func ConvertRouteFromPB(
235237
) diag.Diagnostics {
236238
var diagnostics diag.Diagnostics
237239

238-
dst.Id = types.StringValue(src.Id)
240+
dst.ID = types.StringValue(src.Id)
239241
dst.Name = types.StringValue(src.Name)
240242
dst.From = types.StringValue(src.From)
241243
dst.NamespaceID = types.StringValue(src.NamespaceId)

internal/provider/route_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestConvertRoute(t *testing.T) {
3939
From: types.StringValue("from"),
4040
To: types.ListValueMust(types.StringType, []attr.Value{types.StringValue("to")}),
4141
Name: types.StringValue("route-name"),
42-
Id: types.StringValue("route-id"),
42+
ID: types.StringValue("route-id"),
4343
}
4444

4545
route, diag := provider.ConvertRouteToPB(context.Background(), &plan)

main.go

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
3-
41
package main
52

63
import (
@@ -15,14 +12,7 @@ import (
1512
"google.golang.org/grpc/grpclog"
1613
)
1714

18-
var (
19-
// these will be set by the goreleaser configuration
20-
// to appropriate values for the compiled binary.
21-
version string = "dev"
22-
23-
// goreleaser can pass other information to the main package, such as the specific commit
24-
// https://goreleaser.com/cookbooks/using-main.version/
25-
)
15+
var version = "dev"
2616

2717
func main() {
2818
logger := zerolog.New(os.Stderr).
@@ -46,7 +36,6 @@ func main() {
4636
}
4737

4838
err := providerserver.Serve(context.Background(), provider.New(version), opts)
49-
5039
if err != nil {
5140
log.Fatal(err.Error())
5241
}

0 commit comments

Comments
 (0)