Skip to content

Commit deddc41

Browse files
Consistent API for publish
Signed-off-by: Peter Broadhurst <[email protected]>
1 parent 3ffb370 commit deddc41

File tree

6 files changed

+50
-39
lines changed

6 files changed

+50
-39
lines changed

docs/swagger/swagger.yaml

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4897,12 +4897,6 @@ paths:
48974897
required: true
48984898
schema:
48994899
type: string
4900-
- description: Optional idempotency key. Request will be rejected with 409 if
4901-
an action has already been initiated with the same key
4902-
in: query
4903-
name: idempotencykey
4904-
schema:
4905-
type: string
49064900
- description: Server-side request timeout (milliseconds, or set a custom suffix
49074901
like 10s)
49084902
in: header
@@ -4914,7 +4908,11 @@ paths:
49144908
content:
49154909
application/json:
49164910
schema:
4917-
additionalProperties: {}
4911+
properties:
4912+
idempotencyKey:
4913+
description: An optional identifier to allow idempotent submission
4914+
of requests. Stored on the transaction uniquely within a namespace
4915+
type: string
49184916
type: object
49194917
responses:
49204918
"200":
@@ -5445,12 +5443,6 @@ paths:
54455443
required: true
54465444
schema:
54475445
type: string
5448-
- description: Optional idempotency key. Request will be rejected with 409 if
5449-
an action has already been initiated with the same key
5450-
in: query
5451-
name: idempotencykey
5452-
schema:
5453-
type: string
54545446
- description: Server-side request timeout (milliseconds, or set a custom suffix
54555447
like 10s)
54565448
in: header
@@ -5462,7 +5454,11 @@ paths:
54625454
content:
54635455
application/json:
54645456
schema:
5465-
additionalProperties: {}
5457+
properties:
5458+
idempotencyKey:
5459+
description: An optional identifier to allow idempotent submission
5460+
of requests. Stored on the transaction uniquely within a namespace
5461+
type: string
54665462
type: object
54675463
responses:
54685464
"200":
@@ -14913,12 +14909,6 @@ paths:
1491314909
schema:
1491414910
example: default
1491514911
type: string
14916-
- description: Optional idempotency key. Request will be rejected with 409 if
14917-
an action has already been initiated with the same key
14918-
in: query
14919-
name: idempotencykey
14920-
schema:
14921-
type: string
1492214912
- description: Server-side request timeout (milliseconds, or set a custom suffix
1492314913
like 10s)
1492414914
in: header
@@ -14930,7 +14920,11 @@ paths:
1493014920
content:
1493114921
application/json:
1493214922
schema:
14933-
additionalProperties: {}
14923+
properties:
14924+
idempotencyKey:
14925+
description: An optional identifier to allow idempotent submission
14926+
of requests. Stored on the transaction uniquely within a namespace
14927+
type: string
1493414928
type: object
1493514929
responses:
1493614930
"200":
@@ -15482,12 +15476,6 @@ paths:
1548215476
schema:
1548315477
example: default
1548415478
type: string
15485-
- description: Optional idempotency key. Request will be rejected with 409 if
15486-
an action has already been initiated with the same key
15487-
in: query
15488-
name: idempotencykey
15489-
schema:
15490-
type: string
1549115479
- description: Server-side request timeout (milliseconds, or set a custom suffix
1549215480
like 10s)
1549315481
in: header
@@ -15499,7 +15487,11 @@ paths:
1549915487
content:
1550015488
application/json:
1550115489
schema:
15502-
additionalProperties: {}
15490+
properties:
15491+
idempotencyKey:
15492+
description: An optional identifier to allow idempotent submission
15493+
of requests. Stored on the transaction uniquely within a namespace
15494+
type: string
1550315495
type: object
1550415496
responses:
1550515497
"200":

internal/apiserver/route_post_data_blob_publish.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,17 @@ var postDataBlobPublish = &ffapi.Route{
3232
PathParams: []*ffapi.PathParam{
3333
{Name: "dataid", Description: coremsgs.APIParamsBlobID},
3434
},
35-
QueryParams: []*ffapi.QueryParam{
36-
{Name: "idempotencykey", Description: coremsgs.APIParamsIdempotencyKey},
37-
},
35+
QueryParams: nil,
3836
Description: coremsgs.APIEndpointsPostDataBlobPublish,
39-
JSONInputValue: func() interface{} { return &core.EmptyInput{} },
37+
JSONInputValue: func() interface{} { return &core.PublishInput{} },
4038
JSONOutputValue: func() interface{} { return &core.Data{} },
4139
JSONOutputCodes: []int{http.StatusOK},
4240
Extensions: &coreExtensions{
4341
EnabledIf: func(or orchestrator.Orchestrator) bool {
4442
return or.Broadcast() != nil
4543
},
4644
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
47-
return cr.or.Broadcast().PublishDataBlob(cr.ctx, r.PP["dataid"], core.IdempotencyKey(r.QP["idempotencykey"]))
45+
return cr.or.Broadcast().PublishDataBlob(cr.ctx, r.PP["dataid"], r.Input.(*core.PublishInput).IdempotencyKey)
4846
},
4947
},
5048
}

internal/apiserver/route_post_data_value_publish.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,17 @@ var postDataValuePublish = &ffapi.Route{
3232
PathParams: []*ffapi.PathParam{
3333
{Name: "dataid", Description: coremsgs.APIParamsBlobID},
3434
},
35-
QueryParams: []*ffapi.QueryParam{
36-
{Name: "idempotencykey", Description: coremsgs.APIParamsIdempotencyKey},
37-
},
35+
QueryParams: nil,
3836
Description: coremsgs.APIEndpointsPostDataValuePublish,
39-
JSONInputValue: func() interface{} { return &core.EmptyInput{} },
37+
JSONInputValue: func() interface{} { return &core.PublishInput{} },
4038
JSONOutputValue: func() interface{} { return &core.Data{} },
4139
JSONOutputCodes: []int{http.StatusOK},
4240
Extensions: &coreExtensions{
4341
EnabledIf: func(or orchestrator.Orchestrator) bool {
4442
return or.Broadcast() != nil
4543
},
4644
CoreJSONHandler: func(r *ffapi.APIRequest, cr *coreRequest) (output interface{}, err error) {
47-
return cr.or.Broadcast().PublishDataValue(cr.ctx, r.PP["dataid"], core.IdempotencyKey(r.QP["idempotencykey"]))
45+
return cr.or.Broadcast().PublishDataValue(cr.ctx, r.PP["dataid"], r.Input.(*core.PublishInput).IdempotencyKey)
4846
},
4947
},
5048
}

internal/coremsgs/en_api_translations.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ var (
6464
APIParamsAutometa = ffm("api.params.autometa", "When set, FireFly will automatically generate JSON metadata with the upload details")
6565
APIParamsContractAPIID = ffm("api.params.contractAPIID", "The ID of the contract API")
6666
APIParamsFetchStatus = ffm("api.params.fetchStatus", "When set, the API will return additional status information if available")
67-
APIParamsIdempotencyKey = ffm("api.params.idempotencykey", "Optional idempotency key. Request will be rejected with 409 if an action has already been initiated with the same key")
6867

6968
APIEndpointsAdminGetNamespaceByName = ffm("api.endpoints.adminGetNamespaceByName", "Gets a namespace by name")
7069
APIEndpointsAdminGetNamespaces = ffm("api.endpoints.adminGetNamespaces", "List namespaces")

internal/coremsgs/en_struct_descriptions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,4 +649,7 @@ var (
649649
WebhooksOptInputBody = ffm("WebhookInputOptions.body", "A top-level property of the first data input, to use for the request body. Default is the whole first body")
650650
WebhooksOptInputPath = ffm("WebhookInputOptions.path", "A top-level property of the first data input, to use for a path to append with escaping to the webhook path")
651651
WebhooksOptInputReplyTx = ffm("WebhookInputOptions.replytx", "A top-level property of the first data input, to use to dynamically set whether to pin the response (so the requester can choose)")
652+
653+
// PublishInput field descriptions
654+
PublishInputIdempotencyKey = ffm("PublishInput.idempotencyKey", "An optional identifier to allow idempotent submission of requests. Stored on the transaction uniquely within a namespace")
652655
)

pkg/core/publish.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright © 2022 Kaleido, Inc.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package core
18+
19+
type PublishInput struct {
20+
IdempotencyKey IdempotencyKey `ffstruct:"PublishInput" json:"idempotencyKey,omitempty" ffexcludeoutput:"true"`
21+
}

0 commit comments

Comments
 (0)