working, tested verify endpoint (#50)

This commit is contained in:
Michael Quigley 2022-09-19 16:26:54 -04:00
parent 08aba670ab
commit 6190ac0c60
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
10 changed files with 51 additions and 28 deletions

View File

@ -68,6 +68,25 @@ func (self *createAccountHandler) handleVerifiedCreate(params identity.CreateAcc
logrus.Error(err)
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
}
ar := &store.AccountRequest{
Token: token,
Email: params.Body.Email,
SourceAddress: params.HTTPRequest.RemoteAddr,
}
tx, err := str.Begin()
if err != nil {
logrus.Error(err)
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
}
defer func() { _ = tx.Rollback() }()
if _, err := str.CreateAccountRequest(ar, tx); err != nil {
logrus.Error(err)
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
}
if err := tx.Commit(); err != nil {
logrus.Error(err)
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
}
return identity.NewCreateAccountCreated()
}

View File

@ -1,7 +1,6 @@
package store
import (
"database/sql"
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
)
@ -14,7 +13,7 @@ type AccountRequest struct {
SourceAddress string
}
func (self *Store) CreateAccountRequest(ar *AccountRequest, tx *sql.Tx) (int, error) {
func (self *Store) CreateAccountRequest(ar *AccountRequest, tx *sqlx.Tx) (int, error) {
stmt, err := tx.Prepare("insert into account_requests (token, email, source_address) values (?, ?, ?)")
if err != nil {
return 0, errors.Wrap(err, "error preparing account_requests insert statement")

View File

@ -16,6 +16,7 @@ func newVerifyHandler(cfg *Config) *verifyHandler {
}
func (self *verifyHandler) Handle(params identity.VerifyParams) middleware.Responder {
if params.Body != nil {
logrus.Infof("received verify request for token '%v'", params.Body.Token)
tx, err := str.Begin()
if err != nil {
@ -28,4 +29,8 @@ func (self *verifyHandler) Handle(params identity.VerifyParams) middleware.Respo
return identity.NewVerifyNotFound()
}
return identity.NewVerifyOK().WithPayload(&rest_model_zrok.VerifyResponse{Email: ar.Email})
} else {
logrus.Error("empty verification request")
return identity.NewVerifyInternalServerError().WithPayload(rest_model_zrok.ErrorMessage("empty verification request"))
}
}

View File

@ -207,7 +207,7 @@ func (a *Client) Verify(params *VerifyParams, opts ...ClientOption) (*VerifyOK,
}
op := &runtime.ClientOperation{
ID: "verify",
Method: "GET",
Method: "POST",
PathPattern: "/verify",
ProducesMediaTypes: []string{"application/zrok.v1+json"},
ConsumesMediaTypes: []string{"application/zrok.v1+json"},

View File

@ -86,11 +86,11 @@ func (o *VerifyOK) IsCode(code int) bool {
}
func (o *VerifyOK) Error() string {
return fmt.Sprintf("[GET /verify][%d] verifyOK %+v", 200, o.Payload)
return fmt.Sprintf("[POST /verify][%d] verifyOK %+v", 200, o.Payload)
}
func (o *VerifyOK) String() string {
return fmt.Sprintf("[GET /verify][%d] verifyOK %+v", 200, o.Payload)
return fmt.Sprintf("[POST /verify][%d] verifyOK %+v", 200, o.Payload)
}
func (o *VerifyOK) GetPayload() *rest_model_zrok.VerifyResponse {
@ -148,11 +148,11 @@ func (o *VerifyNotFound) IsCode(code int) bool {
}
func (o *VerifyNotFound) Error() string {
return fmt.Sprintf("[GET /verify][%d] verifyNotFound ", 404)
return fmt.Sprintf("[POST /verify][%d] verifyNotFound ", 404)
}
func (o *VerifyNotFound) String() string {
return fmt.Sprintf("[GET /verify][%d] verifyNotFound ", 404)
return fmt.Sprintf("[POST /verify][%d] verifyNotFound ", 404)
}
func (o *VerifyNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
@ -200,11 +200,11 @@ func (o *VerifyInternalServerError) IsCode(code int) bool {
}
func (o *VerifyInternalServerError) Error() string {
return fmt.Sprintf("[GET /verify][%d] verifyInternalServerError %+v", 500, o.Payload)
return fmt.Sprintf("[POST /verify][%d] verifyInternalServerError %+v", 500, o.Payload)
}
func (o *VerifyInternalServerError) String() string {
return fmt.Sprintf("[GET /verify][%d] verifyInternalServerError %+v", 500, o.Payload)
return fmt.Sprintf("[POST /verify][%d] verifyInternalServerError %+v", 500, o.Payload)
}
func (o *VerifyInternalServerError) GetPayload() rest_model_zrok.ErrorMessage {

View File

@ -287,7 +287,7 @@ func init() {
}
},
"/verify": {
"get": {
"post": {
"tags": [
"identity"
],
@ -844,7 +844,7 @@ func init() {
}
},
"/verify": {
"get": {
"post": {
"tags": [
"identity"
],

View File

@ -30,7 +30,7 @@ func NewVerify(ctx *middleware.Context, handler VerifyHandler) *Verify {
}
/*
Verify swagger:route GET /verify identity verify
Verify swagger:route POST /verify identity verify
Verify verify API
*/

View File

@ -377,10 +377,10 @@ func (o *ZrokAPI) initHandlerCache() {
o.handlers["DELETE"] = make(map[string]http.Handler)
}
o.handlers["DELETE"]["/untunnel"] = tunnel.NewUntunnel(o.context, o.TunnelUntunnelHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
if o.handlers["POST"] == nil {
o.handlers["POST"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/verify"] = identity.NewVerify(o.context, o.IdentityVerifyHandler)
o.handlers["POST"]["/verify"] = identity.NewVerify(o.context, o.IdentityVerifyHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}

View File

@ -169,7 +169,7 @@ paths:
$ref: "#/definitions/errorMessage"
/verify:
get:
post:
tags:
- identity
operationId: verify

View File

@ -114,5 +114,5 @@ const loginOperation = {
const verifyOperation = {
path: '/verify',
contentTypes: ['application/zrok.v1+json'],
method: 'get'
method: 'post'
}