Skip to content

Commit

Permalink
Apply suggestions after review
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Apr 11, 2022
1 parent 1e0edc9 commit 31fe8f5
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 240 deletions.
7 changes: 7 additions & 0 deletions hub-js/proto/storage_backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ message OnDeleteRequest {
message OnDeleteResponse {}

message OnDeleteRevisionRequest {
string type_instance_id = 1;
optional string owner_id = 3;
uint32 resource_version = 4;
}

message OnDeleteRevisionValueAndContextRequest {
string type_instance_id = 1;
optional bytes context = 2;
optional string owner_id = 3;
Expand Down Expand Up @@ -119,6 +125,7 @@ service ValueAndContextStorageBackend {
rpc OnCreate(OnCreateValueAndContextRequest) returns (OnCreateResponse);
rpc OnUpdate(OnUpdateValueAndContextRequest) returns (OnUpdateResponse);
rpc OnDelete(OnDeleteValueAndContextRequest) returns (OnDeleteResponse);
rpc OnDeleteRevision(OnDeleteRevisionValueAndContextRequest) returns (OnDeleteRevisionResponse);

// lock
rpc GetLockedBy(GetLockedByRequest) returns (GetLockedByResponse);
Expand Down
113 changes: 104 additions & 9 deletions hub-js/src/generated/grpc/storage_backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export interface OnDeleteRequest {
export interface OnDeleteResponse {}

export interface OnDeleteRevisionRequest {
typeInstanceId: string;
ownerId?: string | undefined;
resourceVersion: number;
}

export interface OnDeleteRevisionValueAndContextRequest {
typeInstanceId: string;
context?: Uint8Array | undefined;
ownerId?: string | undefined;
Expand Down Expand Up @@ -995,6 +1001,87 @@ export const OnDeleteResponse = {
};

function createBaseOnDeleteRevisionRequest(): OnDeleteRevisionRequest {
return { typeInstanceId: "", ownerId: undefined, resourceVersion: 0 };
}

export const OnDeleteRevisionRequest = {
encode(
message: OnDeleteRevisionRequest,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.typeInstanceId !== "") {
writer.uint32(10).string(message.typeInstanceId);
}
if (message.ownerId !== undefined) {
writer.uint32(26).string(message.ownerId);
}
if (message.resourceVersion !== 0) {
writer.uint32(32).uint32(message.resourceVersion);
}
return writer;
},

decode(
input: _m0.Reader | Uint8Array,
length?: number
): OnDeleteRevisionRequest {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseOnDeleteRevisionRequest();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.typeInstanceId = reader.string();
break;
case 3:
message.ownerId = reader.string();
break;
case 4:
message.resourceVersion = reader.uint32();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},

fromJSON(object: any): OnDeleteRevisionRequest {
return {
typeInstanceId: isSet(object.typeInstanceId)
? String(object.typeInstanceId)
: "",
ownerId: isSet(object.ownerId) ? String(object.ownerId) : undefined,
resourceVersion: isSet(object.resourceVersion)
? Number(object.resourceVersion)
: 0,
};
},

toJSON(message: OnDeleteRevisionRequest): unknown {
const obj: any = {};
message.typeInstanceId !== undefined &&
(obj.typeInstanceId = message.typeInstanceId);
message.ownerId !== undefined && (obj.ownerId = message.ownerId);
message.resourceVersion !== undefined &&
(obj.resourceVersion = Math.round(message.resourceVersion));
return obj;
},

fromPartial(
object: DeepPartial<OnDeleteRevisionRequest>
): OnDeleteRevisionRequest {
const message = createBaseOnDeleteRevisionRequest();
message.typeInstanceId = object.typeInstanceId ?? "";
message.ownerId = object.ownerId ?? undefined;
message.resourceVersion = object.resourceVersion ?? 0;
return message;
},
};

function createBaseOnDeleteRevisionValueAndContextRequest(): OnDeleteRevisionValueAndContextRequest {
return {
typeInstanceId: "",
context: undefined,
Expand All @@ -1003,9 +1090,9 @@ function createBaseOnDeleteRevisionRequest(): OnDeleteRevisionRequest {
};
}

export const OnDeleteRevisionRequest = {
export const OnDeleteRevisionValueAndContextRequest = {
encode(
message: OnDeleteRevisionRequest,
message: OnDeleteRevisionValueAndContextRequest,
writer: _m0.Writer = _m0.Writer.create()
): _m0.Writer {
if (message.typeInstanceId !== "") {
Expand All @@ -1026,10 +1113,10 @@ export const OnDeleteRevisionRequest = {
decode(
input: _m0.Reader | Uint8Array,
length?: number
): OnDeleteRevisionRequest {
): OnDeleteRevisionValueAndContextRequest {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseOnDeleteRevisionRequest();
const message = createBaseOnDeleteRevisionValueAndContextRequest();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
Expand All @@ -1053,7 +1140,7 @@ export const OnDeleteRevisionRequest = {
return message;
},

fromJSON(object: any): OnDeleteRevisionRequest {
fromJSON(object: any): OnDeleteRevisionValueAndContextRequest {
return {
typeInstanceId: isSet(object.typeInstanceId)
? String(object.typeInstanceId)
Expand All @@ -1068,7 +1155,7 @@ export const OnDeleteRevisionRequest = {
};
},

toJSON(message: OnDeleteRevisionRequest): unknown {
toJSON(message: OnDeleteRevisionValueAndContextRequest): unknown {
const obj: any = {};
message.typeInstanceId !== undefined &&
(obj.typeInstanceId = message.typeInstanceId);
Expand All @@ -1084,9 +1171,9 @@ export const OnDeleteRevisionRequest = {
},

fromPartial(
object: DeepPartial<OnDeleteRevisionRequest>
): OnDeleteRevisionRequest {
const message = createBaseOnDeleteRevisionRequest();
object: DeepPartial<OnDeleteRevisionValueAndContextRequest>
): OnDeleteRevisionValueAndContextRequest {
const message = createBaseOnDeleteRevisionValueAndContextRequest();
message.typeInstanceId = object.typeInstanceId ?? "";
message.context = object.context ?? undefined;
message.ownerId = object.ownerId ?? undefined;
Expand Down Expand Up @@ -1672,6 +1759,14 @@ export const ValueAndContextStorageBackendDefinition = {
responseStream: false,
options: {},
},
onDeleteRevision: {
name: "OnDeleteRevision",
requestType: OnDeleteRevisionValueAndContextRequest,
requestStream: false,
responseType: OnDeleteRevisionResponse,
responseStream: false,
options: {},
},
/** lock */
getLockedBy: {
name: "GetLockedBy",
Expand Down
2 changes: 1 addition & 1 deletion internal/secret-storage-backend/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (h *Handler) OnDelete(_ context.Context, request *pb.OnDeleteValueAndContex

// OnDeleteRevision handles TypeInstance's revision deletion by removing a secret entry in a given provider.
// It checks whether a given TypeInstance is locked before doing such operation.
func (h *Handler) OnDeleteRevision(ctx context.Context, request *pb.OnDeleteRevisionRequest) (*pb.OnDeleteRevisionResponse, error) {
func (h *Handler) OnDeleteRevision(ctx context.Context, request *pb.OnDeleteRevisionValueAndContextRequest) (*pb.OnDeleteRevisionResponse, error) {
if request == nil {
return nil, NilRequestInputError
}
Expand Down
4 changes: 2 additions & 2 deletions internal/secret-storage-backend/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func TestHandler_OnDeleteRevision(t *testing.T) {
// given
providerName := "fake"
reqContext := []byte(fmt.Sprintf(`{"provider":"%s"}`, providerName))
req := &storage_backend.OnDeleteRevisionRequest{
req := &storage_backend.OnDeleteRevisionValueAndContextRequest{
TypeInstanceId: "uuid",
Context: reqContext,
ResourceVersion: uint32(2),
Expand Down Expand Up @@ -775,7 +775,7 @@ func TestHandler_OnDeleteRevision(t *testing.T) {
require.NoError(t, err)
defer conn.Close()

client := storage_backend.NewStorageBackendClient(conn)
client := storage_backend.NewValueAndContextStorageBackendClient(conn)

// when
res, err := client.OnDeleteRevision(ctx, req)
Expand Down
2 changes: 1 addition & 1 deletion pkg/hub/api/grpc/storage_backend/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func executeSecretStorageBackendTestScenario(t *testing.T, srvAddr, typeInstance

// delete second revision
t.Logf("Deleting TI %q revision %d...\n", typeInstanceID, resourceVersion)
_, err = client.OnDeleteRevision(ctx, &pb.OnDeleteRevisionRequest{
_, err = client.OnDeleteRevision(ctx, &pb.OnDeleteRevisionValueAndContextRequest{
TypeInstanceId: typeInstanceID,
Context: reqContext,
ResourceVersion: resourceVersion,
Expand Down
Loading

0 comments on commit 31fe8f5

Please sign in to comment.