Skip to content

Commit

Permalink
Always base64 encode filter content strings
Browse files Browse the repository at this point in the history
handle things like 'true' which are valid base64 strings but still need
to be encoded.
  • Loading branch information
tjschutte committed Mar 5, 2024
1 parent 576446f commit 946d9f6
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions internal/provider/filter_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,9 @@ func (r *FilterResource) Create(ctx context.Context, req resource.CreateRequest,
var createFilter Ambar.CreateFilterRequest
createFilter.Description = plan.Description.ValueStringPointer()

// Filters we encode the content string in base64 for API requests to compact complex filters and prevent white spaces
// from giving any issues. If the customer already encoded the contents, great. But it is not required. So we will
// check if they already did it, and otherwise encode it.
_, err := base64.StdEncoding.DecodeString(plan.FilterContents.ValueString())
if err != nil {
// decoding failed, and we will want to encode and assign
encodedContents := base64.StdEncoding.EncodeToString([]byte(plan.FilterContents.ValueString()))
createFilter.FilterContents = encodedContents
} else {
// customer already base64 encoded, so just pass it on through.
createFilter.FilterContents = plan.FilterContents.ValueString()
}
// Encode the customers filter string
encodedContents := base64.StdEncoding.EncodeToString([]byte(plan.FilterContents.ValueString()))
createFilter.FilterContents = encodedContents

createFilter.DataSourceId = plan.DataSourceId.ValueString()

Expand Down

0 comments on commit 946d9f6

Please sign in to comment.