2019-04-15 03:56:55 +00:00
|
|
|
package endpoints
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/go-kit/kit/endpoint"
|
2019-07-20 08:12:58 +00:00
|
|
|
|
2019-07-11 02:33:22 +00:00
|
|
|
"github.com/mitchell/selfpass/services/credentials/types"
|
2019-04-15 03:56:55 +00:00
|
|
|
)
|
|
|
|
|
2019-05-06 00:56:27 +00:00
|
|
|
func MakeCreateEndpoint(svc types.Service) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
|
|
|
|
r := request.(types.CredentialInput)
|
|
|
|
return svc.Create(ctx, r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeDeleteEndpoint(svc types.Service) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
|
|
|
|
r := request.(IDRequest)
|
|
|
|
return nil, svc.Delete(ctx, r.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeGetEndpoint(svc types.Service) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
|
|
|
|
r := request.(IDRequest)
|
|
|
|
return svc.Get(ctx, r.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 03:56:55 +00:00
|
|
|
func MakeGetAllMetadataEndpoint(svc types.Service) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
|
2019-07-12 01:02:46 +00:00
|
|
|
r := request.(SourceHostRequest)
|
2019-04-15 03:56:55 +00:00
|
|
|
|
|
|
|
mdch, errch := svc.GetAllMetadata(ctx, r.SourceHost)
|
|
|
|
|
|
|
|
return MetadataStream{
|
|
|
|
Metadata: mdch,
|
|
|
|
Errors: errch,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeUpdateEndpoint(svc types.Service) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
|
|
|
|
r := request.(UpdateRequest)
|
|
|
|
return svc.Update(ctx, r.ID, r.Credential)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type IDRequest struct {
|
|
|
|
ID string
|
|
|
|
}
|
|
|
|
|
2019-07-12 01:02:46 +00:00
|
|
|
type SourceHostRequest struct {
|
2019-04-15 03:56:55 +00:00
|
|
|
SourceHost string
|
|
|
|
}
|
|
|
|
|
|
|
|
type MetadataStream struct {
|
|
|
|
Metadata <-chan types.Metadata
|
|
|
|
Errors chan error
|
|
|
|
}
|
|
|
|
|
|
|
|
type UpdateRequest struct {
|
|
|
|
ID string
|
|
|
|
Credential types.CredentialInput
|
|
|
|
}
|