Skip to content

Commit

Permalink
Add Vault's structured encrypt/decrypt APIs (GEA-11388) (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenany authored Jan 10, 2024
1 parent 32e8390 commit f59e7c9
Show file tree
Hide file tree
Showing 31 changed files with 236 additions and 52 deletions.
4 changes: 2 additions & 2 deletions pangea-sdk/v3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ TEST_TIMEOUT=-timeout 5m
###################
unit:
@echo "Started unit tests"
go test ${TEST_TIMEOUT} -v -count=1 -race ${SDK_ALL_PKGS}
go test ${TEST_TIMEOUT} -tags=unit -v -count=1 -race ${SDK_ALL_PKGS}
@echo "Finished unit tests"

#######################
# Integration Testing #
#######################
integration:
@echo "Started integration tests"
go test -count=1 -tags "integration" -v -run '^Test_Integration' ./service/...
go test -count=1 -tags integration -v ./service/...
@echo "Finished integration tests"

coverage.out: $(shell find . -type f -print | grep -v vendor | grep "\.go")
Expand Down
10 changes: 5 additions & 5 deletions pangea-sdk/v3/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ module github.com/pangeacyber/pangea-go/pangea-sdk/v3
go 1.18

require (
github.com/hashicorp/go-retryablehttp v0.7.2
github.com/rs/zerolog v1.29.1
github.com/stretchr/testify v1.8.2
github.com/hashicorp/go-retryablehttp v0.7.5
github.com/rs/zerolog v1.31.0
github.com/stretchr/testify v1.8.4
golang.org/x/crypto v0.17.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.15.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
36 changes: 16 additions & 20 deletions pangea-sdk/v3/go.sum
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0=
github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M=
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc=
github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3 changes: 2 additions & 1 deletion pangea-sdk/v3/internal/pangeatesting/integration.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// go:build integration
//go:build integration

package pangeatesting

import (
Expand Down
2 changes: 2 additions & 0 deletions pangea-sdk/v3/internal/pangeautil/pangeautil_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package pangeautil_test

import (
Expand Down
2 changes: 2 additions & 0 deletions pangea-sdk/v3/internal/signer/signer_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package signer_test

import (
Expand Down
2 changes: 2 additions & 0 deletions pangea-sdk/v3/pangea/convert_types_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package pangea_test

import (
Expand Down
2 changes: 2 additions & 0 deletions pangea-sdk/v3/pangea/error_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package pangea_test

import (
Expand Down
2 changes: 2 additions & 0 deletions pangea-sdk/v3/pangea/filters_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package pangea_test

import (
Expand Down
2 changes: 2 additions & 0 deletions pangea-sdk/v3/pangea/pangea_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package pangea_test

import (
Expand Down
2 changes: 2 additions & 0 deletions pangea-sdk/v3/pangea/response_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package pangea_test

import (
Expand Down
2 changes: 2 additions & 0 deletions pangea-sdk/v3/pangea/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package pangea_test

import (
Expand Down
2 changes: 2 additions & 0 deletions pangea-sdk/v3/service/audit/api_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package audit_test

import (
Expand Down
3 changes: 2 additions & 1 deletion pangea-sdk/v3/service/audit/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// go:build integration && !unit
//go:build integration

package audit_test

import (
Expand Down
5 changes: 3 additions & 2 deletions pangea-sdk/v3/service/authn/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// go:build integration && !unit
//go:build integration

package authn_test

import (
Expand Down Expand Up @@ -27,7 +28,7 @@ var PROFILE_NEW = map[string]string{}
var PASSWORD_OLD string
var PASSWORD_NEW string
var timeNow = time.Now()
var timeStr = timeNow.Format("yyyyMMdd_HHmmss")
var timeStr = timeNow.Format("20060102_150405")
var CB_URI = "https://someurl.com/callbacklink"

const (
Expand Down
3 changes: 2 additions & 1 deletion pangea-sdk/v3/service/authn/unit_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// go:build integration && !unit
//go:build unit

package authn_test

import (
Expand Down
3 changes: 2 additions & 1 deletion pangea-sdk/v3/service/domain_intel/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// go:build integration
//go:build integration

package domain_intel_test

import (
Expand Down
2 changes: 2 additions & 0 deletions pangea-sdk/v3/service/embargo/api_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package embargo_test

import (
Expand Down
3 changes: 2 additions & 1 deletion pangea-sdk/v3/service/embargo/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// go:build integration
//go:build integration

package embargo_test

import (
Expand Down
3 changes: 2 additions & 1 deletion pangea-sdk/v3/service/file_intel/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// go:build integration
//go:build integration

package file_intel_test

import (
Expand Down
3 changes: 2 additions & 1 deletion pangea-sdk/v3/service/file_scan/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// go:build integration
//go:build integration

package file_scan_test

import (
Expand Down
3 changes: 2 additions & 1 deletion pangea-sdk/v3/service/ip_intel/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// go:build integration
//go:build integration

package ip_intel_test

import (
Expand Down
2 changes: 2 additions & 0 deletions pangea-sdk/v3/service/redact/api_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unit

package redact_test

import (
Expand Down
3 changes: 2 additions & 1 deletion pangea-sdk/v3/service/redact/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// go:build unit
//go:build integration

package redact_test

import (
Expand Down
3 changes: 2 additions & 1 deletion pangea-sdk/v3/service/url_intel/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// go:build integration
//go:build integration

package url_intel_test

import (
Expand Down
3 changes: 2 additions & 1 deletion pangea-sdk/v3/service/user_intel/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// go:build integration
//go:build integration

package user_intel_test

import (
Expand Down
50 changes: 50 additions & 0 deletions pangea-sdk/v3/service/vault/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,53 @@ func (v *vault) JWTVerify(ctx context.Context, input *JWTVerifyRequest) (*pangea
func (v *vault) FolderCreate(ctx context.Context, input *FolderCreateRequest) (*pangea.PangeaResponse[FolderCreateResult], error) {
return request.DoPost(ctx, v.Client, "v1/folder/create", input, &FolderCreateResult{})
}

// @summary Encrypt structured
//
// @description Encrypt parts of a JSON object.
//
// @operationId vault_post_v1_key_encrypt_structured
//
// @example
//
// data := map[string]interface{}{
// "field1": [4]interface{}{1, 2, "true", "false"},
// "field2": "true",
// }
//
// encryptedResponse, err := client.EncryptStructured(
// ctx,
// &vault.EncryptStructuredRequest{
// ID: "pvi_[...]",
// StructuredData: data,
// Filter: "$.field1[2:4]",
// },
// )
func (v *vault) EncryptStructured(ctx context.Context, input *EncryptStructuredRequest) (*pangea.PangeaResponse[EncryptStructuredResult], error) {
return request.DoPost(ctx, v.Client, "v1/key/encrypt/structured", input, &EncryptStructuredResult{})
}

// @summary Decrypt structured
//
// @description Decrypt parts of a JSON object.
//
// @operationId vault_post_v1_key_decrypt_structured
//
// @example
//
// data := map[string]interface{}{
// "field1": [4]interface{}{1, 2, "kxcbC9E9IlgVaSCChPWUMgUC3ko=", "6FfI/LCzatLRLNAc8SuBK/TDnGxp"},
// "field2": "true",
// }
//
// decryptedResponse, err := client.DecryptStructured(
// ctx,
// &vault.EncryptStructuredRequest{
// ID: "pvi_[...]",
// StructuredData: data,
// Filter: "$.field1[2:4]",
// },
// )
func (v *vault) DecryptStructured(ctx context.Context, input *EncryptStructuredRequest) (*pangea.PangeaResponse[EncryptStructuredResult], error) {
return request.DoPost(ctx, v.Client, "v1/key/decrypt/structured", input, &EncryptStructuredResult{})
}
Loading

0 comments on commit f59e7c9

Please sign in to comment.