Skip to content

Commit

Permalink
go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
dgulinobw committed May 23, 2024
1 parent eebc3ca commit 55a1afc
Show file tree
Hide file tree
Showing 21 changed files with 909 additions and 175 deletions.
24 changes: 10 additions & 14 deletions internal/provider/datasource_fact.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/ledongthuc/goterators"
api "github.com/relaypro-open/dog_api_golang/api"
)
Expand All @@ -20,15 +20,15 @@ type (
FactList []Fact

Fact struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Groups map[string]*FactGroup `tfsdk:"groups"`
}

FactGroup struct {
Vars *string `tfsdk:"vars"`
Hosts *string `tfsdk:"hosts"`
Children []string `tfsdk:"children"`
Vars *string `tfsdk:"vars"`
Hosts *string `tfsdk:"hosts"`
Children []string `tfsdk:"children"`
}
)

Expand Down Expand Up @@ -60,23 +60,19 @@ func (*factDataSource) Schema(ctx context.Context, req datasource.SchemaRequest,
MarkdownDescription: "json string of hosts",
Required: true,
},
//"hosts": schema.MapAttribute{
// Required: true,
// ElementType: types.MapType{ElemType: types.StringType},
//},
"children": schema.ListAttribute{
Required: true,
ElementType: types.StringType,
Required: true,
ElementType: types.StringType,
},
},
},
Optional: true,
},
"name": schema.StringAttribute{
Optional: true,
Optional: true,
},
"id": schema.StringAttribute{
Optional: true,
Optional: true,
Computed: true,
},
},
Expand Down
11 changes: 8 additions & 3 deletions internal/provider/datasource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"fmt"

"github.com/davecgh/go-spew/spew"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/ledongthuc/goterators"
"github.com/davecgh/go-spew/spew"
api "github.com/relaypro-open/dog_api_golang/api"
)

Expand All @@ -30,6 +30,7 @@ type (
ProfileVersion types.String `tfsdk:"profile_version"`
Ec2SecurityGroupIds []*Ec2SecurityGroupIds `tfsdk:"ec2_security_group_ids"`
Vars types.String `tfsdk:"vars"`
AlertEnable types.Bool `tfsdk:"alert_enable"`
}

Ec2SecurityGroupIds struct {
Expand Down Expand Up @@ -95,10 +96,14 @@ func (*groupDataSource) Schema(ctx context.Context, req datasource.SchemaRequest
MarkdownDescription: "json string of vars",
Optional: true,
},
"alert_enable": schema.BoolAttribute{
MarkdownDescription: "alert enable",
Optional: true,
},
"id": schema.StringAttribute{
MarkdownDescription: "group identifier",
Optional: true,
Computed: true,
Computed: true,
},
},
}
Expand Down
10 changes: 5 additions & 5 deletions internal/provider/datasource_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"fmt"

"github.com/davecgh/go-spew/spew"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/ledongthuc/goterators"
"github.com/davecgh/go-spew/spew"
api "github.com/relaypro-open/dog_api_golang/api"
)

Expand Down Expand Up @@ -139,7 +139,7 @@ func (*linkDataSource) Schema(ctx context.Context, req datasource.SchemaRequest,
"id": schema.StringAttribute{
Optional: true,
MarkdownDescription: "Link identifier",
Computed: true,
Computed: true,
},
},
}
Expand Down Expand Up @@ -205,15 +205,15 @@ func (d *linkDataSource) Read(ctx context.Context, req datasource.ReadRequest, r
tflog.Debug(ctx, spew.Sprint("ZZZfilteredLinks: %#v", filteredLinks))
if filteredLinks == nil {
resp.Diagnostics.AddError("Data Error", fmt.Sprintf("dog_link data source returned no results."))
}
}
if len(filteredLinks) > 1 {
resp.Diagnostics.AddError("Data Error", fmt.Sprintf("dog_link data source returned more than one result."))
}
if resp.Diagnostics.HasError() {
return
}

link := filteredLinks[0]
link := filteredLinks[0]
// Set state
state = ApiToLink(link)
diags := resp.State.Set(ctx, &state)
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/datasource_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/ledongthuc/goterators"
api "github.com/relaypro-open/dog_api_golang/api"
)
Expand Down Expand Up @@ -55,7 +55,7 @@ func (*profileDataSource) Schema(ctx context.Context, req datasource.SchemaReque
"id": schema.StringAttribute{
Optional: true,
MarkdownDescription: "Profile identifier",
Computed: true,
Computed: true,
},
},
}
Expand Down Expand Up @@ -121,15 +121,15 @@ func (d *profileDataSource) Read(ctx context.Context, req datasource.ReadRequest

if filteredProfiles == nil {
resp.Diagnostics.AddError("Data Error", fmt.Sprintf("dog_profile data source returned no results."))
}
}
if len(filteredProfiles) > 1 {
resp.Diagnostics.AddError("Data Error", fmt.Sprintf("dog_profile data source returned more than one result."))
}
if resp.Diagnostics.HasError() {
return
}

profile := filteredProfiles[0]
profile := filteredProfiles[0]
// Set state
state = ApiToProfile(profile)
// Set state
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/datasource_ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/ledongthuc/goterators"
api "github.com/relaypro-open/dog_api_golang/api"
)
Expand Down Expand Up @@ -132,7 +132,7 @@ func (*rulesetDataSource) Schema(ctx context.Context, req datasource.SchemaReque
"id": schema.StringAttribute{
Optional: true,
MarkdownDescription: "Rule identifier",
Computed: true,
Computed: true,
},
},
}
Expand Down
5 changes: 2 additions & 3 deletions internal/provider/datasource_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (*serviceDataSource) Schema(ctx context.Context, req datasource.SchemaReque
"ports": schema.ListAttribute{
MarkdownDescription: "Service ports",
Required: true,
ElementType: types.StringType,
ElementType: types.StringType,
},
},
},
Expand All @@ -84,7 +84,7 @@ func (*serviceDataSource) Schema(ctx context.Context, req datasource.SchemaReque
"id": schema.StringAttribute{
Optional: true,
MarkdownDescription: "Service identifier",
Computed: true,
Computed: true,
},
},
}
Expand Down Expand Up @@ -159,7 +159,6 @@ func (d *serviceDataSource) Read(ctx context.Context, req datasource.ReadRequest

filteredServices := filteredServicesProtocol


tflog.Debug(ctx, spew.Sprint("ZZZfilteredServices: %#v", filteredServices))
if filteredServices == nil {
resp.Diagnostics.AddError("Data Error", fmt.Sprintf("dog_service data source returned no results."))
Expand Down
12 changes: 6 additions & 6 deletions internal/provider/datasource_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/ledongthuc/goterators"
api "github.com/relaypro-open/dog_api_golang/api"
)
Expand Down Expand Up @@ -49,12 +49,12 @@ func (*zoneDataSource) Schema(ctx context.Context, req datasource.SchemaRequest,
"ipv4_addresses": schema.ListAttribute{
MarkdownDescription: "List of Ipv4 Addresses",
Optional: true,
ElementType: types.StringType,
ElementType: types.StringType,
},
"ipv6_addresses": schema.ListAttribute{
MarkdownDescription: "List of Ipv6 Addresses",
Optional: true,
ElementType: types.StringType,
ElementType: types.StringType,
},
"name": schema.StringAttribute{
MarkdownDescription: "Zone name",
Expand All @@ -63,7 +63,7 @@ func (*zoneDataSource) Schema(ctx context.Context, req datasource.SchemaRequest,
"id": schema.StringAttribute{
Optional: true,
MarkdownDescription: "Zone identifier",
Computed: true,
Computed: true,
},
},
}
Expand Down Expand Up @@ -128,15 +128,15 @@ func (d *zoneDataSource) Read(ctx context.Context, req datasource.ReadRequest, r

if filteredZones == nil {
resp.Diagnostics.AddError("Data Error", fmt.Sprintf("dog_zone data source returned no results."))
}
}
if len(filteredZones) > 1 {
resp.Diagnostics.AddError("Data Error", fmt.Sprintf("dog_zone data source returned more than one result."))
}
if resp.Diagnostics.HasError() {
return
}

zone := filteredZones[0]
zone := filteredZones[0]
// Set state
state = ApiToZone(zone)
diags := resp.State.Set(ctx, &state)
Expand Down
15 changes: 7 additions & 8 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ type (
)

var (
_ provider.Provider = (*dogProvider)(nil)
_ provider.Provider = (*dogProvider)(nil)
//_ provider.ProviderWithMetadata = (*dogProvider)(nil)
)


func New(version string) func() provider.Provider {
return func() provider.Provider {
return &dogProvider{
Expand Down Expand Up @@ -110,8 +109,8 @@ func (p *dogProvider) Configure(ctx context.Context, req provider.ConfigureReque
if api_endpoint == "" || api_token == "" {
resp.Diagnostics.AddError(
"config values",
fmt.Sprintf("config.Api_Token: %+v\n", config.Api_Token.ValueString() )+
fmt.Sprintf("config.API_Endpoint: %+v\n", config.API_Endpoint.ValueString() )+
fmt.Sprintf("config.Api_Token: %+v\n", config.Api_Token.ValueString())+
fmt.Sprintf("config.API_Endpoint: %+v\n", config.API_Endpoint.ValueString())+
fmt.Sprintf("api_endpoint: %+v\n", api_endpoint)+
fmt.Sprintf("api_token: %+v\n", api_token),
)
Expand All @@ -123,17 +122,17 @@ func (p *dogProvider) Configure(ctx context.Context, req provider.ConfigureReque
if api_endpoint == "" {
resp.Diagnostics.AddError(
"Missing Dog API Endpoint",
"The provider cannot create the Dog API client as there is a missing or empty value for the Dog API endpoint. " +
"Set the API Endpoint value in the configuration or use the DOG_API_ENDPOINT environment variable. " +
"The provider cannot create the Dog API client as there is a missing or empty value for the Dog API endpoint. "+
"Set the API Endpoint value in the configuration or use the DOG_API_ENDPOINT environment variable. "+
"If either is already set, ensure the value is not empty.",
)
}

if api_token == "" {
resp.Diagnostics.AddError(
"Missing Dog API Key",
"The provider cannot create the Dog API client as there is a missing or empty value for the Dog API key. " +
"Set the API Key value in the configuration or use the DOG_API_TOKEN environment variable. " +
"The provider cannot create the Dog API client as there is a missing or empty value for the Dog API key. "+
"Set the API Key value in the configuration or use the DOG_API_TOKEN environment variable. "+
"If either is already set, ensure the value is not empty.",
)
}
Expand Down
22 changes: 11 additions & 11 deletions internal/provider/resource_fact.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
"log"
"regexp"

"github.com/davecgh/go-spew/spew"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
api "github.com/relaypro-open/dog_api_golang/api"
"golang.org/x/exp/slices"
"github.com/davecgh/go-spew/spew"
)

type (
Expand Down Expand Up @@ -64,15 +64,15 @@ func (*factResource) Schema(ctx context.Context, req resource.SchemaRequest, res
// ElementType: types.MapType{ElemType: types.StringType},
//},
"children": schema.ListAttribute{
Required: true,
ElementType: types.StringType,
Required: true,
ElementType: types.StringType,
},
},
},
Required: true,
Required: true,
},
"name": schema.StringAttribute{
Required: true,
Required: true,
Validators: []validator.String{
stringvalidator.LengthBetween(1, 256),
stringvalidator.RegexMatches(
Expand All @@ -82,7 +82,7 @@ func (*factResource) Schema(ctx context.Context, req resource.SchemaRequest, res
},
},
"id": schema.StringAttribute{
Optional: true,
Optional: true,
Computed: true,
},
},
Expand Down Expand Up @@ -113,9 +113,9 @@ func (*factResource) ImportState(ctx context.Context, req resource.ImportStateRe
}

type factResourceData struct {
ID types.String `tfsdk:"id"`
ID types.String `tfsdk:"id"`
Groups map[string]*FactGroup `tfsdk:"groups"`
Name string `tfsdk:"name"`
Name string `tfsdk:"name"`
}

func FactToApiFact(plan Fact) api.Fact {
Expand Down Expand Up @@ -205,7 +205,7 @@ func (r *factResource) Create(ctx context.Context, req resource.CreateRequest, r
if resp.Diagnostics.HasError() {
return
}

tflog.Debug(ctx, spew.Sprint("ZZZfact plan: %#v", plan))
newFact := FactToApiFact(plan)
tflog.Debug(ctx, spew.Sprint("ZZZfact newFact: %#v", newFact))
Expand Down
Loading

0 comments on commit 55a1afc

Please sign in to comment.