From 217718be7e9bea0d197eb339632375d1ef3caf49 Mon Sep 17 00:00:00 2001 From: Ryan Schumacher Date: Thu, 20 Jun 2024 09:49:52 -0500 Subject: [PATCH 1/2] chore: add friendly reminders if go mod tidy needs to be run (#1001) Co-authored-by: Dave Mihalcik --- .github/workflows/friendly-reminders.yaml | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/friendly-reminders.yaml diff --git a/.github/workflows/friendly-reminders.yaml b/.github/workflows/friendly-reminders.yaml new file mode 100644 index 000000000..90fbbf850 --- /dev/null +++ b/.github/workflows/friendly-reminders.yaml @@ -0,0 +1,41 @@ +name: 👋 Friendly Reminders + +on: + pull_request: + branches: main + +jobs: + job: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Extract go version + id: go-version + run: | + echo "go-version=$(go work edit --json | jq -r '.Go')" >>$GITHUB_OUTPUT + - uses: actions/setup-go@v5 + with: + go-version: ${{ steps.go-version.outputs.go-version }} + + - name: Check Go Mod Tidy + id: go-mod-tidy + run: | + # iterate over work file, cd and run go mod tidy + for line in $(go work edit --json | jq -r '.Use.[].DiskPath'); do + (cd $line && go mod tidy) + done + # check if any changes were made + echo $(git status --porcelain) >> $GITHUB_OUTPUT + + - name: Post comment if go.mod was changed + if: steps.go-mod-tidy.outputs.stdout != '' + uses: actions/github-script@v7 + with: + script: | + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '👋 Friendly reminder: go.mod was changed. Make sure to run `go mod tidy`!\n\n' + + '```\n${{ steps.go-mod-tidy.outputs.stdout }}\n```' + }) From 799eb36e4258fa59e5575602c1bc718be4d2581d Mon Sep 17 00:00:00 2001 From: Elizabeth Healy <35498075+elizabethhealy@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:50:38 -0400 Subject: [PATCH 2/2] chore(authz): Remove dead jq code (#1012) --- service/go.mod | 2 - service/go.sum | 4 - .../internal/subjectmappingbuiltin/jq_eval.go | 61 -------------- .../subjectmappingbuiltin/jq_eval_test.go | 81 ------------------- 4 files changed, 148 deletions(-) delete mode 100644 service/internal/subjectmappingbuiltin/jq_eval.go delete mode 100644 service/internal/subjectmappingbuiltin/jq_eval_test.go diff --git a/service/go.mod b/service/go.mod index f5eb7c451..0f0198d98 100644 --- a/service/go.mod +++ b/service/go.mod @@ -13,7 +13,6 @@ require ( github.com/google/uuid v1.6.0 github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.1 - github.com/itchyny/gojq v0.12.15 github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa github.com/jackc/pgx/v5 v5.5.5 github.com/lestrrat-go/jwx/v2 v2.0.21 @@ -59,7 +58,6 @@ require ( github.com/docker/go-units v0.5.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/google/go-cmp v0.6.0 // indirect - github.com/itchyny/timefmt-go v0.1.5 // indirect github.com/tidwall/gjson v1.17.1 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect diff --git a/service/go.sum b/service/go.sum index 685ff50d1..c95c42650 100644 --- a/service/go.sum +++ b/service/go.sum @@ -173,10 +173,6 @@ github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/itchyny/gojq v0.12.15 h1:WC1Nxbx4Ifw5U2oQWACYz32JK8G9qxNtHzrvW4KEcqI= -github.com/itchyny/gojq v0.12.15/go.mod h1:uWAHCbCIla1jiNxmeT5/B5mOjSdfkCq6p8vxWg+BM10= -github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE= -github.com/itchyny/timefmt-go v0.1.5/go.mod h1:nEP7L+2YmAbT2kZ2HfSs1d8Xtw9LY8D2stDBckWakZ8= github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa h1:s+4MhCQ6YrzisK6hFJUX53drDT4UsSW3DEhKn0ifuHw= github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa/go.mod h1:a/s9Lp5W7n/DD0VrVoyJ00FbP2ytTPDVOivvn2bMlds= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= diff --git a/service/internal/subjectmappingbuiltin/jq_eval.go b/service/internal/subjectmappingbuiltin/jq_eval.go deleted file mode 100644 index 1b4bc4d2d..000000000 --- a/service/internal/subjectmappingbuiltin/jq_eval.go +++ /dev/null @@ -1,61 +0,0 @@ -package subjectmappingbuiltin - -import ( - "log/slog" - "strconv" - - "github.com/itchyny/gojq" -) - -func ExecuteQuery(inputJSON map[string]any, queryString string) ([]any, error) { - // first unescape the query string - unescapedQueryString, err := unescapeQueryString(queryString) - if err != nil { - return nil, err - } - - query, err := gojq.Parse(unescapedQueryString) - if err != nil { - return nil, err - } - iter := query.Run(inputJSON) - found := []any{} - for { - v, ok := iter.Next() - if !ok { - break - } - if err, ok2 := v.(error); ok2 { - //nolint:errorlint // temp following gojq example - if err, ok3 := err.(*gojq.HaltError); ok3 && err.Value() == nil { - break - } - // ignore error: we don't have a match but that is not an error state in this case - } else { - if v != nil { - found = append(found, v) - } - } - } - - return found, nil -} - -// unescape any strings within the provided string -func unescapeQueryString(queryString string) (string, error) { - if queryString == "" { - return "", nil - } - unquotedQueryString, err := strconv.Unquote(queryString) - if err != nil { - if err.Error() == "invalid syntax" { - slog.Debug("invalid syntax error when unquoting means there was nothing to unescape. carry on.", slog.String("queryString", queryString)) - unquotedQueryString = queryString - } else { - slog.Error("failed to unescape double quotes in subject external selector value", slog.String("queryString", queryString), slog.String("error", err.Error())) - return "", err - } - } - slog.Debug("unescaped any double quotes in jq query string", slog.String("queryString", unquotedQueryString)) - return unquotedQueryString, nil -} diff --git a/service/internal/subjectmappingbuiltin/jq_eval_test.go b/service/internal/subjectmappingbuiltin/jq_eval_test.go deleted file mode 100644 index 828f68115..000000000 --- a/service/internal/subjectmappingbuiltin/jq_eval_test.go +++ /dev/null @@ -1,81 +0,0 @@ -package subjectmappingbuiltin_test - -import ( - "testing" - - "github.com/opentdf/platform/service/internal/subjectmappingbuiltin" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -/// JQ evaluation tests - -const jqtestResult1 string = "helloworld" - -var jqtestInput1 = map[string]interface{}{ - "testing1": jqtestResult1, -} -var jqtestQuery1 = ".testing1" - -func Test_JQSuccessSimple(t *testing.T) { - res, err := subjectmappingbuiltin.ExecuteQuery(jqtestInput1, jqtestQuery1) - require.NoError(t, err) - assert.Equal(t, []any{jqtestResult1}, res) -} - -var jqtestInput2 = map[string]interface{}{ - "testing1": map[string]interface{}{"testing2": jqtestResult1}, -} -var jqtestQuery2 = ".testing1.testing2" - -func Test_JQSuccessTwoDeep(t *testing.T) { - res, err := subjectmappingbuiltin.ExecuteQuery(jqtestInput2, jqtestQuery2) - require.NoError(t, err) - assert.Equal(t, []any{jqtestResult1}, res) -} - -var jqtestInput3 = map[string]interface{}{ - "testing1": map[string]interface{}{"testing2": []any{jqtestResult1}}, -} -var jqtestQuery3 = ".testing1.testing2[0]" - -func Test_JQSuccessTwoDeepInArray(t *testing.T) { - res, err := subjectmappingbuiltin.ExecuteQuery(jqtestInput3, jqtestQuery3) - require.NoError(t, err) - assert.Equal(t, []any{jqtestResult1}, res) -} - -const jqtestResult2 string = "whatsup" - -var jqtestInput4 = map[string]interface{}{ - "testing1": map[string]interface{}{"testing2": []any{jqtestResult1, jqtestResult2}}, -} -var jqtestQuery4 = ".testing1.testing2[]" - -func Test_JQSuccessTwoDeepAllInArray(t *testing.T) { - res, err := subjectmappingbuiltin.ExecuteQuery(jqtestInput4, jqtestQuery4) - require.NoError(t, err) - assert.Equal(t, []any{jqtestResult1, jqtestResult2}, res) -} - -var jqtestInput5 = map[string]interface{}{ - "testing1": map[string]interface{}{"testing2": jqtestResult1}, -} -var jqtestQuery5 = ".testing1.testing3" - -func Test_JQSuccessTwoDeepAllNoMatch(t *testing.T) { - res, err := subjectmappingbuiltin.ExecuteQuery(jqtestInput5, jqtestQuery5) - require.NoError(t, err) - assert.Equal(t, []any{}, res) -} - -var jqtestInput6 = map[string]interface{}{ - "testing1": map[string]interface{}{"testing2": []any{jqtestResult1, jqtestResult2}}, -} -var jqtestQuery6 = ".testing1.testing2 | index(\"" + jqtestResult2 + "\")" - -func Test_JQSuccessUnescapeQuote(t *testing.T) { - res, err := subjectmappingbuiltin.ExecuteQuery(jqtestInput6, jqtestQuery6) - require.NoError(t, err) - assert.Equal(t, []any{1}, res) -}