-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Ignore name attribute in issue alert conditions (#483)
- Loading branch information
Showing
13 changed files
with
187 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package provider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/jianyuan/go-sentry/v2/sentry" | ||
) | ||
|
||
var _ datasource.DataSource = &OrganizationDataSource{} | ||
var _ datasource.DataSourceWithConfigure = &OrganizationDataSource{} | ||
|
||
type OrganizationDataSourceModel struct { | ||
Id types.String `tfsdk:"id"` | ||
Slug types.String `tfsdk:"slug"` | ||
Name types.String `tfsdk:"name"` | ||
InternalId types.String `tfsdk:"internal_id"` | ||
} | ||
|
||
func (m *OrganizationDataSourceModel) Fill(org sentry.Organization) error { | ||
m.Id = types.StringPointerValue(org.Slug) | ||
m.Slug = types.StringPointerValue(org.Slug) | ||
m.Name = types.StringPointerValue(org.Name) | ||
m.InternalId = types.StringPointerValue(org.ID) | ||
|
||
return nil | ||
} | ||
|
||
func NewOrganizationDataSource() datasource.DataSource { | ||
return &OrganizationDataSource{} | ||
} | ||
|
||
type OrganizationDataSource struct { | ||
baseDataSource | ||
} | ||
|
||
func (d *OrganizationDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_organization" | ||
} | ||
|
||
func (d *OrganizationDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
MarkdownDescription: "Sentry Organization data source.", | ||
|
||
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
MarkdownDescription: "The unique URL slug for this organization.", | ||
Computed: true, | ||
}, | ||
"slug": schema.StringAttribute{ | ||
MarkdownDescription: "The unique URL slug for this organization.", | ||
Required: true, | ||
}, | ||
"internal_id": schema.StringAttribute{ | ||
MarkdownDescription: "The internal ID for this organization.", | ||
Computed: true, | ||
}, | ||
"name": schema.StringAttribute{ | ||
MarkdownDescription: "The human readable name for this organization.", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *OrganizationDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var data OrganizationDataSourceModel | ||
|
||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
org, apiResp, err := d.client.Organizations.Get(ctx, data.Slug.ValueString()) | ||
if apiResp.StatusCode == http.StatusNotFound { | ||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Not found: %s", err.Error())) | ||
return | ||
} | ||
if err != nil { | ||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Read error: %s", err.Error())) | ||
return | ||
} | ||
|
||
if err := data.Fill(*org); err != nil { | ||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Fill error: %s", err)) | ||
return | ||
} | ||
|
||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.