github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/internal/apiserver/route_post_broadcast_message.go (about) 1 // Copyright © 2021 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 apiserver 18 19 import ( 20 "net/http" 21 22 "github.com/kaleido-io/firefly/internal/config" 23 "github.com/kaleido-io/firefly/internal/i18n" 24 "github.com/kaleido-io/firefly/internal/oapispec" 25 "github.com/kaleido-io/firefly/pkg/fftypes" 26 ) 27 28 var broadcastSchema = `{ 29 "properties": { 30 "data": { 31 "items": { 32 "properties": { 33 "id": {"type": "string"}, 34 "hash": {"type": "string"}, 35 "validator": {"type": "string"}, 36 "datatype": { 37 "type": "object", 38 "properties": { 39 "name": {"type": "string"}, 40 "version": {"type": "string"} 41 } 42 }, 43 "value": { 44 "type": "object" 45 } 46 }, 47 "type": "object" 48 }, 49 "type": "array" 50 }, 51 "header": { 52 "properties": { 53 "author": { 54 "type": "string" 55 }, 56 "cid": {}, 57 "context": { 58 "type": "string" 59 }, 60 "group": {}, 61 "topic": { 62 "type": "string" 63 }, 64 "tx": { 65 "properties": { 66 "type": { 67 "type": "string", 68 "default": "pin" 69 } 70 }, 71 "type": "object" 72 } 73 }, 74 "type": "object" 75 } 76 }, 77 "type": "object" 78 }` 79 80 var postBroadcastMessage = &oapispec.Route{ 81 Name: "postBroadcastMessage", 82 Path: "namespaces/{ns}/broadcast/message", 83 Method: http.MethodPost, 84 PathParams: []*oapispec.PathParam{ 85 {Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD}, 86 }, 87 QueryParams: nil, 88 FilterFactory: nil, 89 Description: i18n.MsgTBD, 90 JSONInputValue: func() interface{} { return &fftypes.MessageInput{} }, 91 JSONInputSchema: broadcastSchema, 92 JSONOutputValue: func() interface{} { return &fftypes.Message{} }, 93 JSONOutputCode: http.StatusAccepted, // Async operation 94 JSONHandler: func(r oapispec.APIRequest) (output interface{}, err error) { 95 output, err = r.Or.Broadcast().BroadcastMessage(r.Ctx, r.PP["ns"], r.Input.(*fftypes.MessageInput)) 96 return output, err 97 }, 98 }