Refactor base64gunzip function to be more in line with other functions. (#1077)

Signed-off-by: Jakub Martin <kubam@spacelift.io>
This commit is contained in:
Kuba Martin 2024-01-08 15:05:20 +01:00 committed by GitHub
parent ae22c28289
commit 47c34d05e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 26 additions and 24 deletions

View File

@ -13,7 +13,7 @@ ENHANCEMENTS:
- This change fixes the local state filesystem interface to function as the statemgr API describes. - This change fixes the local state filesystem interface to function as the statemgr API describes.
- A possible side effect is that a hard crash mid-apply will no longer have a in-progress state file to reference. This matches the other state managers. - A possible side effect is that a hard crash mid-apply will no longer have a in-progress state file to reference. This matches the other state managers.
* `tofu console` should work in Solaris and AIX as readline has been updated. ([#632](https://github.com/opentofu/opentofu/pull/632)) * `tofu console` should work in Solaris and AIX as readline has been updated. ([#632](https://github.com/opentofu/opentofu/pull/632))
* Added "base64gunzip" function. ([$800](https://github.com/opentofu/opentofu/issues/800))
BUG FIXES: BUG FIXES:
* `tofu test` resources cleanup at the end of tests changed to use simple reverse run block order. ([#1043](https://github.com/opentofu/opentofu/pull/1043)) * `tofu test` resources cleanup at the end of tests changed to use simple reverse run block order. ([#1043](https://github.com/opentofu/opentofu/pull/1043))

View File

@ -53,8 +53,8 @@ var DescriptionList = map[string]descriptionEntry{
Description: "`base64gzip` compresses a string with gzip and then encodes the result in Base64 encoding.", Description: "`base64gzip` compresses a string with gzip and then encodes the result in Base64 encoding.",
ParamDescription: []string{""}, ParamDescription: []string{""},
}, },
"gunzipbase64": { "base64gunzip": {
Description: "`gunzipbase64` decodes a Base64-encoded string and uncompresses the result with gzip.", Description: "`base64gunzip` decodes a Base64-encoded string and uncompresses the result with gzip.",
ParamDescription: []string{""}, ParamDescription: []string{""},
}, },
"base64sha256": { "base64sha256": {

View File

@ -179,8 +179,8 @@ var Base64GzipFunc = function.New(&function.Spec{
}, },
}) })
// GunzipBase64Func constructs a function that Bae64 decodes a string and decompresses the result with gunzip. // Base64GunzipFunc constructs a function that Bae64 decodes a string and decompresses the result with gunzip.
var GunzipBase64Func = function.New(&function.Spec{ var Base64GunzipFunc = function.New(&function.Spec{
Params: []function.Parameter{ Params: []function.Parameter{
{ {
Name: "str", Name: "str",
@ -260,11 +260,11 @@ func Base64Gzip(str cty.Value) (cty.Value, error) {
return Base64GzipFunc.Call([]cty.Value{str}) return Base64GzipFunc.Call([]cty.Value{str})
} }
// GunzipBase64 decodes a Base64-encoded string and uncompresses the result with gzip. // Base64Gunzip decodes a Base64-encoded string and uncompresses the result with gzip.
// //
// Opentofu uses the "standard" Base64 alphabet as defined in RFC 4648 section 4. // Opentofu uses the "standard" Base64 alphabet as defined in RFC 4648 section 4.
func GunzipBase64(str cty.Value) (cty.Value, error) { func Base64Gunzip(str cty.Value) (cty.Value, error) {
return GunzipBase64Func.Call([]cty.Value{str}) return Base64GunzipFunc.Call([]cty.Value{str})
} }
// URLEncode applies URL encoding to a given string. // URLEncode applies URL encoding to a given string.

View File

@ -7,8 +7,9 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/opentofu/opentofu/internal/lang/marks"
"github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty"
"github.com/opentofu/opentofu/internal/lang/marks"
) )
func TestBase64Decode(t *testing.T) { func TestBase64Decode(t *testing.T) {
@ -159,7 +160,7 @@ func TestBase64Gzip(t *testing.T) {
} }
} }
func TestGunzipBase64(t *testing.T) { func TestBase64Gunzip(t *testing.T) {
tests := []struct { tests := []struct {
String cty.Value String cty.Value
Want cty.Value Want cty.Value
@ -173,8 +174,8 @@ func TestGunzipBase64(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(fmt.Sprintf("gunzipbase64(%#v)", test.String), func(t *testing.T) { t.Run(fmt.Sprintf("base64gunzip(%#v)", test.String), func(t *testing.T) {
got, err := GunzipBase64(test.String) got, err := Base64Gunzip(test.String)
if test.Err { if test.Err {
if err == nil { if err == nil {

View File

@ -43,7 +43,7 @@ func (s *Scope) Functions() map[string]function.Function {
"base64decode": funcs.Base64DecodeFunc, "base64decode": funcs.Base64DecodeFunc,
"base64encode": funcs.Base64EncodeFunc, "base64encode": funcs.Base64EncodeFunc,
"base64gzip": funcs.Base64GzipFunc, "base64gzip": funcs.Base64GzipFunc,
"gunzipbase64": funcs.GunzipBase64Func, "base64gunzip": funcs.Base64GunzipFunc,
"base64sha256": funcs.Base64Sha256Func, "base64sha256": funcs.Base64Sha256Func,
"base64sha512": funcs.Base64Sha512Func, "base64sha512": funcs.Base64Sha512Func,
"bcrypt": funcs.BcryptFunc, "bcrypt": funcs.BcryptFunc,

View File

@ -13,9 +13,10 @@ import (
"github.com/hashicorp/hcl/v2" "github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax" "github.com/hashicorp/hcl/v2/hclsyntax"
homedir "github.com/mitchellh/go-homedir" homedir "github.com/mitchellh/go-homedir"
"github.com/zclconf/go-cty/cty"
"github.com/opentofu/opentofu/internal/experiments" "github.com/opentofu/opentofu/internal/experiments"
"github.com/opentofu/opentofu/internal/lang/marks" "github.com/opentofu/opentofu/internal/lang/marks"
"github.com/zclconf/go-cty/cty"
) )
// TestFunctions tests that functions are callable through the functionality // TestFunctions tests that functions are callable through the functionality
@ -108,9 +109,9 @@ func TestFunctions(t *testing.T) {
}, },
}, },
"gunzipbase64": { "base64gunzip": {
{ {
`gunzipbase64("H4sIAAAAAAAA/ypJLS4BAAAA//8BAAD//wx+f9gEAAAA")`, `base64gunzip("H4sIAAAAAAAA/ypJLS4BAAAA//8BAAD//wx+f9gEAAAA")`,
cty.StringVal("test"), cty.StringVal("test"),
}, },
}, },

View File

@ -518,8 +518,8 @@
"path": "language/functions/csvdecode" "path": "language/functions/csvdecode"
}, },
{ {
"title": "<code>gunzipbase64</code>", "title": "<code>base64gunzip</code>",
"path": "language/functions/gunzipbase64" "path": "language/functions/base64gunzip"
}, },
{ {
"title": "<code>jsondecode</code>", "title": "<code>jsondecode</code>",
@ -932,8 +932,8 @@
"hidden": true "hidden": true
}, },
{ {
"title": "gunzipbase64", "title": "base64gunzip",
"path": "language/functions/gunzipbase64", "path": "language/functions/base64gunzip",
"hidden": true "hidden": true
}, },
{ {

View File

@ -1,12 +1,12 @@
--- ---
page_title: gunzipbase64 - Functions - Configuration Language page_title: base64gunzip - Functions - Configuration Language
description: |- description: |-
The gunzipbase64 funtion decodes a Base64-encoded string and uncompresses the result with gzip. The base64gunzip funtion decodes a Base64-encoded string and uncompresses the result with gzip.
--- ---
# `gunzipbase64` Function # `base64gunzip` Function
`gunzipbase64` decodes a Base64-encoded string and uncompresses the result with gzip. `base64gunzip` decodes a Base64-encoded string and uncompresses the result with gzip.
Opentofu uses the "standard" Base64 alphabet as defined in Opentofu uses the "standard" Base64 alphabet as defined in
[RFC 4648 section 4](https://tools.ietf.org/html/rfc4648#section-4). [RFC 4648 section 4](https://tools.ietf.org/html/rfc4648#section-4).