From eaf8aa9964c5a6cd6787386235098a90c020ab5f Mon Sep 17 00:00:00 2001 From: Lyuben Penkovski <lyuben.penkovski@vereign.com> Date: Thu, 23 Jun 2022 19:49:00 +0300 Subject: [PATCH] Goa DSL and generated code for new Import endpoint --- design/design.go | 11 ++ design/types.go | 16 ++- gen/health/client.go | 2 +- gen/health/endpoints.go | 2 +- gen/health/service.go | 2 +- gen/http/cli/infohub/cli.go | 30 ++++- gen/http/health/client/cli.go | 2 +- gen/http/health/client/client.go | 2 +- gen/http/health/client/encode_decode.go | 2 +- gen/http/health/client/paths.go | 2 +- gen/http/health/client/types.go | 2 +- gen/http/health/server/encode_decode.go | 2 +- gen/http/health/server/paths.go | 2 +- gen/http/health/server/server.go | 2 +- gen/http/health/server/types.go | 2 +- gen/http/infohub/client/cli.go | 17 ++- gen/http/infohub/client/client.go | 30 ++++- gen/http/infohub/client/encode_decode.go | 73 ++++++++++- gen/http/infohub/client/paths.go | 7 +- gen/http/infohub/client/types.go | 35 ++++- gen/http/infohub/server/encode_decode.go | 38 +++++- gen/http/infohub/server/paths.go | 7 +- gen/http/infohub/server/server.go | 58 ++++++++- gen/http/infohub/server/types.go | 33 ++++- gen/http/openapi.json | 2 +- gen/http/openapi.yaml | 147 +++++++++++++-------- gen/http/openapi/client/client.go | 2 +- gen/http/openapi/client/encode_decode.go | 2 +- gen/http/openapi/client/paths.go | 2 +- gen/http/openapi/client/types.go | 2 +- gen/http/openapi/server/paths.go | 2 +- gen/http/openapi/server/server.go | 2 +- gen/http/openapi/server/types.go | 2 +- gen/http/openapi3.json | 2 +- gen/http/openapi3.yaml | 156 +++++++++++++++-------- gen/infohub/client.go | 16 ++- gen/infohub/endpoints.go | 14 +- gen/infohub/service.go | 19 ++- gen/openapi/client.go | 2 +- gen/openapi/endpoints.go | 2 +- gen/openapi/service.go | 2 +- 41 files changed, 603 insertions(+), 152 deletions(-) diff --git a/design/design.go b/design/design.go index 75b1d81..7389f2e 100644 --- a/design/design.go +++ b/design/design.go @@ -27,6 +27,17 @@ var _ = Service("infohub", func() { Response(StatusOK) }) }) + + Method("Import", func() { + Description("Import the given data wrapped as Verifiable Presentation into the Cache.") + Payload(ImportRequest) + Result(ImportResult) + HTTP(func() { + POST("/v1/import") + Body("data") + Response(StatusOK) + }) + }) }) var _ = Service("health", func() { diff --git a/design/types.go b/design/types.go index cdc70b7..20f542c 100644 --- a/design/types.go +++ b/design/types.go @@ -5,7 +5,21 @@ import . "goa.design/goa/v3/dsl" var ExportRequest = Type("ExportRequest", func() { Field(1, "exportName", String, "Name of export to be performed.", func() { - Example("myexport") + Example("testexport") }) Required("exportName") }) + +var ImportRequest = Type("ImportRequest", func() { + Field(1, "data", Bytes, "Data wrapped in Verifiable Presentation that will be imported into Cache.", func() { + Example("data") + }) + Required("data") +}) + +var ImportResult = Type("ImportResult", func() { + Field(1, "importIds", ArrayOf(String), "importIds is an array of unique identifiers used as Cache keys to retrieve the imported data entries later.", func() { + Example([]string{"585a999a-f36d-419d-bed3-8ebfa5bb79c9"}) + }) + Required("importIds") +}) diff --git a/gen/health/client.go b/gen/health/client.go index 406ce2f..b37fa3f 100644 --- a/gen/health/client.go +++ b/gen/health/client.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // health client // diff --git a/gen/health/endpoints.go b/gen/health/endpoints.go index d7f4298..438595e 100644 --- a/gen/health/endpoints.go +++ b/gen/health/endpoints.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // health endpoints // diff --git a/gen/health/service.go b/gen/health/service.go index 328823d..4c16a9c 100644 --- a/gen/health/service.go +++ b/gen/health/service.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // health service // diff --git a/gen/http/cli/infohub/cli.go b/gen/http/cli/infohub/cli.go index 1f96261..785950b 100644 --- a/gen/http/cli/infohub/cli.go +++ b/gen/http/cli/infohub/cli.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // infohub HTTP client CLI support package // @@ -25,14 +25,14 @@ import ( // func UsageCommands() string { return `health (liveness|readiness) -infohub export +infohub (export|import) ` } // UsageExamples produces an example of a valid invocation of the CLI tool. func UsageExamples() string { return os.Args[0] + ` health liveness` + "\n" + - os.Args[0] + ` infohub export --export-name "myexport"` + "\n" + + os.Args[0] + ` infohub export --export-name "testexport"` + "\n" + "" } @@ -56,6 +56,9 @@ func ParseEndpoint( infohubExportFlags = flag.NewFlagSet("export", flag.ExitOnError) infohubExportExportNameFlag = infohubExportFlags.String("export-name", "REQUIRED", "Name of export to be performed.") + + infohubImportFlags = flag.NewFlagSet("import", flag.ExitOnError) + infohubImportBodyFlag = infohubImportFlags.String("body", "REQUIRED", "") ) healthFlags.Usage = healthUsage healthLivenessFlags.Usage = healthLivenessUsage @@ -63,6 +66,7 @@ func ParseEndpoint( infohubFlags.Usage = infohubUsage infohubExportFlags.Usage = infohubExportUsage + infohubImportFlags.Usage = infohubImportUsage if err := flag.CommandLine.Parse(os.Args[1:]); err != nil { return nil, nil, err @@ -113,6 +117,9 @@ func ParseEndpoint( case "export": epf = infohubExportFlags + case "import": + epf = infohubImportFlags + } } @@ -151,6 +158,9 @@ func ParseEndpoint( case "export": endpoint = c.Export() data, err = infohubc.BuildExportPayload(*infohubExportExportNameFlag) + case "import": + endpoint = c.Import() + data, err = infohubc.BuildImportPayload(*infohubImportBodyFlag) } } } @@ -203,6 +213,7 @@ Usage: COMMAND: export: Export returns data signed as Verifiable Presentation. + import: Import the given data wrapped as Verifiable Presentation into the Cache. Additional help: %[1]s infohub COMMAND --help @@ -215,6 +226,17 @@ Export returns data signed as Verifiable Presentation. -export-name STRING: Name of export to be performed. Example: - %[1]s infohub export --export-name "myexport" + %[1]s infohub export --export-name "testexport" +`, os.Args[0]) +} + +func infohubImportUsage() { + fmt.Fprintf(os.Stderr, `%[1]s [flags] infohub import -body STRING + +Import the given data wrapped as Verifiable Presentation into the Cache. + -body STRING: + +Example: + %[1]s infohub import --body "data" `, os.Args[0]) } diff --git a/gen/http/health/client/cli.go b/gen/http/health/client/cli.go index 87164f6..270e6fd 100644 --- a/gen/http/health/client/cli.go +++ b/gen/http/health/client/cli.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // health HTTP client CLI support package // diff --git a/gen/http/health/client/client.go b/gen/http/health/client/client.go index d0d6d91..6f380ea 100644 --- a/gen/http/health/client/client.go +++ b/gen/http/health/client/client.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // health client HTTP transport // diff --git a/gen/http/health/client/encode_decode.go b/gen/http/health/client/encode_decode.go index fb0dfe3..4b86a40 100644 --- a/gen/http/health/client/encode_decode.go +++ b/gen/http/health/client/encode_decode.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // health HTTP client encoders and decoders // diff --git a/gen/http/health/client/paths.go b/gen/http/health/client/paths.go index 04cc126..f0f55df 100644 --- a/gen/http/health/client/paths.go +++ b/gen/http/health/client/paths.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // HTTP request path constructors for the health service. // diff --git a/gen/http/health/client/types.go b/gen/http/health/client/types.go index 50dbf04..4ceaa24 100644 --- a/gen/http/health/client/types.go +++ b/gen/http/health/client/types.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // health HTTP client types // diff --git a/gen/http/health/server/encode_decode.go b/gen/http/health/server/encode_decode.go index 9c5ef19..dcf32b3 100644 --- a/gen/http/health/server/encode_decode.go +++ b/gen/http/health/server/encode_decode.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // health HTTP server encoders and decoders // diff --git a/gen/http/health/server/paths.go b/gen/http/health/server/paths.go index 8b14384..567e60d 100644 --- a/gen/http/health/server/paths.go +++ b/gen/http/health/server/paths.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // HTTP request path constructors for the health service. // diff --git a/gen/http/health/server/server.go b/gen/http/health/server/server.go index 0e6bf48..f37c7e6 100644 --- a/gen/http/health/server/server.go +++ b/gen/http/health/server/server.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // health HTTP server // diff --git a/gen/http/health/server/types.go b/gen/http/health/server/types.go index 72523d4..f60f04c 100644 --- a/gen/http/health/server/types.go +++ b/gen/http/health/server/types.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // health HTTP server types // diff --git a/gen/http/infohub/client/cli.go b/gen/http/infohub/client/cli.go index ede4162..e7e678b 100644 --- a/gen/http/infohub/client/cli.go +++ b/gen/http/infohub/client/cli.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // infohub HTTP client CLI support package // @@ -23,3 +23,18 @@ func BuildExportPayload(infohubExportExportName string) (*infohub.ExportRequest, return v, nil } + +// BuildImportPayload builds the payload for the infohub Import endpoint from +// CLI flags. +func BuildImportPayload(infohubImportBody string) (*infohub.ImportRequest, error) { + var body []byte + { + body = []byte(infohubImportBody) + } + v := body + res := &infohub.ImportRequest{ + Data: v, + } + + return res, nil +} diff --git a/gen/http/infohub/client/client.go b/gen/http/infohub/client/client.go index dfcd5fc..1dfd6eb 100644 --- a/gen/http/infohub/client/client.go +++ b/gen/http/infohub/client/client.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // infohub client HTTP transport // @@ -20,6 +20,9 @@ type Client struct { // Export Doer is the HTTP client used to make requests to the Export endpoint. ExportDoer goahttp.Doer + // Import Doer is the HTTP client used to make requests to the Import endpoint. + ImportDoer goahttp.Doer + // RestoreResponseBody controls whether the response bodies are reset after // decoding so they can be read again. RestoreResponseBody bool @@ -41,6 +44,7 @@ func NewClient( ) *Client { return &Client{ ExportDoer: doer, + ImportDoer: doer, RestoreResponseBody: restoreBody, scheme: scheme, host: host, @@ -67,3 +71,27 @@ func (c *Client) Export() goa.Endpoint { return decodeResponse(resp) } } + +// Import returns an endpoint that makes HTTP requests to the infohub service +// Import server. +func (c *Client) Import() goa.Endpoint { + var ( + encodeRequest = EncodeImportRequest(c.encoder) + decodeResponse = DecodeImportResponse(c.decoder, c.RestoreResponseBody) + ) + return func(ctx context.Context, v interface{}) (interface{}, error) { + req, err := c.BuildImportRequest(ctx, v) + if err != nil { + return nil, err + } + err = encodeRequest(req, v) + if err != nil { + return nil, err + } + resp, err := c.ImportDoer.Do(req) + if err != nil { + return nil, goahttp.ErrRequestError("infohub", "Import", err) + } + return decodeResponse(resp) + } +} diff --git a/gen/http/infohub/client/encode_decode.go b/gen/http/infohub/client/encode_decode.go index 4eea0d4..df2876a 100644 --- a/gen/http/infohub/client/encode_decode.go +++ b/gen/http/infohub/client/encode_decode.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // infohub HTTP client encoders and decoders // @@ -77,3 +77,74 @@ func DecodeExportResponse(decoder func(*http.Response) goahttp.Decoder, restoreB } } } + +// BuildImportRequest instantiates a HTTP request object with method and path +// set to call the "infohub" service "Import" endpoint +func (c *Client) BuildImportRequest(ctx context.Context, v interface{}) (*http.Request, error) { + u := &url.URL{Scheme: c.scheme, Host: c.host, Path: ImportInfohubPath()} + req, err := http.NewRequest("POST", u.String(), nil) + if err != nil { + return nil, goahttp.ErrInvalidURL("infohub", "Import", u.String(), err) + } + if ctx != nil { + req = req.WithContext(ctx) + } + + return req, nil +} + +// EncodeImportRequest returns an encoder for requests sent to the infohub +// Import server. +func EncodeImportRequest(encoder func(*http.Request) goahttp.Encoder) func(*http.Request, interface{}) error { + return func(req *http.Request, v interface{}) error { + p, ok := v.(*infohub.ImportRequest) + if !ok { + return goahttp.ErrInvalidType("infohub", "Import", "*infohub.ImportRequest", v) + } + body := p.Data + if err := encoder(req).Encode(&body); err != nil { + return goahttp.ErrEncodingError("infohub", "Import", err) + } + return nil + } +} + +// DecodeImportResponse returns a decoder for responses returned by the infohub +// Import endpoint. restoreBody controls whether the response body should be +// restored after having been read. +func DecodeImportResponse(decoder func(*http.Response) goahttp.Decoder, restoreBody bool) func(*http.Response) (interface{}, error) { + return func(resp *http.Response) (interface{}, error) { + if restoreBody { + b, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + resp.Body = ioutil.NopCloser(bytes.NewBuffer(b)) + defer func() { + resp.Body = ioutil.NopCloser(bytes.NewBuffer(b)) + }() + } else { + defer resp.Body.Close() + } + switch resp.StatusCode { + case http.StatusOK: + var ( + body ImportResponseBody + err error + ) + err = decoder(resp).Decode(&body) + if err != nil { + return nil, goahttp.ErrDecodingError("infohub", "Import", err) + } + err = ValidateImportResponseBody(&body) + if err != nil { + return nil, goahttp.ErrValidationError("infohub", "Import", err) + } + res := NewImportResultOK(&body) + return res, nil + default: + body, _ := ioutil.ReadAll(resp.Body) + return nil, goahttp.ErrInvalidResponse("infohub", "Import", resp.StatusCode, string(body)) + } + } +} diff --git a/gen/http/infohub/client/paths.go b/gen/http/infohub/client/paths.go index 98272ee..72e6ec4 100644 --- a/gen/http/infohub/client/paths.go +++ b/gen/http/infohub/client/paths.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // HTTP request path constructors for the infohub service. // @@ -15,3 +15,8 @@ import ( func ExportInfohubPath(exportName string) string { return fmt.Sprintf("/v1/export/%v", exportName) } + +// ImportInfohubPath returns the URL path to the infohub service Import HTTP endpoint. +func ImportInfohubPath() string { + return "/v1/import" +} diff --git a/gen/http/infohub/client/types.go b/gen/http/infohub/client/types.go index c1e33d9..7e0b0f0 100644 --- a/gen/http/infohub/client/types.go +++ b/gen/http/infohub/client/types.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // infohub HTTP client types // @@ -6,3 +6,36 @@ // $ goa gen code.vereign.com/gaiax/tsa/infohub/design package client + +import ( + infohub "code.vereign.com/gaiax/tsa/infohub/gen/infohub" + goa "goa.design/goa/v3/pkg" +) + +// ImportResponseBody is the type of the "infohub" service "Import" endpoint +// HTTP response body. +type ImportResponseBody struct { + // importIds is an array of unique identifiers used as Cache keys to retrieve + // the imported data entries later. + ImportIds []string `form:"importIds,omitempty" json:"importIds,omitempty" xml:"importIds,omitempty"` +} + +// NewImportResultOK builds a "infohub" service "Import" endpoint result from a +// HTTP "OK" response. +func NewImportResultOK(body *ImportResponseBody) *infohub.ImportResult { + v := &infohub.ImportResult{} + v.ImportIds = make([]string, len(body.ImportIds)) + for i, val := range body.ImportIds { + v.ImportIds[i] = val + } + + return v +} + +// ValidateImportResponseBody runs the validations defined on ImportResponseBody +func ValidateImportResponseBody(body *ImportResponseBody) (err error) { + if body.ImportIds == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("importIds", "body")) + } + return +} diff --git a/gen/http/infohub/server/encode_decode.go b/gen/http/infohub/server/encode_decode.go index 9aa1ff4..ac35585 100644 --- a/gen/http/infohub/server/encode_decode.go +++ b/gen/http/infohub/server/encode_decode.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // infohub HTTP server encoders and decoders // @@ -9,9 +9,12 @@ package server import ( "context" + "io" "net/http" + infohub "code.vereign.com/gaiax/tsa/infohub/gen/infohub" goahttp "goa.design/goa/v3/http" + goa "goa.design/goa/v3/pkg" ) // EncodeExportResponse returns an encoder for responses returned by the @@ -41,3 +44,36 @@ func DecodeExportRequest(mux goahttp.Muxer, decoder func(*http.Request) goahttp. return payload, nil } } + +// EncodeImportResponse returns an encoder for responses returned by the +// infohub Import endpoint. +func EncodeImportResponse(encoder func(context.Context, http.ResponseWriter) goahttp.Encoder) func(context.Context, http.ResponseWriter, interface{}) error { + return func(ctx context.Context, w http.ResponseWriter, v interface{}) error { + res, _ := v.(*infohub.ImportResult) + enc := encoder(ctx, w) + body := NewImportResponseBody(res) + w.WriteHeader(http.StatusOK) + return enc.Encode(body) + } +} + +// DecodeImportRequest returns a decoder for requests sent to the infohub +// Import endpoint. +func DecodeImportRequest(mux goahttp.Muxer, decoder func(*http.Request) goahttp.Decoder) func(*http.Request) (interface{}, error) { + return func(r *http.Request) (interface{}, error) { + var ( + body []byte + err error + ) + err = decoder(r).Decode(&body) + if err != nil { + if err == io.EOF { + return nil, goa.MissingPayloadError() + } + return nil, goa.DecodePayloadError(err.Error()) + } + payload := NewImportRequest(body) + + return payload, nil + } +} diff --git a/gen/http/infohub/server/paths.go b/gen/http/infohub/server/paths.go index 303b230..9164f05 100644 --- a/gen/http/infohub/server/paths.go +++ b/gen/http/infohub/server/paths.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // HTTP request path constructors for the infohub service. // @@ -15,3 +15,8 @@ import ( func ExportInfohubPath(exportName string) string { return fmt.Sprintf("/v1/export/%v", exportName) } + +// ImportInfohubPath returns the URL path to the infohub service Import HTTP endpoint. +func ImportInfohubPath() string { + return "/v1/import" +} diff --git a/gen/http/infohub/server/server.go b/gen/http/infohub/server/server.go index 961f9d5..cacd6a1 100644 --- a/gen/http/infohub/server/server.go +++ b/gen/http/infohub/server/server.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // infohub HTTP server // @@ -20,6 +20,7 @@ import ( type Server struct { Mounts []*MountPoint Export http.Handler + Import http.Handler } // ErrorNamer is an interface implemented by generated error structs that @@ -56,8 +57,10 @@ func New( return &Server{ Mounts: []*MountPoint{ {"Export", "GET", "/v1/export/{exportName}"}, + {"Import", "POST", "/v1/import"}, }, Export: NewExportHandler(e.Export, mux, decoder, encoder, errhandler, formatter), + Import: NewImportHandler(e.Import, mux, decoder, encoder, errhandler, formatter), } } @@ -67,11 +70,13 @@ func (s *Server) Service() string { return "infohub" } // Use wraps the server handlers with the given middleware. func (s *Server) Use(m func(http.Handler) http.Handler) { s.Export = m(s.Export) + s.Import = m(s.Import) } // Mount configures the mux to serve the infohub endpoints. func Mount(mux goahttp.Muxer, h *Server) { MountExportHandler(mux, h.Export) + MountImportHandler(mux, h.Import) } // Mount configures the mux to serve the infohub endpoints. @@ -129,3 +134,54 @@ func NewExportHandler( } }) } + +// MountImportHandler configures the mux to serve the "infohub" service +// "Import" endpoint. +func MountImportHandler(mux goahttp.Muxer, h http.Handler) { + f, ok := h.(http.HandlerFunc) + if !ok { + f = func(w http.ResponseWriter, r *http.Request) { + h.ServeHTTP(w, r) + } + } + mux.Handle("POST", "/v1/import", f) +} + +// NewImportHandler creates a HTTP handler which loads the HTTP request and +// calls the "infohub" service "Import" endpoint. +func NewImportHandler( + endpoint goa.Endpoint, + mux goahttp.Muxer, + decoder func(*http.Request) goahttp.Decoder, + encoder func(context.Context, http.ResponseWriter) goahttp.Encoder, + errhandler func(context.Context, http.ResponseWriter, error), + formatter func(err error) goahttp.Statuser, +) http.Handler { + var ( + decodeRequest = DecodeImportRequest(mux, decoder) + encodeResponse = EncodeImportResponse(encoder) + encodeError = goahttp.ErrorEncoder(encoder, formatter) + ) + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ctx := context.WithValue(r.Context(), goahttp.AcceptTypeKey, r.Header.Get("Accept")) + ctx = context.WithValue(ctx, goa.MethodKey, "Import") + ctx = context.WithValue(ctx, goa.ServiceKey, "infohub") + payload, err := decodeRequest(r) + if err != nil { + if err := encodeError(ctx, w, err); err != nil { + errhandler(ctx, w, err) + } + return + } + res, err := endpoint(ctx, payload) + if err != nil { + if err := encodeError(ctx, w, err); err != nil { + errhandler(ctx, w, err) + } + return + } + if err := encodeResponse(ctx, w, res); err != nil { + errhandler(ctx, w, err) + } + }) +} diff --git a/gen/http/infohub/server/types.go b/gen/http/infohub/server/types.go index 6b91906..1964ea0 100644 --- a/gen/http/infohub/server/types.go +++ b/gen/http/infohub/server/types.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // infohub HTTP server types // @@ -11,6 +11,27 @@ import ( infohub "code.vereign.com/gaiax/tsa/infohub/gen/infohub" ) +// ImportResponseBody is the type of the "infohub" service "Import" endpoint +// HTTP response body. +type ImportResponseBody struct { + // importIds is an array of unique identifiers used as Cache keys to retrieve + // the imported data entries later. + ImportIds []string `form:"importIds" json:"importIds" xml:"importIds"` +} + +// NewImportResponseBody builds the HTTP response body from the result of the +// "Import" endpoint of the "infohub" service. +func NewImportResponseBody(res *infohub.ImportResult) *ImportResponseBody { + body := &ImportResponseBody{} + if res.ImportIds != nil { + body.ImportIds = make([]string, len(res.ImportIds)) + for i, val := range res.ImportIds { + body.ImportIds[i] = val + } + } + return body +} + // NewExportRequest builds a infohub service Export endpoint payload. func NewExportRequest(exportName string) *infohub.ExportRequest { v := &infohub.ExportRequest{} @@ -18,3 +39,13 @@ func NewExportRequest(exportName string) *infohub.ExportRequest { return v } + +// NewImportRequest builds a infohub service Import endpoint payload. +func NewImportRequest(body []byte) *infohub.ImportRequest { + v := body + res := &infohub.ImportRequest{ + Data: v, + } + + return res +} diff --git a/gen/http/openapi.json b/gen/http/openapi.json index 73d9f18..42a4800 100644 --- a/gen/http/openapi.json +++ b/gen/http/openapi.json @@ -1 +1 @@ -{"swagger":"2.0","info":{"title":"Information Hub Service","description":"Information Hub Service exposes HTTP API for exporting and importing information.","version":""},"host":"localhost:8084","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/v1/export/{exportName}":{"get":{"tags":["infohub"],"summary":"Export infohub","description":"Export returns data signed as Verifiable Presentation.","operationId":"infohub#Export","parameters":[{"name":"exportName","in":"path","description":"Name of export to be performed.","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","format":"binary"}}},"schemes":["http"]}}}} \ No newline at end of file +{"swagger":"2.0","info":{"title":"Information Hub Service","description":"Information Hub Service exposes HTTP API for exporting and importing information.","version":""},"host":"localhost:8084","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/v1/export/{exportName}":{"get":{"tags":["infohub"],"summary":"Export infohub","description":"Export returns data signed as Verifiable Presentation.","operationId":"infohub#Export","parameters":[{"name":"exportName","in":"path","description":"Name of export to be performed.","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","format":"binary"}}},"schemes":["http"]}},"/v1/import":{"post":{"tags":["infohub"],"summary":"Import infohub","description":"Import the given data wrapped as Verifiable Presentation into the Cache.","operationId":"infohub#Import","parameters":[{"name":"bytes","in":"body","description":"Data wrapped in Verifiable Presentation that will be imported into Cache.","required":true,"schema":{"type":"string","format":"byte"}}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/InfohubImportResponseBody","required":["importIds"]}}},"schemes":["http"]}}},"definitions":{"InfohubImportResponseBody":{"title":"InfohubImportResponseBody","type":"object","properties":{"importIds":{"type":"array","items":{"type":"string","example":"Veniam non."},"description":"importIds is an array of unique identifiers used as Cache keys to retrieve the imported data entries later.","example":["585a999a-f36d-419d-bed3-8ebfa5bb79c9"]}},"example":{"importIds":["585a999a-f36d-419d-bed3-8ebfa5bb79c9"]},"required":["importIds"]}}} \ No newline at end of file diff --git a/gen/http/openapi.yaml b/gen/http/openapi.yaml index 1d2f51f..d97b75e 100644 --- a/gen/http/openapi.yaml +++ b/gen/http/openapi.yaml @@ -1,59 +1,100 @@ swagger: "2.0" info: - title: Information Hub Service - description: Information Hub Service exposes HTTP API for exporting and importing - information. - version: "" + title: Information Hub Service + description: Information Hub Service exposes HTTP API for exporting and importing information. + version: "" host: localhost:8084 consumes: -- application/json -- application/xml -- application/gob + - application/json + - application/xml + - application/gob produces: -- application/json -- application/xml -- application/gob + - application/json + - application/xml + - application/gob paths: - /liveness: - get: - tags: - - health - summary: Liveness health - operationId: health#Liveness - responses: - "200": - description: OK response. - schemes: - - http - /readiness: - get: - tags: - - health - summary: Readiness health - operationId: health#Readiness - responses: - "200": - description: OK response. - schemes: - - http - /v1/export/{exportName}: - get: - tags: - - infohub - summary: Export infohub - description: Export returns data signed as Verifiable Presentation. - operationId: infohub#Export - parameters: - - name: exportName - in: path - description: Name of export to be performed. - required: true - type: string - responses: - "200": - description: OK response. - schema: - type: string - format: binary - schemes: - - http + /liveness: + get: + tags: + - health + summary: Liveness health + operationId: health#Liveness + responses: + "200": + description: OK response. + schemes: + - http + /readiness: + get: + tags: + - health + summary: Readiness health + operationId: health#Readiness + responses: + "200": + description: OK response. + schemes: + - http + /v1/export/{exportName}: + get: + tags: + - infohub + summary: Export infohub + description: Export returns data signed as Verifiable Presentation. + operationId: infohub#Export + parameters: + - name: exportName + in: path + description: Name of export to be performed. + required: true + type: string + responses: + "200": + description: OK response. + schema: + type: string + format: binary + schemes: + - http + /v1/import: + post: + tags: + - infohub + summary: Import infohub + description: Import the given data wrapped as Verifiable Presentation into the Cache. + operationId: infohub#Import + parameters: + - name: bytes + in: body + description: Data wrapped in Verifiable Presentation that will be imported into Cache. + required: true + schema: + type: string + format: byte + responses: + "200": + description: OK response. + schema: + $ref: '#/definitions/InfohubImportResponseBody' + required: + - importIds + schemes: + - http +definitions: + InfohubImportResponseBody: + title: InfohubImportResponseBody + type: object + properties: + importIds: + type: array + items: + type: string + example: Veniam non. + description: importIds is an array of unique identifiers used as Cache keys to retrieve the imported data entries later. + example: + - 585a999a-f36d-419d-bed3-8ebfa5bb79c9 + example: + importIds: + - 585a999a-f36d-419d-bed3-8ebfa5bb79c9 + required: + - importIds diff --git a/gen/http/openapi/client/client.go b/gen/http/openapi/client/client.go index 7128c21..ca8bf50 100644 --- a/gen/http/openapi/client/client.go +++ b/gen/http/openapi/client/client.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // openapi client HTTP transport // diff --git a/gen/http/openapi/client/encode_decode.go b/gen/http/openapi/client/encode_decode.go index 9bfd2d7..e1b2965 100644 --- a/gen/http/openapi/client/encode_decode.go +++ b/gen/http/openapi/client/encode_decode.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // openapi HTTP client encoders and decoders // diff --git a/gen/http/openapi/client/paths.go b/gen/http/openapi/client/paths.go index d0d05b6..3a1079b 100644 --- a/gen/http/openapi/client/paths.go +++ b/gen/http/openapi/client/paths.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // HTTP request path constructors for the openapi service. // diff --git a/gen/http/openapi/client/types.go b/gen/http/openapi/client/types.go index 16c762d..61e2712 100644 --- a/gen/http/openapi/client/types.go +++ b/gen/http/openapi/client/types.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // openapi HTTP client types // diff --git a/gen/http/openapi/server/paths.go b/gen/http/openapi/server/paths.go index 6449fc4..0b3a272 100644 --- a/gen/http/openapi/server/paths.go +++ b/gen/http/openapi/server/paths.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // HTTP request path constructors for the openapi service. // diff --git a/gen/http/openapi/server/server.go b/gen/http/openapi/server/server.go index 000ba5c..7f14b07 100644 --- a/gen/http/openapi/server/server.go +++ b/gen/http/openapi/server/server.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // openapi HTTP server // diff --git a/gen/http/openapi/server/types.go b/gen/http/openapi/server/types.go index b67c6dc..a9b28d0 100644 --- a/gen/http/openapi/server/types.go +++ b/gen/http/openapi/server/types.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // openapi HTTP server types // diff --git a/gen/http/openapi3.json b/gen/http/openapi3.json index d35523a..e121b07 100644 --- a/gen/http/openapi3.json +++ b/gen/http/openapi3.json @@ -1 +1 @@ -{"openapi":"3.0.3","info":{"title":"Information Hub Service","description":"Information Hub Service exposes HTTP API for exporting and importing information.","version":"1.0"},"servers":[{"url":"http://localhost:8084","description":"Information Hub Server"}],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}}}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}}}},"/v1/export/{exportName}":{"get":{"tags":["infohub"],"summary":"Export infohub","description":"Export returns data signed as Verifiable Presentation.","operationId":"infohub#Export","parameters":[{"name":"exportName","in":"path","description":"Name of export to be performed.","required":true,"schema":{"type":"string","description":"Name of export to be performed.","example":"myexport"},"example":"myexport"}],"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"string","example":"Veniam non.","format":"binary"},"example":"Ipsam similique nulla quis."}}}}}}},"components":{},"tags":[{"name":"health","description":"Health service provides health check endpoints."},{"name":"infohub","description":"Information Hub Service enables exporting and importing information."}]} \ No newline at end of file +{"openapi":"3.0.3","info":{"title":"Information Hub Service","description":"Information Hub Service exposes HTTP API for exporting and importing information.","version":"1.0"},"servers":[{"url":"http://localhost:8084","description":"Information Hub Server"}],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}}}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}}}},"/v1/export/{exportName}":{"get":{"tags":["infohub"],"summary":"Export infohub","description":"Export returns data signed as Verifiable Presentation.","operationId":"infohub#Export","parameters":[{"name":"exportName","in":"path","description":"Name of export to be performed.","required":true,"schema":{"type":"string","description":"Name of export to be performed.","example":"testexport"},"example":"testexport"}],"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"string","example":"Ipsam similique nulla quis.","format":"binary"},"example":"Hic iste totam."}}}}}},"/v1/import":{"post":{"tags":["infohub"],"summary":"Import infohub","description":"Import the given data wrapped as Verifiable Presentation into the Cache.","operationId":"infohub#Import","requestBody":{"description":"Data wrapped in Verifiable Presentation that will be imported into Cache.","required":true,"content":{"application/json":{"schema":{"type":"string","description":"Data wrapped in Verifiable Presentation that will be imported into Cache.","example":"data","format":"binary"},"example":"data"}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ImportResult"},"example":{"importIds":["585a999a-f36d-419d-bed3-8ebfa5bb79c9"]}}}}}}}},"components":{"schemas":{"ImportResult":{"type":"object","properties":{"importIds":{"type":"array","items":{"type":"string","example":"Quibusdam ut exercitationem dolore eius id sed."},"description":"importIds is an array of unique identifiers used as Cache keys to retrieve the imported data entries later.","example":["585a999a-f36d-419d-bed3-8ebfa5bb79c9"]}},"example":{"importIds":["585a999a-f36d-419d-bed3-8ebfa5bb79c9"]},"required":["importIds"]}}},"tags":[{"name":"health","description":"Health service provides health check endpoints."},{"name":"infohub","description":"Information Hub Service enables exporting and importing information."}]} \ No newline at end of file diff --git a/gen/http/openapi3.yaml b/gen/http/openapi3.yaml index 9faf4e1..bc9348f 100644 --- a/gen/http/openapi3.yaml +++ b/gen/http/openapi3.yaml @@ -1,61 +1,105 @@ openapi: 3.0.3 info: - title: Information Hub Service - description: Information Hub Service exposes HTTP API for exporting and importing - information. - version: "1.0" + title: Information Hub Service + description: Information Hub Service exposes HTTP API for exporting and importing information. + version: "1.0" servers: -- url: http://localhost:8084 - description: Information Hub Server + - url: http://localhost:8084 + description: Information Hub Server paths: - /liveness: - get: - tags: - - health - summary: Liveness health - operationId: health#Liveness - responses: - "200": - description: OK response. - /readiness: - get: - tags: - - health - summary: Readiness health - operationId: health#Readiness - responses: - "200": - description: OK response. - /v1/export/{exportName}: - get: - tags: - - infohub - summary: Export infohub - description: Export returns data signed as Verifiable Presentation. - operationId: infohub#Export - parameters: - - name: exportName - in: path - description: Name of export to be performed. - required: true - schema: - type: string - description: Name of export to be performed. - example: myexport - example: myexport - responses: - "200": - description: OK response. - content: - application/json: - schema: - type: string - example: Veniam non. - format: binary - example: Ipsam similique nulla quis. -components: {} + /liveness: + get: + tags: + - health + summary: Liveness health + operationId: health#Liveness + responses: + "200": + description: OK response. + /readiness: + get: + tags: + - health + summary: Readiness health + operationId: health#Readiness + responses: + "200": + description: OK response. + /v1/export/{exportName}: + get: + tags: + - infohub + summary: Export infohub + description: Export returns data signed as Verifiable Presentation. + operationId: infohub#Export + parameters: + - name: exportName + in: path + description: Name of export to be performed. + required: true + schema: + type: string + description: Name of export to be performed. + example: testexport + example: testexport + responses: + "200": + description: OK response. + content: + application/json: + schema: + type: string + example: Ipsam similique nulla quis. + format: binary + example: Hic iste totam. + /v1/import: + post: + tags: + - infohub + summary: Import infohub + description: Import the given data wrapped as Verifiable Presentation into the Cache. + operationId: infohub#Import + requestBody: + description: Data wrapped in Verifiable Presentation that will be imported into Cache. + required: true + content: + application/json: + schema: + type: string + description: Data wrapped in Verifiable Presentation that will be imported into Cache. + example: data + format: binary + example: data + responses: + "200": + description: OK response. + content: + application/json: + schema: + $ref: '#/components/schemas/ImportResult' + example: + importIds: + - 585a999a-f36d-419d-bed3-8ebfa5bb79c9 +components: + schemas: + ImportResult: + type: object + properties: + importIds: + type: array + items: + type: string + example: Quibusdam ut exercitationem dolore eius id sed. + description: importIds is an array of unique identifiers used as Cache keys to retrieve the imported data entries later. + example: + - 585a999a-f36d-419d-bed3-8ebfa5bb79c9 + example: + importIds: + - 585a999a-f36d-419d-bed3-8ebfa5bb79c9 + required: + - importIds tags: -- name: health - description: Health service provides health check endpoints. -- name: infohub - description: Information Hub Service enables exporting and importing information. + - name: health + description: Health service provides health check endpoints. + - name: infohub + description: Information Hub Service enables exporting and importing information. diff --git a/gen/infohub/client.go b/gen/infohub/client.go index 2d942c2..022aab5 100644 --- a/gen/infohub/client.go +++ b/gen/infohub/client.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // infohub client // @@ -16,12 +16,14 @@ import ( // Client is the "infohub" service client. type Client struct { ExportEndpoint goa.Endpoint + ImportEndpoint goa.Endpoint } // NewClient initializes a "infohub" service client given the endpoints. -func NewClient(export goa.Endpoint) *Client { +func NewClient(export, import_ goa.Endpoint) *Client { return &Client{ ExportEndpoint: export, + ImportEndpoint: import_, } } @@ -34,3 +36,13 @@ func (c *Client) Export(ctx context.Context, p *ExportRequest) (res interface{}, } return ires.(interface{}), nil } + +// Import calls the "Import" endpoint of the "infohub" service. +func (c *Client) Import(ctx context.Context, p *ImportRequest) (res *ImportResult, err error) { + var ires interface{} + ires, err = c.ImportEndpoint(ctx, p) + if err != nil { + return + } + return ires.(*ImportResult), nil +} diff --git a/gen/infohub/endpoints.go b/gen/infohub/endpoints.go index e3a12a4..e4089e4 100644 --- a/gen/infohub/endpoints.go +++ b/gen/infohub/endpoints.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // infohub endpoints // @@ -16,18 +16,21 @@ import ( // Endpoints wraps the "infohub" service endpoints. type Endpoints struct { Export goa.Endpoint + Import goa.Endpoint } // NewEndpoints wraps the methods of the "infohub" service with endpoints. func NewEndpoints(s Service) *Endpoints { return &Endpoints{ Export: NewExportEndpoint(s), + Import: NewImportEndpoint(s), } } // Use applies the given middleware to all the "infohub" service endpoints. func (e *Endpoints) Use(m func(goa.Endpoint) goa.Endpoint) { e.Export = m(e.Export) + e.Import = m(e.Import) } // NewExportEndpoint returns an endpoint function that calls the method @@ -38,3 +41,12 @@ func NewExportEndpoint(s Service) goa.Endpoint { return s.Export(ctx, p) } } + +// NewImportEndpoint returns an endpoint function that calls the method +// "Import" of service "infohub". +func NewImportEndpoint(s Service) goa.Endpoint { + return func(ctx context.Context, req interface{}) (interface{}, error) { + p := req.(*ImportRequest) + return s.Import(ctx, p) + } +} diff --git a/gen/infohub/service.go b/gen/infohub/service.go index e65ec3b..3efe6c1 100644 --- a/gen/infohub/service.go +++ b/gen/infohub/service.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // infohub service // @@ -15,6 +15,8 @@ import ( type Service interface { // Export returns data signed as Verifiable Presentation. Export(context.Context, *ExportRequest) (res interface{}, err error) + // Import the given data wrapped as Verifiable Presentation into the Cache. + Import(context.Context, *ImportRequest) (res *ImportResult, err error) } // ServiceName is the name of the service as defined in the design. This is the @@ -25,10 +27,23 @@ const ServiceName = "infohub" // MethodNames lists the service method names as defined in the design. These // are the same values that are set in the endpoint request contexts under the // MethodKey key. -var MethodNames = [1]string{"Export"} +var MethodNames = [2]string{"Export", "Import"} // ExportRequest is the payload type of the infohub service Export method. type ExportRequest struct { // Name of export to be performed. ExportName string } + +// ImportRequest is the payload type of the infohub service Import method. +type ImportRequest struct { + // Data wrapped in Verifiable Presentation that will be imported into Cache. + Data []byte +} + +// ImportResult is the result type of the infohub service Import method. +type ImportResult struct { + // importIds is an array of unique identifiers used as Cache keys to retrieve + // the imported data entries later. + ImportIds []string +} diff --git a/gen/openapi/client.go b/gen/openapi/client.go index 7fe5e21..a6c2862 100644 --- a/gen/openapi/client.go +++ b/gen/openapi/client.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // openapi client // diff --git a/gen/openapi/endpoints.go b/gen/openapi/endpoints.go index 1a95707..6bda9e7 100644 --- a/gen/openapi/endpoints.go +++ b/gen/openapi/endpoints.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // openapi endpoints // diff --git a/gen/openapi/service.go b/gen/openapi/service.go index 05c0615..bb1d008 100644 --- a/gen/openapi/service.go +++ b/gen/openapi/service.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.7.5, DO NOT EDIT. +// Code generated by goa v3.7.6, DO NOT EDIT. // // openapi service // -- GitLab