Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into schema-nil-required
Browse files Browse the repository at this point in the history
  • Loading branch information
decentralgabe authored Dec 9, 2022
2 parents cd5f9be + 42bff04 commit 1b9ee0a
Show file tree
Hide file tree
Showing 17 changed files with 899 additions and 180 deletions.
136 changes: 105 additions & 31 deletions doc/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,11 @@ definitions:
type: array
id:
type: string
reason:
description: The reason why the submission was approved or denied.
type: string
status:
description: One of {`pending`, `done`}.
description: One of {`pending`, `approved`, `denied`}.
type: string
required:
- definition_id
Expand Down Expand Up @@ -831,8 +834,25 @@ definitions:
type: object
github.com_tbd54566975_ssi-service_pkg_server_router.ReviewSubmissionResponse:
properties:
submission:
$ref: '#/definitions/exchange.PresentationSubmission'
definition_id:
type: string
descriptor_map:
items:
$ref: '#/definitions/exchange.SubmissionDescriptor'
type: array
id:
type: string
reason:
description: The reason why the submission was approved or denied.
type: string
status:
description: One of {`pending`, `approved`, `denied`}.
type: string
required:
- definition_id
- descriptor_map
- id
- status
type: object
github.com_tbd54566975_ssi-service_pkg_server_router.StoreKeyRequest:
properties:
Expand Down Expand Up @@ -1318,8 +1338,11 @@ definitions:
type: array
id:
type: string
reason:
description: The reason why the submission was approved or denied.
type: string
status:
description: One of {`pending`, `done`}.
description: One of {`pending`, `approved`, `denied`}.
type: string
required:
- definition_id
Expand Down Expand Up @@ -1383,8 +1406,25 @@ definitions:
type: object
pkg_server_router.ReviewSubmissionResponse:
properties:
submission:
$ref: '#/definitions/exchange.PresentationSubmission'
definition_id:
type: string
descriptor_map:
items:
$ref: '#/definitions/exchange.SubmissionDescriptor'
type: array
id:
type: string
reason:
description: The reason why the submission was approved or denied.
type: string
status:
description: One of {`pending`, `approved`, `denied`}.
type: string
required:
- definition_id
- descriptor_map
- id
- status
type: object
pkg_server_router.StoreKeyRequest:
properties:
Expand Down Expand Up @@ -1471,8 +1511,11 @@ definitions:
type: array
id:
type: string
reason:
description: The reason why the submission was approved or denied.
type: string
status:
description: One of {`pending`, `done`}.
description: One of {`pending`, `approved`, `denied`}.
type: string
required:
- definition_id
Expand Down Expand Up @@ -2492,52 +2535,55 @@ paths:
summary: Get PresentationDefinition
tags:
- PresentationDefinitionAPI
/v1/presentations/submission/{id}:
/v1/presentations/submissions:
get:
consumes:
- application/json
description: Get a submission by its ID
description: List existing submissions according to a filtering query. The `filter`
field follows the syntax described in https://google.aip.dev/160.
parameters:
- description: ID
in: path
name: id
- description: request body
in: body
name: request
required: true
type: string
schema:
$ref: '#/definitions/pkg_server_router.ListSubmissionRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/pkg_server_router.GetSubmissionResponse'
$ref: '#/definitions/pkg_server_router.ListSubmissionResponse'
"400":
description: Bad request
schema:
type: string
summary: Get Submission
"500":
description: Internal server error
schema:
type: string
summary: List Submissions
tags:
- SubmissionAPI
/v1/presentations/submissions:
get:
put:
consumes:
- application/json
description: Reviews a pending submission. After this method is called, the
operation with `id==presentations/submissions/{submission_id}` will be updated
with the result of this invocation.
description: Creates a submission in this server ready to be reviewed.
parameters:
- description: request body
in: body
name: request
required: true
schema:
$ref: '#/definitions/pkg_server_router.ReviewSubmissionRequest'
$ref: '#/definitions/pkg_server_router.CreateSubmissionRequest'
produces:
- application/json
responses:
"200":
description: OK
"201":
description: The type of response is Submission once the operation has finished.
schema:
$ref: '#/definitions/pkg_server_router.ReviewSubmissionResponse'
$ref: '#/definitions/pkg_server_router.Operation'
"400":
description: Bad request
schema:
Expand All @@ -2546,27 +2592,55 @@ paths:
description: Internal server error
schema:
type: string
summary: Review a pending submissions
summary: Create Submission
tags:
- SubmissionAPI
/v1/presentations/submissions/{id}:
get:
consumes:
- application/json
description: Get a submission by its ID
parameters:
- description: ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/pkg_server_router.GetSubmissionResponse'
"400":
description: Bad request
schema:
type: string
summary: Get Submission
tags:
- SubmissionAPI
/v1/presentations/submissions/{id}/review:
put:
consumes:
- application/json
description: Creates a submission in this server ready to be reviewed.
description: Reviews a pending submission. After this method is called, the
operation with `id==presentations/submissions/{submission_id}` will be updated
with the result of this invocation.
parameters:
- description: request body
in: body
name: request
required: true
schema:
$ref: '#/definitions/pkg_server_router.CreateSubmissionRequest'
$ref: '#/definitions/pkg_server_router.ReviewSubmissionRequest'
produces:
- application/json
responses:
"201":
description: The type of response is Submission once the operation has finished.
"200":
description: OK
schema:
$ref: '#/definitions/pkg_server_router.Operation'
$ref: '#/definitions/pkg_server_router.ReviewSubmissionResponse'
"400":
description: Bad request
schema:
Expand All @@ -2575,7 +2649,7 @@ paths:
description: Internal server error
schema:
type: string
summary: Create Submission
summary: Review a pending submissions
tags:
- SubmissionAPI
/v1/schemas:
Expand Down
42 changes: 31 additions & 11 deletions pkg/server/router/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,20 @@ func NewOperationRouter(s svcframework.Service) (*OperationRouter, error) {
// @Failure 400 {string} string "Bad request"
// @Failure 500 {string} string "Internal server error"
// @Router /v1/operations/{id} [get]
func (pdr OperationRouter) GetOperation(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
return nil
func (o OperationRouter) GetOperation(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
id := framework.GetParam(ctx, IDParam)
if id == nil {
return framework.NewRequestError(
util.LoggingNewError("get operation request requires id"), http.StatusBadRequest)
}

op, err := o.service.GetOperation(operation.GetOperationRequest{ID: *id})

if err != nil {
return framework.NewRequestError(
util.LoggingErrorMsg(err, "failed getting operation"), http.StatusInternalServerError)
}
return framework.Respond(ctx, w, routerModel(op), http.StatusOK)
}

type GetOperationsRequest struct {
Expand Down Expand Up @@ -108,7 +120,7 @@ type GetOperationsResponse struct {
// @Failure 400 {string} string "Bad request"
// @Failure 500 {string} string "Internal server error"
// @Router /v1/operations [get]
func (pdr OperationRouter) GetOperations(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
func (o OperationRouter) GetOperations(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
var request GetOperationsRequest
if err := framework.Decode(r, &request); err != nil {
return framework.NewRequestError(
Expand All @@ -126,21 +138,29 @@ func (pdr OperationRouter) GetOperations(ctx context.Context, w http.ResponseWri
util.LoggingErrorMsg(err, "invalid get operations request"), http.StatusBadRequest)
}

ops, err := pdr.service.GetOperations(req)
ops, err := o.service.GetOperations(req)
if err != nil {
logrus.WithError(err).Error("getting operations from service")
return framework.NewRequestError(err, http.StatusInternalServerError)
}
resp := GetOperationsResponse{Operations: make([]Operation, len(ops.Operations))}
for i, op := range ops.Operations {
resp.Operations[i].ID = op.ID
resp.Operations[i].Done = op.Done
resp.Operations[i].Result.Error = op.Result.Error
resp.Operations[i].Result.Response = op.Result.Response
resp := GetOperationsResponse{Operations: make([]Operation, 0, len(ops.Operations))}
for _, op := range ops.Operations {
resp.Operations = append(resp.Operations, routerModel(op))
}
return framework.Respond(ctx, w, resp, http.StatusOK)
}

func routerModel(op operation.Operation) Operation {
return Operation{
ID: op.ID,
Done: op.Done,
Result: OperationResult{
Error: op.Result.Error,
Response: op.Result.Response,
},
}
}

// CancelOperation godoc
// @Summary Cancel an ongoing operation
// @Description Cancels an ongoing operation, if possible.
Expand All @@ -152,6 +172,6 @@ func (pdr OperationRouter) GetOperations(ctx context.Context, w http.ResponseWri
// @Failure 400 {string} string "Bad request"
// @Failure 500 {string} string "Internal server error"
// @Router /v1/operations [get]
func (pdr OperationRouter) CancelOperation(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
func (o OperationRouter) CancelOperation(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
return nil
}
Loading

0 comments on commit 1b9ee0a

Please sign in to comment.