-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webhook recipient): notification variables (#594)
This adds the notification variable functionality to custom webhooks.
- Loading branch information
1 parent
1b80562
commit f8d71e5
Showing
10 changed files
with
1,025 additions
and
14 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
51 changes: 51 additions & 0 deletions
51
internal/helper/validation/valid_notification_variables.go
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,51 @@ | ||
package validation | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
|
||
"github.com/honeycombio/terraform-provider-honeycombio/internal/models" | ||
) | ||
|
||
var _ validator.Set = notificationVariablesValidator{} | ||
|
||
type notificationVariablesValidator struct{} | ||
|
||
func (v notificationVariablesValidator) Description(_ context.Context) string { | ||
return "value must be a valid set of webhook variables" | ||
} | ||
|
||
func (v notificationVariablesValidator) MarkdownDescription(ctx context.Context) string { | ||
return v.Description(ctx) | ||
} | ||
|
||
func (v notificationVariablesValidator) ValidateSet(ctx context.Context, request validator.SetRequest, response *validator.SetResponse) { | ||
if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { | ||
return | ||
} | ||
|
||
// variable names cannot be duplicated | ||
var variables []models.NotificationVariableModel | ||
response.Diagnostics.Append(request.ConfigValue.ElementsAs(ctx, &variables, false)...) | ||
|
||
duplicateMap := make(map[string]bool) | ||
for i, v := range variables { | ||
name := v.Name.ValueString() | ||
if duplicateMap[name] { | ||
response.Diagnostics.AddAttributeError( | ||
path.Root("variable").AtListIndex(i).AtName("name"), | ||
"Conflicting configuration arguments", | ||
"cannot have more than one \"variable\" with the same \"name\"", | ||
) | ||
} | ||
duplicateMap[name] = true | ||
} | ||
} | ||
|
||
// ValidNotificationVariables determines if the provided recipient notification variables are valid. | ||
// Today this means no variable names are duplicated. | ||
func ValidNotificationVariables() validator.Set { | ||
return notificationVariablesValidator{} | ||
} |
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.