Skip to content

Commit

Permalink
teamClient, teamApi -> platformClient, platformApi
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjohansson committed Sep 27, 2024
1 parent 324d1cf commit fc8b4ea
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/provider-install-verification/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ terraform {
}

provider "ee-platform" {
teams_api = "http://localhost:8080"
platform_api = "localhost:8080"
}

data "ee-platform_teams" "all_teams" {}
Expand Down
10 changes: 5 additions & 5 deletions internal/client/teams.go → internal/client/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ type Team struct {
SnPaasOrg string `json:"snpaas_org"`
}

type TeamsClient interface {
type PlatformClient interface {
GetTeams() (Teams, error)
}

type teamsClient struct {
type platformClient struct {
teamsEndpoint string
}

func (t teamsClient) GetTeams() (teams Teams, err error) {
func (t platformClient) GetTeams() (teams Teams, err error) {
u, err := url.Parse(t.teamsEndpoint)
if err != nil {
return
Expand All @@ -52,8 +52,8 @@ func (t teamsClient) GetTeams() (teams Teams, err error) {
return
}

func NewTeamsClient(teamsEndpoint string) TeamsClient {
return teamsClient{
func NewPlatformClient(teamsEndpoint string) PlatformClient {
return platformClient{
teamsEndpoint: teamsEndpoint,
}
}
10 changes: 5 additions & 5 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ func (p *eePlatformProvider) Metadata(_ context.Context, _ provider.MetadataRequ
}

type EEPlatformProviderModel struct {
TeamsApi types.String `tfsdk:"teams_api"`
TeamsApi types.String `tfsdk:"platform_api"`
}

func (p *eePlatformProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: "Manage EE Platform resources with terraform",
Attributes: map[string]schema.Attribute{
"teams_api": schema.StringAttribute{
"platform_api": schema.StringAttribute{
Optional: true,
},
},
Expand All @@ -59,7 +59,7 @@ func (p *eePlatformProvider) Schema(_ context.Context, _ provider.SchemaRequest,

// Configure prepares a EE Platform API client for data sources and resources.
func (p *eePlatformProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
teamsApi := os.Getenv("TEAMS_API")
teamsApi := os.Getenv("PLATFORM_API")

var data EEPlatformProviderModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
Expand All @@ -70,13 +70,13 @@ func (p *eePlatformProvider) Configure(ctx context.Context, req provider.Configu
} else {
resp.Diagnostics.AddError(
"Missing teams API endpoint",
"While configuring the provider, the teams API endpoint was not found in the TEAMS_API environment variable or provider configuration block teams_api attribute.",
"While configuring the provider, the teams API endpoint was not found in the PLATFORM_API environment variable or provider configuration block platform_api attribute.",
)
return
}
}

resp.DataSourceData = client.NewTeamsClient(teamsApi)
resp.DataSourceData = client.NewPlatformClient(teamsApi)
}

// DataSources defines the data sources implemented in the provider.
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/teams_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewTeamsDataSource() datasource.DataSource {

// teamsDataSource is the data source implementation.
type teamsDataSource struct {
teamsClient client.TeamsClient
platformClient client.PlatformClient
}

// Metadata returns the data source type name.
Expand All @@ -37,7 +37,7 @@ func (d *teamsDataSource) Configure(ctx context.Context, req datasource.Configur
return
}

teamsClient, ok := req.ProviderData.(client.TeamsClient)
platformClient, ok := req.ProviderData.(client.PlatformClient)
if !ok {
resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type",
Expand All @@ -47,7 +47,7 @@ func (d *teamsDataSource) Configure(ctx context.Context, req datasource.Configur
return
}

d.teamsClient = teamsClient
d.platformClient = platformClient
}

// Schema defines the schema for the data source.
Expand Down Expand Up @@ -92,7 +92,7 @@ func (d *teamsDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
}

func (d *teamsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
teams, err := d.teamsClient.GetTeams()
teams, err := d.platformClient.GetTeams()
if err != nil {
resp.Diagnostics.AddError("Unable to fetch teams", err.Error())
}
Expand Down

0 comments on commit fc8b4ea

Please sign in to comment.