mirror of
https://github.com/openziti/zrok.git
synced 2025-02-06 21:39:39 +01:00
shortid (#79)
This commit is contained in:
parent
9b31da1039
commit
67377ed985
@ -22,7 +22,11 @@ func (self *createAccountHandler) Handle(params identity.CreateAccountParams) mi
|
||||
}
|
||||
logrus.Infof("received account request for email '%v'", params.Body.Email)
|
||||
|
||||
token := createToken()
|
||||
token, err := createToken()
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return identity.NewCreateAccountInternalServerError()
|
||||
}
|
||||
ar := &store.AccountRequest{
|
||||
Token: token,
|
||||
Email: params.Body.Email,
|
||||
|
@ -91,7 +91,10 @@ func (self *enableHandler) Handle(params identity.EnableParams, principal *rest_
|
||||
|
||||
func (self *enableHandler) createIdentity(email string, client *rest_management_api_client.ZitiEdgeManagement) (*identity_edge.CreateIdentityCreated, error) {
|
||||
iIsAdmin := false
|
||||
name := createToken()
|
||||
name, err := createToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
identityType := rest_model_edge.IdentityTypeUser
|
||||
tags := self.zrokTags()
|
||||
tags.SubTags["zrokEmail"] = email
|
||||
|
@ -33,10 +33,15 @@ func (self *registerHandler) Handle(params identity.RegisterParams) middleware.R
|
||||
return identity.NewRegisterNotFound()
|
||||
}
|
||||
|
||||
token, err := createToken()
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return identity.NewRegisterInternalServerError()
|
||||
}
|
||||
a := &store.Account{
|
||||
Email: ar.Email,
|
||||
Password: hashPassword(params.Body.Password),
|
||||
Token: createToken(),
|
||||
Token: token,
|
||||
}
|
||||
if _, err := str.CreateAccount(a, tx); err != nil {
|
||||
logrus.Error(err)
|
||||
|
@ -1,16 +1,14 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/sha512"
|
||||
"crypto/x509"
|
||||
"encoding/hex"
|
||||
errors2 "github.com/go-openapi/errors"
|
||||
"github.com/lithammer/shortuuid/v4"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||
"github.com/openziti/edge/rest_management_api_client"
|
||||
"github.com/openziti/edge/rest_util"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/teris-io/shortid"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
@ -45,16 +43,12 @@ func edgeClient(cfg *ZitiConfig) (*rest_management_api_client.ZitiEdgeManagement
|
||||
return rest_util.NewEdgeManagementClientWithUpdb(cfg.Username, cfg.Password, cfg.ApiEndpoint, caPool)
|
||||
}
|
||||
|
||||
func createToken() string {
|
||||
return shortuuid.New()
|
||||
func createToken() (string, error) {
|
||||
return shortid.Generate()
|
||||
}
|
||||
|
||||
func createServiceName() (string, error) {
|
||||
bytes := make([]byte, 4)
|
||||
if _, err := rand.Read(bytes); err != nil {
|
||||
return "", errors.Wrap(err, "error generating service name")
|
||||
}
|
||||
return hex.EncodeToString(bytes), nil
|
||||
return shortid.Generate()
|
||||
}
|
||||
|
||||
func hashPassword(raw string) string {
|
||||
|
1
go.mod
1
go.mod
@ -80,6 +80,7 @@ require (
|
||||
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/speps/go-hashids v2.0.0+incompatible // indirect
|
||||
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.10 // indirect
|
||||
github.com/tklauser/numcpus v0.4.0 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -514,6 +514,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
||||
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569 h1:xzABM9let0HLLqFypcxvLmlvEciCHL7+Lv+4vwZqecI=
|
||||
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569/go.mod h1:2Ly+NIftZN4de9zRmENdYbvPQeaVIYKWpLFStLFEBgI=
|
||||
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
|
||||
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw=
|
||||
|
Loading…
Reference in New Issue
Block a user