github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/internal/apiserver/route_post_send_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 privateSendSchema = `{ 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 "group": { 52 "properties": { 53 "name": { 54 "type": "string" 55 }, 56 "members": { 57 "type": "array", 58 "items": { 59 "properties": { 60 "identity": { 61 "type": "string" 62 }, 63 "node": { 64 "type": "string" 65 } 66 }, 67 "required": ["identity"], 68 "type": "object" 69 } 70 } 71 }, 72 "required": ["members"], 73 "type": "object" 74 }, 75 "header": { 76 "properties": { 77 "author": { 78 "type": "string" 79 }, 80 "cid": {}, 81 "context": { 82 "type": "string" 83 }, 84 "group": {}, 85 "topic": { 86 "type": "string" 87 }, 88 "tx": { 89 "properties": { 90 "type": { 91 "type": "string", 92 "default": "pin" 93 } 94 }, 95 "type": "object" 96 } 97 }, 98 "type": "object" 99 } 100 }, 101 "type": "object" 102 }` 103 104 var postSendMessage = &oapispec.Route{ 105 Name: "postSendMessage", 106 Path: "namespaces/{ns}/send/message", 107 Method: http.MethodPost, 108 PathParams: []*oapispec.PathParam{ 109 {Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD}, 110 }, 111 QueryParams: nil, 112 FilterFactory: nil, 113 Description: i18n.MsgTBD, 114 JSONInputValue: func() interface{} { return &fftypes.MessageInput{} }, 115 JSONInputSchema: privateSendSchema, 116 JSONOutputValue: func() interface{} { return &fftypes.Message{} }, 117 JSONOutputCode: http.StatusAccepted, // Async operation 118 JSONHandler: func(r oapispec.APIRequest) (output interface{}, err error) { 119 output, err = r.Or.PrivateMessaging().SendMessage(r.Ctx, r.PP["ns"], r.Input.(*fftypes.MessageInput)) 120 return output, err 121 }, 122 }