diff --git a/cmd/infohub/main.go b/cmd/infohub/main.go index 1d6cb878ef6c6c426c4789864438cbd06f74d663..8a58c2be1a07dd670634b671d60a397483a2a2fe 100644 --- a/cmd/infohub/main.go +++ b/cmd/infohub/main.go @@ -107,7 +107,7 @@ func main() { ) { infohubSvc = infohub.New(storage, policy, cache, credentials, signer, logger) - healthSvc = health.New() + healthSvc = health.New(Version) } // create endpoints diff --git a/design/design.go b/design/design.go index 7389f2e5197f06bfd6edbe797ee0bb863340795a..8dc9a59d0a53ed9f5c9171f9ad7c687fe982f131 100644 --- a/design/design.go +++ b/design/design.go @@ -45,7 +45,7 @@ var _ = Service("health", func() { Method("Liveness", func() { Payload(Empty) - Result(Empty) + Result(HealthResponse) HTTP(func() { GET("/liveness") Response(StatusOK) @@ -54,7 +54,7 @@ var _ = Service("health", func() { Method("Readiness", func() { Payload(Empty) - Result(Empty) + Result(HealthResponse) HTTP(func() { GET("/readiness") Response(StatusOK) diff --git a/design/types.go b/design/types.go index 20f542cbd0e7461399e39f1b2db548866a2f8725..93e17042a07221eda60d6e5096f9b7d9d48cebb1 100644 --- a/design/types.go +++ b/design/types.go @@ -23,3 +23,10 @@ var ImportResult = Type("ImportResult", func() { }) Required("importIds") }) + +var HealthResponse = Type("HealthResponse", func() { + Field(1, "service", String, "Service name.") + Field(2, "status", String, "Status message.") + Field(3, "version", String, "Service runtime version.") + Required("service", "status", "version") +}) diff --git a/gen/health/client.go b/gen/health/client.go index 9980a08855d0054b2382017fabf756bfc57be6df..65d2c1776ba9030157d4cc422853d7b0c59a930c 100644 --- a/gen/health/client.go +++ b/gen/health/client.go @@ -28,13 +28,21 @@ func NewClient(liveness, readiness goa.Endpoint) *Client { } // Liveness calls the "Liveness" endpoint of the "health" service. -func (c *Client) Liveness(ctx context.Context) (err error) { - _, err = c.LivenessEndpoint(ctx, nil) - return +func (c *Client) Liveness(ctx context.Context) (res *HealthResponse, err error) { + var ires any + ires, err = c.LivenessEndpoint(ctx, nil) + if err != nil { + return + } + return ires.(*HealthResponse), nil } // Readiness calls the "Readiness" endpoint of the "health" service. -func (c *Client) Readiness(ctx context.Context) (err error) { - _, err = c.ReadinessEndpoint(ctx, nil) - return +func (c *Client) Readiness(ctx context.Context) (res *HealthResponse, err error) { + var ires any + ires, err = c.ReadinessEndpoint(ctx, nil) + if err != nil { + return + } + return ires.(*HealthResponse), nil } diff --git a/gen/health/endpoints.go b/gen/health/endpoints.go index e8f909dd236ac6e60d8741b21da28b9dc6b26f21..44b17ff6019dbebe7e287a0b4e15c9603bd280e6 100644 --- a/gen/health/endpoints.go +++ b/gen/health/endpoints.go @@ -37,7 +37,7 @@ func (e *Endpoints) Use(m func(goa.Endpoint) goa.Endpoint) { // "Liveness" of service "health". func NewLivenessEndpoint(s Service) goa.Endpoint { return func(ctx context.Context, req any) (any, error) { - return nil, s.Liveness(ctx) + return s.Liveness(ctx) } } @@ -45,6 +45,6 @@ func NewLivenessEndpoint(s Service) goa.Endpoint { // "Readiness" of service "health". func NewReadinessEndpoint(s Service) goa.Endpoint { return func(ctx context.Context, req any) (any, error) { - return nil, s.Readiness(ctx) + return s.Readiness(ctx) } } diff --git a/gen/health/service.go b/gen/health/service.go index f1a85278c820a630b0fa6f213110c5dc042282af..31d7cd46e8f1da943ff001ea7aa9fc6e34a9f901 100644 --- a/gen/health/service.go +++ b/gen/health/service.go @@ -14,9 +14,9 @@ import ( // Health service provides health check endpoints. type Service interface { // Liveness implements Liveness. - Liveness(context.Context) (err error) + Liveness(context.Context) (res *HealthResponse, err error) // Readiness implements Readiness. - Readiness(context.Context) (err error) + Readiness(context.Context) (res *HealthResponse, err error) } // ServiceName is the name of the service as defined in the design. This is the @@ -28,3 +28,13 @@ const ServiceName = "health" // are the same values that are set in the endpoint request contexts under the // MethodKey key. var MethodNames = [2]string{"Liveness", "Readiness"} + +// HealthResponse is the result type of the health service Liveness method. +type HealthResponse struct { + // Service name. + Service string + // Status message. + Status string + // Service runtime version. + Version string +} diff --git a/gen/http/cli/infohub/cli.go b/gen/http/cli/infohub/cli.go index 52dbc9335daecb5af8e551d47a2ac0fb2b8ea6dc..1becb790390e782671a35f6f6994650d3d229075 100644 --- a/gen/http/cli/infohub/cli.go +++ b/gen/http/cli/infohub/cli.go @@ -23,15 +23,15 @@ import ( // // command (subcommand1|subcommand2|...) func UsageCommands() string { - return `health (liveness|readiness) -infohub (export|import) + return `infohub (export|import) +health (liveness|readiness) ` } // 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 "testexport"` + "\n" + + return os.Args[0] + ` infohub export --export-name "testexport"` + "\n" + + os.Args[0] + ` health liveness` + "\n" + "" } @@ -45,12 +45,6 @@ func ParseEndpoint( restore bool, ) (goa.Endpoint, any, error) { var ( - healthFlags = flag.NewFlagSet("health", flag.ContinueOnError) - - healthLivenessFlags = flag.NewFlagSet("liveness", flag.ExitOnError) - - healthReadinessFlags = flag.NewFlagSet("readiness", flag.ExitOnError) - infohubFlags = flag.NewFlagSet("infohub", flag.ContinueOnError) infohubExportFlags = flag.NewFlagSet("export", flag.ExitOnError) @@ -58,15 +52,21 @@ func ParseEndpoint( infohubImportFlags = flag.NewFlagSet("import", flag.ExitOnError) infohubImportBodyFlag = infohubImportFlags.String("body", "REQUIRED", "") - ) - healthFlags.Usage = healthUsage - healthLivenessFlags.Usage = healthLivenessUsage - healthReadinessFlags.Usage = healthReadinessUsage + healthFlags = flag.NewFlagSet("health", flag.ContinueOnError) + + healthLivenessFlags = flag.NewFlagSet("liveness", flag.ExitOnError) + + healthReadinessFlags = flag.NewFlagSet("readiness", flag.ExitOnError) + ) infohubFlags.Usage = infohubUsage infohubExportFlags.Usage = infohubExportUsage infohubImportFlags.Usage = infohubImportUsage + healthFlags.Usage = healthUsage + healthLivenessFlags.Usage = healthLivenessUsage + healthReadinessFlags.Usage = healthReadinessUsage + if err := flag.CommandLine.Parse(os.Args[1:]); err != nil { return nil, nil, err } @@ -82,10 +82,10 @@ func ParseEndpoint( { svcn = flag.Arg(0) switch svcn { - case "health": - svcf = healthFlags case "infohub": svcf = infohubFlags + case "health": + svcf = healthFlags default: return nil, nil, fmt.Errorf("unknown service %q", svcn) } @@ -101,16 +101,6 @@ func ParseEndpoint( { epn = svcf.Arg(0) switch svcn { - case "health": - switch epn { - case "liveness": - epf = healthLivenessFlags - - case "readiness": - epf = healthReadinessFlags - - } - case "infohub": switch epn { case "export": @@ -121,6 +111,16 @@ func ParseEndpoint( } + case "health": + switch epn { + case "liveness": + epf = healthLivenessFlags + + case "readiness": + epf = healthReadinessFlags + + } + } } if epf == nil { @@ -141,16 +141,6 @@ func ParseEndpoint( ) { switch svcn { - case "health": - c := healthc.NewClient(scheme, host, doer, enc, dec, restore) - switch epn { - case "liveness": - endpoint = c.Liveness() - data = nil - case "readiness": - endpoint = c.Readiness() - data = nil - } case "infohub": c := infohubc.NewClient(scheme, host, doer, enc, dec, restore) switch epn { @@ -161,6 +151,16 @@ func ParseEndpoint( endpoint = c.Import() data, err = infohubc.BuildImportPayload(*infohubImportBodyFlag) } + case "health": + c := healthc.NewClient(scheme, host, doer, enc, dec, restore) + switch epn { + case "liveness": + endpoint = c.Liveness() + data = nil + case "readiness": + endpoint = c.Readiness() + data = nil + } } } if err != nil { @@ -170,72 +170,72 @@ func ParseEndpoint( return endpoint, data, nil } -// healthUsage displays the usage of the health command and its subcommands. -func healthUsage() { - fmt.Fprintf(os.Stderr, `Health service provides health check endpoints. +// infohubUsage displays the usage of the infohub command and its subcommands. +func infohubUsage() { + fmt.Fprintf(os.Stderr, `Information Hub Service enables exporting and importing information. Usage: - %[1]s [globalflags] health COMMAND [flags] + %[1]s [globalflags] infohub COMMAND [flags] COMMAND: - liveness: Liveness implements Liveness. - readiness: Readiness implements Readiness. + export: Export returns data signed as Verifiable Presentation. + import: Import the given data wrapped as Verifiable Presentation into the Cache. Additional help: - %[1]s health COMMAND --help + %[1]s infohub COMMAND --help `, os.Args[0]) } -func healthLivenessUsage() { - fmt.Fprintf(os.Stderr, `%[1]s [flags] health liveness +func infohubExportUsage() { + fmt.Fprintf(os.Stderr, `%[1]s [flags] infohub export -export-name STRING -Liveness implements Liveness. +Export returns data signed as Verifiable Presentation. + -export-name STRING: Name of export to be performed. Example: - %[1]s health liveness + %[1]s infohub export --export-name "testexport" `, os.Args[0]) } -func healthReadinessUsage() { - fmt.Fprintf(os.Stderr, `%[1]s [flags] health readiness +func infohubImportUsage() { + fmt.Fprintf(os.Stderr, `%[1]s [flags] infohub import -body STRING -Readiness implements Readiness. +Import the given data wrapped as Verifiable Presentation into the Cache. + -body STRING: Example: - %[1]s health readiness + %[1]s infohub import --body "data" `, os.Args[0]) } -// infohubUsage displays the usage of the infohub command and its subcommands. -func infohubUsage() { - fmt.Fprintf(os.Stderr, `Information Hub Service enables exporting and importing information. +// healthUsage displays the usage of the health command and its subcommands. +func healthUsage() { + fmt.Fprintf(os.Stderr, `Health service provides health check endpoints. Usage: - %[1]s [globalflags] infohub COMMAND [flags] + %[1]s [globalflags] health COMMAND [flags] COMMAND: - export: Export returns data signed as Verifiable Presentation. - import: Import the given data wrapped as Verifiable Presentation into the Cache. + liveness: Liveness implements Liveness. + readiness: Readiness implements Readiness. Additional help: - %[1]s infohub COMMAND --help + %[1]s health COMMAND --help `, os.Args[0]) } -func infohubExportUsage() { - fmt.Fprintf(os.Stderr, `%[1]s [flags] infohub export -export-name STRING +func healthLivenessUsage() { + fmt.Fprintf(os.Stderr, `%[1]s [flags] health liveness -Export returns data signed as Verifiable Presentation. - -export-name STRING: Name of export to be performed. +Liveness implements Liveness. Example: - %[1]s infohub export --export-name "testexport" + %[1]s health liveness `, os.Args[0]) } -func infohubImportUsage() { - fmt.Fprintf(os.Stderr, `%[1]s [flags] infohub import -body STRING +func healthReadinessUsage() { + fmt.Fprintf(os.Stderr, `%[1]s [flags] health readiness -Import the given data wrapped as Verifiable Presentation into the Cache. - -body STRING: +Readiness implements Readiness. Example: - %[1]s infohub import --body "data" + %[1]s health readiness `, os.Args[0]) } diff --git a/gen/http/health/client/encode_decode.go b/gen/http/health/client/encode_decode.go index 00da3b5a237c82366985f827428ee5458d735337..c5265be497cfef0abfa3c7cc38276958d6ff5e00 100644 --- a/gen/http/health/client/encode_decode.go +++ b/gen/http/health/client/encode_decode.go @@ -51,7 +51,20 @@ func DecodeLivenessResponse(decoder func(*http.Response) goahttp.Decoder, restor } switch resp.StatusCode { case http.StatusOK: - return nil, nil + var ( + body LivenessResponseBody + err error + ) + err = decoder(resp).Decode(&body) + if err != nil { + return nil, goahttp.ErrDecodingError("health", "Liveness", err) + } + err = ValidateLivenessResponseBody(&body) + if err != nil { + return nil, goahttp.ErrValidationError("health", "Liveness", err) + } + res := NewLivenessHealthResponseOK(&body) + return res, nil default: body, _ := io.ReadAll(resp.Body) return nil, goahttp.ErrInvalidResponse("health", "Liveness", resp.StatusCode, string(body)) @@ -93,7 +106,20 @@ func DecodeReadinessResponse(decoder func(*http.Response) goahttp.Decoder, resto } switch resp.StatusCode { case http.StatusOK: - return nil, nil + var ( + body ReadinessResponseBody + err error + ) + err = decoder(resp).Decode(&body) + if err != nil { + return nil, goahttp.ErrDecodingError("health", "Readiness", err) + } + err = ValidateReadinessResponseBody(&body) + if err != nil { + return nil, goahttp.ErrValidationError("health", "Readiness", err) + } + res := NewReadinessHealthResponseOK(&body) + return res, nil default: body, _ := io.ReadAll(resp.Body) return nil, goahttp.ErrInvalidResponse("health", "Readiness", resp.StatusCode, string(body)) diff --git a/gen/http/health/client/types.go b/gen/http/health/client/types.go index 893241d01c4e78365dada87156d786ff0c535acb..7c5cd0dcffa137328cb8933e332cebab6b991e14 100644 --- a/gen/http/health/client/types.go +++ b/gen/http/health/client/types.go @@ -6,3 +6,84 @@ // $ goa gen gitlab.eclipse.org/eclipse/xfsc/tsa/infohub/design package client + +import ( + health "gitlab.eclipse.org/eclipse/xfsc/tsa/infohub/gen/health" + goa "goa.design/goa/v3/pkg" +) + +// LivenessResponseBody is the type of the "health" service "Liveness" endpoint +// HTTP response body. +type LivenessResponseBody struct { + // Service name. + Service *string `form:"service,omitempty" json:"service,omitempty" xml:"service,omitempty"` + // Status message. + Status *string `form:"status,omitempty" json:"status,omitempty" xml:"status,omitempty"` + // Service runtime version. + Version *string `form:"version,omitempty" json:"version,omitempty" xml:"version,omitempty"` +} + +// ReadinessResponseBody is the type of the "health" service "Readiness" +// endpoint HTTP response body. +type ReadinessResponseBody struct { + // Service name. + Service *string `form:"service,omitempty" json:"service,omitempty" xml:"service,omitempty"` + // Status message. + Status *string `form:"status,omitempty" json:"status,omitempty" xml:"status,omitempty"` + // Service runtime version. + Version *string `form:"version,omitempty" json:"version,omitempty" xml:"version,omitempty"` +} + +// NewLivenessHealthResponseOK builds a "health" service "Liveness" endpoint +// result from a HTTP "OK" response. +func NewLivenessHealthResponseOK(body *LivenessResponseBody) *health.HealthResponse { + v := &health.HealthResponse{ + Service: *body.Service, + Status: *body.Status, + Version: *body.Version, + } + + return v +} + +// NewReadinessHealthResponseOK builds a "health" service "Readiness" endpoint +// result from a HTTP "OK" response. +func NewReadinessHealthResponseOK(body *ReadinessResponseBody) *health.HealthResponse { + v := &health.HealthResponse{ + Service: *body.Service, + Status: *body.Status, + Version: *body.Version, + } + + return v +} + +// ValidateLivenessResponseBody runs the validations defined on +// LivenessResponseBody +func ValidateLivenessResponseBody(body *LivenessResponseBody) (err error) { + if body.Service == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("service", "body")) + } + if body.Status == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("status", "body")) + } + if body.Version == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("version", "body")) + } + return +} + +// ValidateReadinessResponseBody runs the validations defined on +// ReadinessResponseBody +func ValidateReadinessResponseBody(body *ReadinessResponseBody) (err error) { + if body.Service == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("service", "body")) + } + if body.Status == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("status", "body")) + } + if body.Version == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("version", "body")) + } + return +} diff --git a/gen/http/health/server/encode_decode.go b/gen/http/health/server/encode_decode.go index 81a4b7782588db5a465f4dcce56cdb7aa41ff2f3..36b7defc6c0fa931690fa3e612b5fe9bf4447e9c 100644 --- a/gen/http/health/server/encode_decode.go +++ b/gen/http/health/server/encode_decode.go @@ -11,6 +11,7 @@ import ( "context" "net/http" + health "gitlab.eclipse.org/eclipse/xfsc/tsa/infohub/gen/health" goahttp "goa.design/goa/v3/http" ) @@ -18,8 +19,11 @@ import ( // health Liveness endpoint. func EncodeLivenessResponse(encoder func(context.Context, http.ResponseWriter) goahttp.Encoder) func(context.Context, http.ResponseWriter, any) error { return func(ctx context.Context, w http.ResponseWriter, v any) error { + res, _ := v.(*health.HealthResponse) + enc := encoder(ctx, w) + body := NewLivenessResponseBody(res) w.WriteHeader(http.StatusOK) - return nil + return enc.Encode(body) } } @@ -27,7 +31,10 @@ func EncodeLivenessResponse(encoder func(context.Context, http.ResponseWriter) g // health Readiness endpoint. func EncodeReadinessResponse(encoder func(context.Context, http.ResponseWriter) goahttp.Encoder) func(context.Context, http.ResponseWriter, any) error { return func(ctx context.Context, w http.ResponseWriter, v any) error { + res, _ := v.(*health.HealthResponse) + enc := encoder(ctx, w) + body := NewReadinessResponseBody(res) w.WriteHeader(http.StatusOK) - return nil + return enc.Encode(body) } } diff --git a/gen/http/health/server/types.go b/gen/http/health/server/types.go index 67a3d7aae73ba6466405ea6f2d5195190fa7bc8b..7b5b3b7f94385f831814654733f861e43fd78e64 100644 --- a/gen/http/health/server/types.go +++ b/gen/http/health/server/types.go @@ -6,3 +6,51 @@ // $ goa gen gitlab.eclipse.org/eclipse/xfsc/tsa/infohub/design package server + +import ( + health "gitlab.eclipse.org/eclipse/xfsc/tsa/infohub/gen/health" +) + +// LivenessResponseBody is the type of the "health" service "Liveness" endpoint +// HTTP response body. +type LivenessResponseBody struct { + // Service name. + Service string `form:"service" json:"service" xml:"service"` + // Status message. + Status string `form:"status" json:"status" xml:"status"` + // Service runtime version. + Version string `form:"version" json:"version" xml:"version"` +} + +// ReadinessResponseBody is the type of the "health" service "Readiness" +// endpoint HTTP response body. +type ReadinessResponseBody struct { + // Service name. + Service string `form:"service" json:"service" xml:"service"` + // Status message. + Status string `form:"status" json:"status" xml:"status"` + // Service runtime version. + Version string `form:"version" json:"version" xml:"version"` +} + +// NewLivenessResponseBody builds the HTTP response body from the result of the +// "Liveness" endpoint of the "health" service. +func NewLivenessResponseBody(res *health.HealthResponse) *LivenessResponseBody { + body := &LivenessResponseBody{ + Service: res.Service, + Status: res.Status, + Version: res.Version, + } + return body +} + +// NewReadinessResponseBody builds the HTTP response body from the result of +// the "Readiness" endpoint of the "health" service. +func NewReadinessResponseBody(res *health.HealthResponse) *ReadinessResponseBody { + body := &ReadinessResponseBody{ + Service: res.Service, + Status: res.Status, + Version: res.Version, + } + return body +} diff --git a/gen/http/openapi.json b/gen/http/openapi.json index 42a48004c5c9060181c4ffa79cd67bdafaf55e4e..4e66da414fd0d33707cb71267409fe9bc9f908a7 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"]}},"/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 +{"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.","schema":{"$ref":"#/definitions/HealthLivenessResponseBody","required":["service","status","version"]}}},"schemes":["http"]}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/HealthReadinessResponseBody","required":["service","status","version"]}}},"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":{"HealthLivenessResponseBody":{"title":"HealthLivenessResponseBody","type":"object","properties":{"service":{"type":"string","description":"Service name.","example":"Atque voluptatem."},"status":{"type":"string","description":"Status message.","example":"Optio et enim in eum."},"version":{"type":"string","description":"Service runtime version.","example":"A consequatur iusto."}},"example":{"service":"Vel voluptates.","status":"Ut quidem.","version":"Iusto reprehenderit praesentium sint est molestiae labore."},"required":["service","status","version"]},"HealthReadinessResponseBody":{"title":"HealthReadinessResponseBody","type":"object","properties":{"service":{"type":"string","description":"Service name.","example":"Placeat quia qui tenetur."},"status":{"type":"string","description":"Status message.","example":"Est adipisci incidunt."},"version":{"type":"string","description":"Service runtime version.","example":"Ipsa cum expedita dolore."}},"example":{"service":"Excepturi iusto.","status":"Ut quo quae.","version":"Qui consequatur laborum et dolorem."},"required":["service","status","version"]},"InfohubImportResponseBody":{"title":"InfohubImportResponseBody","type":"object","properties":{"importIds":{"type":"array","items":{"type":"string","example":"Rerum possimus dolor fugiat fugit."},"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 d97b75e1656bcbcebfe7f2ec1ae8ee24b2ab8365..bb0ddac4b0769017b6680ecac1d96a537913f820 100644 --- a/gen/http/openapi.yaml +++ b/gen/http/openapi.yaml @@ -22,6 +22,12 @@ paths: responses: "200": description: OK response. + schema: + $ref: '#/definitions/HealthLivenessResponseBody' + required: + - service + - status + - version schemes: - http /readiness: @@ -33,6 +39,12 @@ paths: responses: "200": description: OK response. + schema: + $ref: '#/definitions/HealthReadinessResponseBody' + required: + - service + - status + - version schemes: - http /v1/export/{exportName}: @@ -81,6 +93,54 @@ paths: schemes: - http definitions: + HealthLivenessResponseBody: + title: HealthLivenessResponseBody + type: object + properties: + service: + type: string + description: Service name. + example: Atque voluptatem. + status: + type: string + description: Status message. + example: Optio et enim in eum. + version: + type: string + description: Service runtime version. + example: A consequatur iusto. + example: + service: Vel voluptates. + status: Ut quidem. + version: Iusto reprehenderit praesentium sint est molestiae labore. + required: + - service + - status + - version + HealthReadinessResponseBody: + title: HealthReadinessResponseBody + type: object + properties: + service: + type: string + description: Service name. + example: Placeat quia qui tenetur. + status: + type: string + description: Status message. + example: Est adipisci incidunt. + version: + type: string + description: Service runtime version. + example: Ipsa cum expedita dolore. + example: + service: Excepturi iusto. + status: Ut quo quae. + version: Qui consequatur laborum et dolorem. + required: + - service + - status + - version InfohubImportResponseBody: title: InfohubImportResponseBody type: object @@ -89,7 +149,7 @@ definitions: type: array items: type: string - example: Veniam non. + example: Rerum possimus dolor fugiat fugit. 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 diff --git a/gen/http/openapi3.json b/gen/http/openapi3.json index e121b07cd358bb8a74fded3de2062adb554b48bc..6b7a04cc10c6a72194f547124f294802e622c32c 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":"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 +{"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.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HealthResponse"},"example":{"service":"Hic iste totam.","status":"Et eos hic similique.","version":"Ut eos magnam in itaque quia."}}}}}}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HealthResponse"},"example":{"service":"Voluptatem labore omnis.","status":"Qui reiciendis doloremque magni dicta rerum.","version":"Autem sed molestiae quibusdam velit."}}}}}}},"/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":"Quis repudiandae neque sed.","format":"binary"},"example":"Praesentium quo esse voluptatem sapiente."}}}}}},"/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":{"HealthResponse":{"type":"object","properties":{"service":{"type":"string","description":"Service name.","example":"Minima qui ducimus earum et."},"status":{"type":"string","description":"Status message.","example":"Provident eaque deserunt."},"version":{"type":"string","description":"Service runtime version.","example":"Voluptatem quo."}},"example":{"service":"Iure beatae asperiores accusantium ex id quisquam.","status":"Ut non.","version":"Et sed quia ut."},"required":["service","status","version"]},"ImportResult":{"type":"object","properties":{"importIds":{"type":"array","items":{"type":"string","example":"Voluptas voluptates numquam et velit."},"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":"infohub","description":"Information Hub Service enables exporting and importing information."},{"name":"health","description":"Health service provides health check endpoints."}]} \ No newline at end of file diff --git a/gen/http/openapi3.yaml b/gen/http/openapi3.yaml index bc9348f1cf7118b48525eb38f4c3a7c5eae1b32d..a342ed4019f8962d5a7f232a933c6be57e5fd5fa 100644 --- a/gen/http/openapi3.yaml +++ b/gen/http/openapi3.yaml @@ -16,6 +16,14 @@ paths: responses: "200": description: OK response. + content: + application/json: + schema: + $ref: '#/components/schemas/HealthResponse' + example: + service: Hic iste totam. + status: Et eos hic similique. + version: Ut eos magnam in itaque quia. /readiness: get: tags: @@ -25,6 +33,14 @@ paths: responses: "200": description: OK response. + content: + application/json: + schema: + $ref: '#/components/schemas/HealthResponse' + example: + service: Voluptatem labore omnis. + status: Qui reiciendis doloremque magni dicta rerum. + version: Autem sed molestiae quibusdam velit. /v1/export/{exportName}: get: tags: @@ -49,9 +65,9 @@ paths: application/json: schema: type: string - example: Ipsam similique nulla quis. + example: Quis repudiandae neque sed. format: binary - example: Hic iste totam. + example: Praesentium quo esse voluptatem sapiente. /v1/import: post: tags: @@ -82,6 +98,29 @@ paths: - 585a999a-f36d-419d-bed3-8ebfa5bb79c9 components: schemas: + HealthResponse: + type: object + properties: + service: + type: string + description: Service name. + example: Minima qui ducimus earum et. + status: + type: string + description: Status message. + example: Provident eaque deserunt. + version: + type: string + description: Service runtime version. + example: Voluptatem quo. + example: + service: Iure beatae asperiores accusantium ex id quisquam. + status: Ut non. + version: Et sed quia ut. + required: + - service + - status + - version ImportResult: type: object properties: @@ -89,7 +128,7 @@ components: type: array items: type: string - example: Quibusdam ut exercitationem dolore eius id sed. + example: Voluptas voluptates numquam et velit. 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 @@ -99,7 +138,7 @@ components: 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. diff --git a/internal/credential/credentials.go b/internal/credential/credentials.go index f1e9121d01f79e500f8f99c0a331fdca76843d12..fdd2ffcf85fbf1306aab8cc061d1e740b95f0460 100644 --- a/internal/credential/credentials.go +++ b/internal/credential/credentials.go @@ -32,7 +32,7 @@ func New(issuerURI string, httpClient *http.Client) *Credentials { } // NewCredential creates a Verifiable Credential without proofs. -func (c *Credentials) NewCredential(contexts []string, subjectID string, subject map[string]interface{}, proof bool) (*verifiable.Credential, error) { +func (c *Credentials) NewCredential(contexts []string, subjectID string, subject map[string]interface{}, proof bool) (*verifiable.Credential, error) { //nolint:revive jsonldContexts := defaultContexts jsonldContexts = append(jsonldContexts, contexts...) diff --git a/internal/service/error_response.go b/internal/service/error_response.go index c079923a83800c8d4bc050a07fc929e5c83b2a80..9234f3041e4f396e936b553b74492589d15728e0 100644 --- a/internal/service/error_response.go +++ b/internal/service/error_response.go @@ -2,6 +2,7 @@ package service import ( "context" + goahttp "goa.design/goa/v3/http" goa "goa.design/goa/v3/pkg" diff --git a/internal/service/health/service.go b/internal/service/health/service.go index ffa6d9af3d67b8681ce5464bc555ca38aa6b801e..7f553918a004831dbf22191299d680bdf33ce639 100644 --- a/internal/service/health/service.go +++ b/internal/service/health/service.go @@ -1,17 +1,31 @@ package health -import "context" +import ( + "context" -type Service struct{} + "gitlab.eclipse.org/eclipse/xfsc/tsa/infohub/gen/health" +) -func New() *Service { - return &Service{} +type Service struct { + version string } -func (s *Service) Liveness(ctx context.Context) error { - return nil +func New(version string) *Service { + return &Service{version: version} } -func (s *Service) Readiness(ctx context.Context) error { - return nil +func (s *Service) Liveness(_ context.Context) (*health.HealthResponse, error) { + return &health.HealthResponse{ + Service: "infohub", + Status: "up", + Version: s.version, + }, nil +} + +func (s *Service) Readiness(_ context.Context) (*health.HealthResponse, error) { + return &health.HealthResponse{ + Service: "infohub", + Status: "up", + Version: s.version, + }, nil }