Skip to content

Commit

Permalink
syncing up to 76d00866ace4ed65746d545573ba275d91e856fb
Browse files Browse the repository at this point in the history
Co-authored-by: Bruce Yu <[email protected]>
  • Loading branch information
superblocksadmin and bruce-y committed Nov 15, 2024
1 parent 7054c86 commit 3798f86
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 102 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add support for machine-to-machine (M2M) authentication for Databricks plugin
- Update `WaitGroup` runnable to block `Close` method on the `WaitGroup` completing (addresses `redis: client is closed` errors)
- Allow branch name to be given in workflow HTTP requests as a header: `X-Superblocks-Branch`
- Add `last_updated` field to the `Resource` proto, and set last updated time in update signature requests to server

## v1.16.0

Expand Down
10 changes: 6 additions & 4 deletions internal/signature/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
pbsecurity "github.com/superblocksteam/agent/types/gen/go/security/v1"
pbutils "github.com/superblocksteam/agent/types/gen/go/utils/v1"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"

"go.uber.org/zap"
)
Expand Down Expand Up @@ -333,14 +334,14 @@ func (r *reconciler) prep(log *zap.Logger, resources []*signingResult) prepped {
fullResId := strings.TrimLeft(strings.Join([]string{resType, resId}, "-"), "-")

if res.GetApiLiteral() != nil {
update, err := r.updateFromApiLiteral(resId, result, res.GetApiLiteral().GetData().GetStructValue())
update, err := r.updateFromApiLiteral(resId, result, res.GetApiLiteral().GetData().GetStructValue(), res.GetLastUpdated())
if err != nil {
log.Error("error building patch from api literal", zap.Error(err), zap.String(observability.OBS_TAG_RESOURCE_ID, fullResId))
continue
}
prepped.apiUpdates = append(prepped.apiUpdates, update)
} else if res.GetApi() != nil {
update, err := r.updateFromApiLiteral(resId, result, res.GetApi().GetStructValue())
update, err := r.updateFromApiLiteral(resId, result, res.GetApi().GetStructValue(), res.GetLastUpdated())
if err != nil {
log.Error("error building patch from api", zap.Error(err), zap.String(observability.OBS_TAG_RESOURCE_ID, fullResId))
continue
Expand Down Expand Up @@ -383,9 +384,10 @@ func (r *reconciler) prep(log *zap.Logger, resources []*signingResult) prepped {
return prepped
}

func (r *reconciler) updateFromApiLiteral(id string, res *signingResult, api *structpb.Struct) (*pbapi.UpdateApiSignature, error) {
func (r *reconciler) updateFromApiLiteral(id string, res *signingResult, api *structpb.Struct, lastUpdated *timestamppb.Timestamp) (*pbapi.UpdateApiSignature, error) {
update := &pbapi.UpdateApiSignature{
ApiId: id,
ApiId: id,
Updated: lastUpdated,
}
errs := []error{res.err}

Expand Down
37 changes: 36 additions & 1 deletion internal/signature/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protocmp"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
Expand Down Expand Up @@ -715,12 +716,46 @@ func TestPatchFromApiLiteralMissingSignature(t *testing.T) {
require.NoError(t, err)

resource := &pbsecurity.Resource{
LastUpdated: &timestamppb.Timestamp{Seconds: 1},
Config: &pbsecurity.Resource_Api{
Api: structpb.NewStructValue(apiNoSig),
},
}

patchApi, err := args.reconciler.updateFromApiLiteral(apiId, &signingResult{resource: resource}, apiNoSig)
patchApi, err := args.reconciler.updateFromApiLiteral(apiId, &signingResult{resource: resource}, apiNoSig, nil)
require.NoError(t, err)
require.NotNil(t, patchApi)
require.NotNil(t, patchApi.GetResult())
require.Nil(t, patchApi.GetUpdated())
}

func TestUpdateFromApiLiteral(t *testing.T) {
t.Parallel()

args := validArgs(t)
apiId := "0"
api, err := structpb.NewStruct(map[string]any{
"blocks": map[string]any{},
"metadata": map[string]any{
"id": apiId,
},
})
require.NoError(t, err)

resource := &pbsecurity.Resource{
LastUpdated: &timestamppb.Timestamp{Seconds: 1},
Config: &pbsecurity.Resource_ApiLiteral_{
ApiLiteral: &pbsecurity.Resource_ApiLiteral{
Data: structpb.NewStructValue(api),
},
},
}
err = args.signer.SignAndUpdateResource(resource)
require.NoError(t, err)

patchApi, err := args.reconciler.updateFromApiLiteral(apiId, &signingResult{resource: resource}, api, resource.GetLastUpdated())
require.NoError(t, err)
require.NotNil(t, patchApi)
require.NotNil(t, patchApi.GetResult())
require.NotNil(t, patchApi.GetUpdated())
}
2 changes: 1 addition & 1 deletion types/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BUF_VERSION = "1.45.0"
.ONESHELL:

PYTHON_CMD = python3.10
PYTHON_CMD = python
# ":" delimited string of paths
PYTHONPATH=.:superblocks_types

Expand Down
4 changes: 4 additions & 0 deletions types/api/security/v1/service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@
},
"branchName": {
"type": "string"
},
"lastUpdated": {
"type": "string",
"format": "date-time"
}
}
},
Expand Down
Loading

0 comments on commit 3798f86

Please sign in to comment.