Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI upgrade to support credential creation etc. #110

Merged
merged 9 commits into from
Oct 18, 2024
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ ui:
session_cookie_authentication_key: "PjanW5cOBIlWzjLK23Q8NIo4va53e1bsgWmcqMdznVzkW3uEozfotj7MZsD7HpBo"
#The encryption key, must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 modes.
session_store_encryption_key: "SQxqb3LKw1YFyAiy4j7FaGGJKeEzr8Db"
session_inactivity_timeout_in_seconds: 600
services:
apigw:
base_url: http://vc_dev_apigw:8080
Expand Down
8 changes: 7 additions & 1 deletion internal/mockas/apiv1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type MockInputData struct {
FamilyName string `json:"family_name"`
BirthDate string `json:"birth_date"`
CollectID string `json:"collect_id"`
IdentitySchemaName string `json:"identity_schema_name"`
}

type uploadMock struct {
Expand Down Expand Up @@ -52,10 +53,15 @@ func (c *Client) mockOne(ctx context.Context, data MockInputData) (*uploadMock,
if data.CollectID == "" {
data.CollectID = gofakeit.UUID()
}

if data.DocumentID == "" {
data.DocumentID = gofakeit.UUID()
}

if data.IdentitySchemaName == "" {
data.IdentitySchemaName = "SE"
}

meta := &model.MetaData{
AuthenticSource: data.AuthenticSource,
DocumentType: data.DocumentType,
Expand Down Expand Up @@ -84,7 +90,7 @@ func (c *Client) mockOne(ctx context.Context, data MockInputData) (*uploadMock,
{
AuthenticSourcePersonID: data.AuthenticSourcePersonID,
Schema: &model.IdentitySchema{
Name: "SE",
Name: data.IdentitySchemaName,
Version: "1.0.0",
},
FamilyName: data.FamilyName,
Expand Down
24 changes: 24 additions & 0 deletions internal/ui/apiv1/apigw_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,27 @@ func (c *APIGWClient) Upload(req *apiv1_apigw.UploadRequest) (any, error) {
}
return reply, nil
}

func (c *APIGWClient) Credential(req *CredentialRequest) (any, error) {
reply, err := c.DoPostJSON("/api/v1/credential", req)
if err != nil {
return nil, err
}
return reply, nil
}

func (c *APIGWClient) GetDocument(req *GetDocumentRequest) (any, error) {
reply, err := c.DoPostJSON("/api/v1/document", req)
if err != nil {
return nil, err
}
return reply, nil
}

func (c *APIGWClient) Notification(request *NotificationRequest) (any, error) {
reply, err := c.DoPostJSON("/api/v1/notification", request)
if err != nil {
return nil, err
}
return reply, nil
}
63 changes: 52 additions & 11 deletions internal/ui/apiv1/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ func (c *Client) Health(ctx context.Context, req *apiv1_status.StatusRequest) (*
}

type LoginRequest struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
Username string `json:"username" validate:"required"`
Password string `json:"password" validate:"required"`
}

type LoggedinReply struct {
Username string `json:"username" binding:"required"`
Username string `json:"username" validate:"required"`
// LoggedInTime RFC3339
LoggedInTime time.Time `json:"logged_in_time" binding:"required"`
LoggedInTime time.Time `json:"logged_in_time" validate:"required"`
}

func (c *Client) Login(ctx context.Context, req *LoginRequest) (*LoggedinReply, error) {
Expand Down Expand Up @@ -55,12 +55,6 @@ type DocumentListRequest struct {
ValidTo int64 `json:"valid_to"`
}

type PortalRequest struct {
DocumentType string `json:"document_type" binding:"required"`
AuthenticSource string `json:"authentic_source" binding:"required"`
AuthenticSourcePersonId string `json:"authentic_source_person_id" binding:"required"`
}

func (c *Client) DocumentList(ctx context.Context, req *DocumentListRequest) (any, error) {
reply, err := c.apigwClient.DocumentList(req)
if err != nil {
Expand All @@ -77,8 +71,55 @@ func (c *Client) Upload(ctx context.Context, req *apiv1_apigw.UploadRequest) (an
return reply, nil
}

type CredentialRequest struct {
AuthenticSource string `json:"authentic_source" validate:"required"`
Identity *model.Identity `json:"identity" validate:"required"`
DocumentType string `json:"document_type" validate:"required"`
CredentialType string `json:"credential_type" validate:"required"`
CollectID string `json:"collect_id" validate:"required"`
}

func (c *Client) Credential(ctx context.Context, req *CredentialRequest) (any, error) {
reply, err := c.apigwClient.Credential(req)
if err != nil {
return nil, err
}
return reply, nil
}

type GetDocumentRequest struct {
AuthenticSource string `json:"authentic_source" validate:"required"`
DocumentType string `json:"document_type" validate:"required"`
DocumentID string `json:"document_id" validate:"required"`
}

func (c *Client) GetDocument(ctx context.Context, req *GetDocumentRequest) (any, error) {
reply, err := c.apigwClient.GetDocument(req)
if err != nil {
return nil, err
}
return reply, nil
}

type NotificationRequest struct {
AuthenticSource string `json:"authentic_source" validate:"required"`
DocumentType string `json:"document_type" validate:"required"`
DocumentID string `json:"document_id" validate:"required"`
}

func (c *Client) Notification(ctx context.Context, request *NotificationRequest) (any, error) {
reply, err := c.apigwClient.Notification(request)
if err != nil {
return nil, err
}
return reply, nil
}

type MockNextRequest struct {
PortalRequest
DocumentType string `json:"document_type" validate:"required"`
AuthenticSource string `json:"authentic_source" validate:"required"`
AuthenticSourcePersonId string `json:"authentic_source_person_id" validate:"required"`
IdentitySchemaName string `json:"identity_schema_name" validate:"required"`
}

func (c *Client) MockNext(ctx context.Context, req *MockNextRequest) (any, error) {
Expand Down
13 changes: 8 additions & 5 deletions internal/ui/httpserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import (

type Apiv1 interface {
// ui
Health(ctx context.Context, req *apiv1_status.StatusRequest) (*apiv1_status.StatusReply, error)
Login(ctx context.Context, req *apiv1.LoginRequest) (*apiv1.LoggedinReply, error)
Health(ctx context.Context, request *apiv1_status.StatusRequest) (*apiv1_status.StatusReply, error)
Login(ctx context.Context, request *apiv1.LoginRequest) (*apiv1.LoggedinReply, error)
Logout(ctx context.Context) error
User(ctx context.Context) (*apiv1.LoggedinReply, error)

// apigw
StatusAPIGW(ctx context.Context, request *apiv1_status.StatusRequest) (any, error)
DocumentList(ctx context.Context, req *apiv1.DocumentListRequest) (any, error)
Upload(ctx context.Context, req *apigw_apiv1.UploadRequest) (any, error)
DocumentList(ctx context.Context, request *apiv1.DocumentListRequest) (any, error)
Upload(ctx context.Context, request *apigw_apiv1.UploadRequest) (any, error)
Credential(ctx context.Context, request *apiv1.CredentialRequest) (any, error)
GetDocument(ctx context.Context, request *apiv1.GetDocumentRequest) (any, error)
Notification(ctx context.Context, reguest *apiv1.NotificationRequest) (any, error)

// mockas
MockNext(ctx context.Context, req *apiv1.MockNextRequest) (any, error)
MockNext(ctx context.Context, request *apiv1.MockNextRequest) (any, error)
}
53 changes: 42 additions & 11 deletions internal/ui/httpserver/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ func (s *Service) endpointHealth(ctx context.Context, c *gin.Context) (any, erro

func (s *Service) endpointLogin(ctx context.Context, c *gin.Context) (any, error) {
request := &apiv1.LoginRequest{}
//TODO(mk): use pkg bind.go after it has been fixed instead of context.go
if err := c.ShouldBindJSON(&request); err != nil {
if err := s.httpHelpers.Binding.Request(ctx, c, request); err != nil {
return nil, err
}

Expand Down Expand Up @@ -98,12 +97,11 @@ func (s *Service) endpointAPIGWStatus(ctx context.Context, c *gin.Context) (any,

func (s *Service) endpointDocumentList(ctx context.Context, c *gin.Context) (any, error) {
request := &apiv1.DocumentListRequest{}
//TODO(mk): use pkg bind.go after it has been fixed instead of context.go
if err := c.ShouldBindJSON(&request); err != nil {
if err := s.httpHelpers.Binding.Request(ctx, c, request); err != nil {
return nil, err
}
reply, err := s.apiv1.DocumentList(ctx, request)

reply, err := s.apiv1.DocumentList(ctx, request)
if err != nil {
return nil, err
}
Expand All @@ -112,14 +110,48 @@ func (s *Service) endpointDocumentList(ctx context.Context, c *gin.Context) (any

func (s *Service) endpointUpload(ctx context.Context, c *gin.Context) (any, error) {
request := &apiv1_apigw.UploadRequest{}
//TODO(mk): use pkg bind.go after it has been fixed instead of context.go
if err := c.ShouldBindJSON(&request); err != nil {
s.log.Debug("Binding error", "error", err)
if err := s.httpHelpers.Binding.Request(ctx, c, request); err != nil {
return nil, err
}

reply, err := s.apiv1.Upload(ctx, request)
if err != nil {
return nil, err
}
return reply, nil
}

func (s *Service) endpointCredential(ctx context.Context, c *gin.Context) (any, error) {
request := &apiv1.CredentialRequest{}
if err := s.httpHelpers.Binding.Request(ctx, c, request); err != nil {
return nil, err
}

reply, err := s.apiv1.Credential(ctx, request)
if err != nil {
return nil, err
}
return reply, nil
}

func (s *Service) endpointGetDocument(ctx context.Context, c *gin.Context) (any, error) {
request := &apiv1.GetDocumentRequest{}
if err := s.httpHelpers.Binding.Request(ctx, c, request); err != nil {
return nil, err
}
reply, err := s.apiv1.GetDocument(ctx, request)
if err != nil {
return nil, err
}
return reply, nil
}

func (s *Service) endpointNotification(ctx context.Context, c *gin.Context) (any, error) {
request := &apiv1.NotificationRequest{}
if err := s.httpHelpers.Binding.Request(ctx, c, request); err != nil {
return nil, err
}
reply, err := s.apiv1.Notification(ctx, request)
if err != nil {
return nil, err
}
Expand All @@ -128,12 +160,11 @@ func (s *Service) endpointUpload(ctx context.Context, c *gin.Context) (any, erro

func (s *Service) endpointMockNext(ctx context.Context, c *gin.Context) (any, error) {
request := &apiv1.MockNextRequest{}
//TODO(mk): use pkg bind.go after it has been fixed instead of context.go
if err := c.ShouldBindJSON(&request); err != nil {
if err := s.httpHelpers.Binding.Request(ctx, c, request); err != nil {
return nil, err
}
reply, err := s.apiv1.MockNext(ctx, request)

reply, err := s.apiv1.MockNext(ctx, request)
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion internal/ui/httpserver/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func New(ctx context.Context, cfg *model.Cfg, apiv1 *apiv1.Client, tracer *trace
server: &http.Server{},
sessionConfig: &sessionConfig{
name: "vc_ui_auth_session",
inactivityTimeoutInSeconds: 300,
inactivityTimeoutInSeconds: cfg.UI.SessionInactivityTimeoutInSeconds,
path: "/",
httpOnly: true,
secure: cfg.UI.APIServer.TLS.Enabled,
Expand Down Expand Up @@ -91,6 +91,9 @@ func New(ctx context.Context, cfg *model.Cfg, apiv1 *apiv1.Client, tracer *trace
s.httpHelpers.Server.RegEndpoint(ctx, rgAPIGW, http.MethodGet, "health", s.endpointAPIGWStatus)
s.httpHelpers.Server.RegEndpoint(ctx, rgAPIGW, http.MethodPost, "document/list", s.endpointDocumentList)
s.httpHelpers.Server.RegEndpoint(ctx, rgAPIGW, http.MethodPost, "upload", s.endpointUpload)
s.httpHelpers.Server.RegEndpoint(ctx, rgAPIGW, http.MethodPost, "credential", s.endpointCredential)
s.httpHelpers.Server.RegEndpoint(ctx, rgAPIGW, http.MethodPost, "document", s.endpointGetDocument)
s.httpHelpers.Server.RegEndpoint(ctx, rgAPIGW, http.MethodPost, "notification", s.endpointNotification)

rgMockAS := rgSecure.Group("mockas")
s.httpHelpers.Server.RegEndpoint(ctx, rgMockAS, http.MethodPost, "mock/next", s.endpointMockNext)
Expand Down
Loading
Loading