Skip to content

Commit

Permalink
golines provider
Browse files Browse the repository at this point in the history
  • Loading branch information
1riatsila1 committed Oct 31, 2024
1 parent bce281d commit 975e46b
Show file tree
Hide file tree
Showing 38 changed files with 2,037 additions and 435 deletions.
7 changes: 6 additions & 1 deletion pkg/config-api-provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ var (
func main() {
var debug bool

flag.BoolVar(&debug, "debug", false, "set to true to run the provider with support for debuggers like delve")
flag.BoolVar(
&debug,
"debug",
false,
"set to true to run the provider with support for debuggers like delve",
)
flag.Parse()

opts := providerserver.ServeOpts{
Expand Down
24 changes: 20 additions & 4 deletions pkg/config-api-provider/provider/data-sources/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ type agentDataSourceModel struct {
} `tfsdk:"filter"`
}

func (d *agentDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (d *agentDataSource) Metadata(
_ context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
) {
resp.TypeName = req.ProviderTypeName + "_agent"
}

func (d *agentDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *agentDataSource) Schema(
_ context.Context,
_ datasource.SchemaRequest,
resp *datasource.SchemaResponse,
) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Expand Down Expand Up @@ -92,7 +100,11 @@ func (d *agentDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
}
}

func (d *agentDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (d *agentDataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
var state agentDataSourceModel

// Read configuration from request
Expand Down Expand Up @@ -139,7 +151,11 @@ func (d *agentDataSource) Read(ctx context.Context, req datasource.ReadRequest,
}
}

func (d *agentDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (d *agentDataSource) Configure(
_ context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
) {
// Add a nil check when handling ProviderData because Terraform
// sets that data after it calls the ConfigureProvider RPC.
if req.ProviderData == nil {
Expand Down
24 changes: 20 additions & 4 deletions pkg/config-api-provider/provider/data-sources/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ type groupDataSourceModel struct {
} `tfsdk:"filter"`
}

func (d *groupDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (d *groupDataSource) Metadata(
_ context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
) {
resp.TypeName = req.ProviderTypeName + "_group"
}

func (d *groupDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *groupDataSource) Schema(
_ context.Context,
_ datasource.SchemaRequest,
resp *datasource.SchemaResponse,
) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Expand All @@ -64,7 +72,11 @@ func (d *groupDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
}
}

func (d *groupDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (d *groupDataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
var state groupDataSourceModel

// Read configuration from request
Expand Down Expand Up @@ -112,7 +124,11 @@ func (d *groupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
}
}

func (d *groupDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (d *groupDataSource) Configure(
_ context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
) {
// Add a nil check when handling ProviderData because Terraform
// sets that data after it calls the ConfigureProvider RPC.
if req.ProviderData == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@ type networkGroupAssignmentDataSourceModel struct {
} `tfsdk:"filter"`
}

func (d *networkGroupAssignmentDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (d *networkGroupAssignmentDataSource) Metadata(
_ context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
) {
resp.TypeName = req.ProviderTypeName + "_network_group_assignment"
}

func (d *networkGroupAssignmentDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *networkGroupAssignmentDataSource) Schema(
_ context.Context,
_ datasource.SchemaRequest,
resp *datasource.SchemaResponse,
) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Expand All @@ -60,7 +68,11 @@ func (d *networkGroupAssignmentDataSource) Schema(_ context.Context, _ datasourc
}
}

func (d *networkGroupAssignmentDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (d *networkGroupAssignmentDataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
var state networkGroupAssignmentDataSourceModel

diags := req.Config.Get(ctx, &state)
Expand Down Expand Up @@ -99,7 +111,11 @@ func (d *networkGroupAssignmentDataSource) Read(ctx context.Context, req datasou
}
}

func (d *networkGroupAssignmentDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (d *networkGroupAssignmentDataSource) Configure(
_ context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
) {
if req.ProviderData == nil {
return
}
Expand Down
24 changes: 20 additions & 4 deletions pkg/config-api-provider/provider/data-sources/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ type sensorDataSourceModel struct {
} `tfsdk:"filter"`
}

func (d *sensorDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (d *sensorDataSource) Metadata(
_ context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
) {
resp.TypeName = req.ProviderTypeName + "_sensor"
}

func (d *sensorDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *sensorDataSource) Schema(
_ context.Context,
_ datasource.SchemaRequest,
resp *datasource.SchemaResponse,
) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Expand Down Expand Up @@ -92,7 +100,11 @@ func (d *sensorDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
}
}

func (d *sensorDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (d *sensorDataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
var state sensorDataSourceModel

// Read configuration from request
Expand Down Expand Up @@ -142,7 +154,11 @@ func (d *sensorDataSource) Read(ctx context.Context, req datasource.ReadRequest,
}
}

func (d *sensorDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (d *sensorDataSource) Configure(
_ context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
) {
// Add a nil check when handling ProviderData because Terraform
// sets that data after it calls the ConfigureProvider RPC.
if req.ProviderData == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ type sensorGroupAssignmentDataSourceModel struct {
} `tfsdk:"filter"`
}

func (d *sensorGroupAssignmentDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (d *sensorGroupAssignmentDataSource) Metadata(
_ context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
) {
resp.TypeName = req.ProviderTypeName + "_sensor_group_assignment"
}

func (d *sensorGroupAssignmentDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *sensorGroupAssignmentDataSource) Schema(
_ context.Context,
_ datasource.SchemaRequest,
resp *datasource.SchemaResponse,
) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Expand All @@ -61,7 +69,11 @@ func (d *sensorGroupAssignmentDataSource) Schema(_ context.Context, _ datasource
}
}

func (d *sensorGroupAssignmentDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (d *sensorGroupAssignmentDataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
var state sensorGroupAssignmentDataSourceModel

// Read configuration from request
Expand Down Expand Up @@ -102,7 +114,11 @@ func (d *sensorGroupAssignmentDataSource) Read(ctx context.Context, req datasour
}
}

func (d *sensorGroupAssignmentDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (d *sensorGroupAssignmentDataSource) Configure(
_ context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
) {
// Add a nil check when handling ProviderData because Terraform
// sets that data after it calls the ConfigureProvider RPC.
if req.ProviderData == nil {
Expand Down
24 changes: 20 additions & 4 deletions pkg/config-api-provider/provider/data-sources/wired_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ type wiredNetworkDataSourceModel struct {
} `tfsdk:"filter"`
}

func (d *wiredNetworkDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (d *wiredNetworkDataSource) Metadata(
_ context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
) {
resp.TypeName = req.ProviderTypeName + "_wired_network"
}

func (d *wiredNetworkDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *wiredNetworkDataSource) Schema(
_ context.Context,
_ datasource.SchemaRequest,
resp *datasource.SchemaResponse,
) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Expand Down Expand Up @@ -86,7 +94,11 @@ func (d *wiredNetworkDataSource) Schema(_ context.Context, _ datasource.SchemaRe
}
}

func (d *wiredNetworkDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (d *wiredNetworkDataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
var state wiredNetworkDataSourceModel

// Read configuration from request
Expand Down Expand Up @@ -133,7 +145,11 @@ func (d *wiredNetworkDataSource) Read(ctx context.Context, req datasource.ReadRe
}
}

func (d *wiredNetworkDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (d *wiredNetworkDataSource) Configure(
_ context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
) {
// Add a nil check when handling ProviderData because Terraform
// sets that data after it calls the ConfigureProvider RPC.
if req.ProviderData == nil {
Expand Down
24 changes: 20 additions & 4 deletions pkg/config-api-provider/provider/data-sources/wireless_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,19 @@ type wirelessNetworkDataSourceModel struct {
} `tfsdk:"filter"`
}

func (d *wirelessNetworkDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
func (d *wirelessNetworkDataSource) Metadata(
_ context.Context,
req datasource.MetadataRequest,
resp *datasource.MetadataResponse,
) {
resp.TypeName = req.ProviderTypeName + "_wireless_network"
}

func (d *wirelessNetworkDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *wirelessNetworkDataSource) Schema(
_ context.Context,
_ datasource.SchemaRequest,
resp *datasource.SchemaResponse,
) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Expand Down Expand Up @@ -94,7 +102,11 @@ func (d *wirelessNetworkDataSource) Schema(_ context.Context, _ datasource.Schem
}
}

func (d *wirelessNetworkDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (d *wirelessNetworkDataSource) Read(
ctx context.Context,
req datasource.ReadRequest,
resp *datasource.ReadResponse,
) {
var state wirelessNetworkDataSourceModel

// Read configuration from request
Expand Down Expand Up @@ -143,7 +155,11 @@ func (d *wirelessNetworkDataSource) Read(ctx context.Context, req datasource.Rea
}
}

func (d *wirelessNetworkDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
func (d *wirelessNetworkDataSource) Configure(
_ context.Context,
req datasource.ConfigureRequest,
resp *datasource.ConfigureResponse,
) {
// Add a nil check when handling ProviderData because Terraform
// sets that data after it calls the ConfigureProvider RPC.
if req.ProviderData == nil {
Expand Down
18 changes: 15 additions & 3 deletions pkg/config-api-provider/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,21 @@ type uxiConfigurationProvider struct {
}

// Metadata returns the provider type name.
func (p *uxiConfigurationProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) {
func (p *uxiConfigurationProvider) Metadata(
_ context.Context,
_ provider.MetadataRequest,
resp *provider.MetadataResponse,
) {
resp.TypeName = "uxi"
resp.Version = p.version
}

// Schema defines the provider-level schema for configuration data.
func (p *uxiConfigurationProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
func (p *uxiConfigurationProvider) Schema(
_ context.Context,
_ provider.SchemaRequest,
resp *provider.SchemaResponse,
) {
resp.Schema = schema.Schema{Attributes: map[string]schema.Attribute{
"host": schema.StringAttribute{Optional: true},
"client_id": schema.StringAttribute{Optional: true},
Expand All @@ -69,7 +77,11 @@ func (p *uxiConfigurationProvider) Schema(_ context.Context, _ provider.SchemaRe

// TODO: Obtain a greenlake access token
// Configure prepares a Configuration API client for data sources and resources.
func (p *uxiConfigurationProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
func (p *uxiConfigurationProvider) Configure(
ctx context.Context,
req provider.ConfigureRequest,
resp *provider.ConfigureResponse,
) {
// Init
var config uxiProviderModel
diags := req.Config.Get(ctx, &config)
Expand Down
Loading

0 comments on commit 975e46b

Please sign in to comment.