Merge pull request 'RefactorFileStructure' (#4) from RefactorFileStructure into main
Reviewed-on: https://git.infra.nkode.tech/dkelly/go-nkode/pulls/4
This commit is contained in:
108
cmd/main.go
Normal file
108
cmd/main.go
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
httpSwagger "github.com/swaggo/http-swagger"
|
||||||
|
_ "go-nkode/docs"
|
||||||
|
"go-nkode/internal/api"
|
||||||
|
"go-nkode/internal/db"
|
||||||
|
"go-nkode/internal/email"
|
||||||
|
"go-nkode/internal/models"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
emailQueueBufferSize = 100
|
||||||
|
maxEmailsPerSecond = 13 // SES allows 14, but I don't want to push it
|
||||||
|
)
|
||||||
|
|
||||||
|
// @title NKode API
|
||||||
|
// @version 1.0
|
||||||
|
// @description This is the NKode API server.
|
||||||
|
// @termsOfService http://nkode.example.com/terms/
|
||||||
|
|
||||||
|
// @contact.name API Support
|
||||||
|
// @contact.url http://nkode.example.com/support
|
||||||
|
// @contact.email support@nkode.example.com
|
||||||
|
|
||||||
|
// @license.name MIT
|
||||||
|
// @license.url https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
// @host localhost:8080
|
||||||
|
// @BasePath /
|
||||||
|
|
||||||
|
// @securityDefinitions.apiKey ApiKeyAuth
|
||||||
|
// @in header
|
||||||
|
// @name Authorization
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
dbPath := os.Getenv("SQLITE_DB")
|
||||||
|
if dbPath == "" {
|
||||||
|
log.Fatalf("SQLITE_DB=/path/to/nkode.db not set")
|
||||||
|
}
|
||||||
|
db := db.NewSqliteDB(dbPath)
|
||||||
|
defer db.CloseDb()
|
||||||
|
|
||||||
|
sesClient := email.NewSESClient()
|
||||||
|
emailQueue := email.NewEmailQueue(emailQueueBufferSize, maxEmailsPerSecond, &sesClient)
|
||||||
|
emailQueue.Start()
|
||||||
|
defer emailQueue.Stop()
|
||||||
|
|
||||||
|
nkodeApi := api.NewNKodeAPI(db, emailQueue)
|
||||||
|
AddDefaultCustomer(nkodeApi)
|
||||||
|
handler := api.NKodeHandler{Api: nkodeApi}
|
||||||
|
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.Handle(api.CreateNewCustomer, &handler)
|
||||||
|
mux.Handle(api.GenerateSignupResetInterface, &handler)
|
||||||
|
mux.Handle(api.SetNKode, &handler)
|
||||||
|
mux.Handle(api.ConfirmNKode, &handler)
|
||||||
|
mux.Handle(api.GetLoginInterface, &handler)
|
||||||
|
mux.Handle(api.Login, &handler)
|
||||||
|
mux.Handle(api.RenewAttributes, &handler)
|
||||||
|
mux.Handle(api.RandomSvgInterface, &handler)
|
||||||
|
mux.Handle(api.RefreshToken, &handler)
|
||||||
|
mux.Handle(api.ResetNKode, &handler)
|
||||||
|
|
||||||
|
// Serve Swagger UI
|
||||||
|
mux.Handle("/swagger/", httpSwagger.WrapHandler)
|
||||||
|
|
||||||
|
fmt.Println("Running on localhost:8080...")
|
||||||
|
log.Fatal(http.ListenAndServe(":8080", corsMiddleware(mux)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func corsMiddleware(next http.Handler) http.Handler {
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// Set the CORS headers
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||||
|
|
||||||
|
// Handle preflight requests
|
||||||
|
if r.Method == http.MethodOptions {
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the next handler
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddDefaultCustomer(nkodeApi api.NKodeAPI) {
|
||||||
|
newId, err := uuid.Parse("ed9ed6e0-082c-4b57-8d8c-f00ed6493457")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
customerId := models.CustomerId(newId)
|
||||||
|
nkodePolicy := models.NewDefaultNKodePolicy()
|
||||||
|
_, err = nkodeApi.CreateNewCustomer(nkodePolicy, &customerId)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
} else {
|
||||||
|
log.Println("created new customer: ", newId)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,8 +5,9 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"go-nkode/core"
|
"go-nkode/internal/api"
|
||||||
"go-nkode/util"
|
"go-nkode/internal/models"
|
||||||
|
"go-nkode/internal/security"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -15,94 +16,94 @@ import (
|
|||||||
|
|
||||||
func TestApi(t *testing.T) {
|
func TestApi(t *testing.T) {
|
||||||
base := "http://localhost:8080"
|
base := "http://localhost:8080"
|
||||||
newCustomerBody := core.NewCustomerPost{
|
newCustomerBody := models.NewCustomerPost{
|
||||||
NKodePolicy: core.NewDefaultNKodePolicy(),
|
NKodePolicy: models.NewDefaultNKodePolicy(),
|
||||||
}
|
}
|
||||||
kp := core.KeypadDimension{
|
kp := models.KeypadDimension{
|
||||||
AttrsPerKey: 14,
|
AttrsPerKey: 14,
|
||||||
NumbOfKeys: 10,
|
NumbOfKeys: 10,
|
||||||
}
|
}
|
||||||
var customerResp core.CreateNewCustomerResp
|
var customerResp models.CreateNewCustomerResp
|
||||||
testApiPost(t, base+core.CreateNewCustomer, newCustomerBody, &customerResp)
|
testApiPost(t, base+api.CreateNewCustomer, newCustomerBody, &customerResp)
|
||||||
|
|
||||||
userEmail := "test_username" + util.GenerateRandomString(12) + "@example.com"
|
userEmail := "test_username" + security.GenerateRandomString(12) + "@example.com"
|
||||||
signupInterfaceBody := core.GenerateSignupRestInterfacePost{
|
signupInterfaceBody := models.GenerateSignupRestInterfacePost{
|
||||||
CustomerId: customerResp.CustomerId,
|
CustomerId: customerResp.CustomerId,
|
||||||
AttrsPerKey: kp.AttrsPerKey,
|
AttrsPerKey: kp.AttrsPerKey,
|
||||||
NumbOfKeys: kp.NumbOfKeys,
|
NumbOfKeys: kp.NumbOfKeys,
|
||||||
UserEmail: strings.ToUpper(userEmail), // should be case-insensitive
|
UserEmail: strings.ToUpper(userEmail), // should be case-insensitive
|
||||||
Reset: false,
|
Reset: false,
|
||||||
}
|
}
|
||||||
var signupInterfaceResp core.GenerateSignupResetInterfaceResp
|
var signupInterfaceResp models.GenerateSignupResetInterfaceResp
|
||||||
testApiPost(t, base+core.GenerateSignupResetInterface, signupInterfaceBody, &signupInterfaceResp)
|
testApiPost(t, base+api.GenerateSignupResetInterface, signupInterfaceBody, &signupInterfaceResp)
|
||||||
assert.Len(t, signupInterfaceResp.SvgInterface, kp.TotalAttrs())
|
assert.Len(t, signupInterfaceResp.SvgInterface, kp.TotalAttrs())
|
||||||
passcodeLen := 4
|
passcodeLen := 4
|
||||||
setInterface := signupInterfaceResp.UserIdxInterface
|
setInterface := signupInterfaceResp.UserIdxInterface
|
||||||
userPasscode := setInterface[:passcodeLen]
|
userPasscode := setInterface[:passcodeLen]
|
||||||
kpSet := core.KeypadDimension{NumbOfKeys: kp.NumbOfKeys, AttrsPerKey: kp.NumbOfKeys}
|
kpSet := models.KeypadDimension{NumbOfKeys: kp.NumbOfKeys, AttrsPerKey: kp.NumbOfKeys}
|
||||||
setKeySelection, err := core.SelectKeyByAttrIdx(setInterface, userPasscode, kpSet)
|
setKeySelection, err := models.SelectKeyByAttrIdx(setInterface, userPasscode, kpSet)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
setNKodeBody := core.SetNKodePost{
|
setNKodeBody := models.SetNKodePost{
|
||||||
CustomerId: customerResp.CustomerId,
|
CustomerId: customerResp.CustomerId,
|
||||||
SessionId: signupInterfaceResp.SessionId,
|
SessionId: signupInterfaceResp.SessionId,
|
||||||
KeySelection: setKeySelection,
|
KeySelection: setKeySelection,
|
||||||
}
|
}
|
||||||
var setNKodeResp core.SetNKodeResp
|
var setNKodeResp models.SetNKodeResp
|
||||||
testApiPost(t, base+core.SetNKode, setNKodeBody, &setNKodeResp)
|
testApiPost(t, base+api.SetNKode, setNKodeBody, &setNKodeResp)
|
||||||
confirmInterface := setNKodeResp.UserInterface
|
confirmInterface := setNKodeResp.UserInterface
|
||||||
confirmKeySelection, err := core.SelectKeyByAttrIdx(confirmInterface, userPasscode, kpSet)
|
confirmKeySelection, err := models.SelectKeyByAttrIdx(confirmInterface, userPasscode, kpSet)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
confirmNKodeBody := core.ConfirmNKodePost{
|
confirmNKodeBody := models.ConfirmNKodePost{
|
||||||
CustomerId: customerResp.CustomerId,
|
CustomerId: customerResp.CustomerId,
|
||||||
KeySelection: confirmKeySelection,
|
KeySelection: confirmKeySelection,
|
||||||
SessionId: signupInterfaceResp.SessionId,
|
SessionId: signupInterfaceResp.SessionId,
|
||||||
}
|
}
|
||||||
testApiPost(t, base+core.ConfirmNKode, confirmNKodeBody, nil)
|
testApiPost(t, base+api.ConfirmNKode, confirmNKodeBody, nil)
|
||||||
|
|
||||||
loginInterfaceBody := core.GetLoginInterfacePost{
|
loginInterfaceBody := models.GetLoginInterfacePost{
|
||||||
CustomerId: customerResp.CustomerId,
|
CustomerId: customerResp.CustomerId,
|
||||||
UserEmail: userEmail,
|
UserEmail: userEmail,
|
||||||
}
|
}
|
||||||
|
|
||||||
var loginInterfaceResp core.GetLoginInterfaceResp
|
var loginInterfaceResp models.GetLoginInterfaceResp
|
||||||
testApiPost(t, base+core.GetLoginInterface, loginInterfaceBody, &loginInterfaceResp)
|
testApiPost(t, base+api.GetLoginInterface, loginInterfaceBody, &loginInterfaceResp)
|
||||||
assert.Equal(t, loginInterfaceResp.AttrsPerKey, kp.AttrsPerKey)
|
assert.Equal(t, loginInterfaceResp.AttrsPerKey, kp.AttrsPerKey)
|
||||||
assert.Equal(t, loginInterfaceResp.NumbOfKeys, kp.NumbOfKeys)
|
assert.Equal(t, loginInterfaceResp.NumbOfKeys, kp.NumbOfKeys)
|
||||||
loginKeySelection, err := core.SelectKeyByAttrIdx(loginInterfaceResp.UserIdxInterface, userPasscode, kp)
|
loginKeySelection, err := models.SelectKeyByAttrIdx(loginInterfaceResp.UserIdxInterface, userPasscode, kp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
loginBody := core.LoginPost{
|
loginBody := models.LoginPost{
|
||||||
CustomerId: customerResp.CustomerId,
|
CustomerId: customerResp.CustomerId,
|
||||||
UserEmail: userEmail,
|
UserEmail: userEmail,
|
||||||
KeySelection: loginKeySelection,
|
KeySelection: loginKeySelection,
|
||||||
}
|
}
|
||||||
|
|
||||||
var jwtTokens core.AuthenticationTokens
|
var jwtTokens security.AuthenticationTokens
|
||||||
testApiPost(t, base+core.Login, loginBody, &jwtTokens)
|
testApiPost(t, base+api.Login, loginBody, &jwtTokens)
|
||||||
refreshClaims, err := core.ParseRegisteredClaimToken(jwtTokens.RefreshToken)
|
refreshClaims, err := security.ParseRegisteredClaimToken(jwtTokens.RefreshToken)
|
||||||
assert.Equal(t, refreshClaims.Subject, userEmail)
|
assert.Equal(t, refreshClaims.Subject, userEmail)
|
||||||
accessClaims, err := core.ParseRegisteredClaimToken(jwtTokens.AccessToken)
|
accessClaims, err := security.ParseRegisteredClaimToken(jwtTokens.AccessToken)
|
||||||
assert.Equal(t, accessClaims.Subject, userEmail)
|
assert.Equal(t, accessClaims.Subject, userEmail)
|
||||||
renewBody := core.RenewAttributesPost{CustomerId: customerResp.CustomerId}
|
renewBody := models.RenewAttributesPost{CustomerId: customerResp.CustomerId}
|
||||||
testApiPost(t, base+core.RenewAttributes, renewBody, nil)
|
testApiPost(t, base+api.RenewAttributes, renewBody, nil)
|
||||||
|
|
||||||
loginKeySelection, err = core.SelectKeyByAttrIdx(loginInterfaceResp.UserIdxInterface, userPasscode, kp)
|
loginKeySelection, err = models.SelectKeyByAttrIdx(loginInterfaceResp.UserIdxInterface, userPasscode, kp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
loginBody = core.LoginPost{
|
loginBody = models.LoginPost{
|
||||||
CustomerId: customerResp.CustomerId,
|
CustomerId: customerResp.CustomerId,
|
||||||
UserEmail: userEmail,
|
UserEmail: userEmail,
|
||||||
KeySelection: loginKeySelection,
|
KeySelection: loginKeySelection,
|
||||||
}
|
}
|
||||||
|
|
||||||
testApiPost(t, base+core.Login, loginBody, &jwtTokens)
|
testApiPost(t, base+api.Login, loginBody, &jwtTokens)
|
||||||
|
|
||||||
var randomSvgInterfaceResp core.RandomSvgInterfaceResp
|
var randomSvgInterfaceResp models.RandomSvgInterfaceResp
|
||||||
testApiGet(t, base+core.RandomSvgInterface, &randomSvgInterfaceResp, "")
|
testApiGet(t, base+api.RandomSvgInterface, &randomSvgInterfaceResp, "")
|
||||||
assert.Equal(t, core.KeypadMax.TotalAttrs(), len(randomSvgInterfaceResp.Svgs))
|
assert.Equal(t, models.KeypadMax.TotalAttrs(), len(randomSvgInterfaceResp.Svgs))
|
||||||
|
|
||||||
var refreshTokenResp core.RefreshTokenResp
|
var refreshTokenResp models.RefreshTokenResp
|
||||||
|
|
||||||
testApiGet(t, base+core.RefreshToken, &refreshTokenResp, jwtTokens.RefreshToken)
|
testApiGet(t, base+api.RefreshToken, &refreshTokenResp, jwtTokens.RefreshToken)
|
||||||
accessClaims, err = core.ParseRegisteredClaimToken(refreshTokenResp.AccessToken)
|
accessClaims, err = security.ParseRegisteredClaimToken(refreshTokenResp.AccessToken)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, accessClaims.Subject, userEmail)
|
assert.Equal(t, accessClaims.Subject, userEmail)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package core
|
package config
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FrontendHost = "https://nkode.tech"
|
FrontendHost = "https://nkode.tech"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package core
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@@ -64,22 +64,3 @@ var HttpErrMap = map[error]int{
|
|||||||
ErrInvalidNKode: http.StatusBadRequest,
|
ErrInvalidNKode: http.StatusBadRequest,
|
||||||
ErrStringIsNotAnSVG: http.StatusInternalServerError,
|
ErrStringIsNotAnSVG: http.StatusInternalServerError,
|
||||||
}
|
}
|
||||||
|
|
||||||
var SetColors = []RGBColor{
|
|
||||||
{0, 0, 0}, // Black
|
|
||||||
{255, 0, 0}, // Red
|
|
||||||
{0, 128, 0}, // Dark Green
|
|
||||||
{0, 0, 255}, // Blue
|
|
||||||
{244, 200, 60}, // Yellow
|
|
||||||
{255, 0, 255}, // Magenta
|
|
||||||
{0, 200, 200}, // Cyan
|
|
||||||
{127, 0, 127}, // Purple
|
|
||||||
{232, 92, 13}, // Orange
|
|
||||||
{0, 127, 127}, // Teal
|
|
||||||
{127, 127, 0}, // Olive
|
|
||||||
{127, 0, 0}, // Dark Red
|
|
||||||
{128, 128, 128}, // Gray
|
|
||||||
{228, 102, 102}, // Dark Purple
|
|
||||||
{185, 17, 240}, // Salmon
|
|
||||||
{16, 200, 100}, // Green
|
|
||||||
}
|
|
||||||
129
docs/docs.go
Normal file
129
docs/docs.go
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
// Package docs Code generated by swaggo/swag. DO NOT EDIT
|
||||||
|
package docs
|
||||||
|
|
||||||
|
import "github.com/swaggo/swag"
|
||||||
|
|
||||||
|
const docTemplate = `{
|
||||||
|
"schemes": {{ marshal .Schemes }},
|
||||||
|
"swagger": "2.0",
|
||||||
|
"info": {
|
||||||
|
"description": "{{escape .Description}}",
|
||||||
|
"title": "{{.Title}}",
|
||||||
|
"termsOfService": "http://nkode.example.com/terms/",
|
||||||
|
"contact": {
|
||||||
|
"name": "API Support",
|
||||||
|
"url": "http://nkode.example.com/support",
|
||||||
|
"email": "support@nkode.example.com"
|
||||||
|
},
|
||||||
|
"license": {
|
||||||
|
"name": "MIT",
|
||||||
|
"url": "https://opensource.org/licenses/MIT"
|
||||||
|
},
|
||||||
|
"version": "{{.Version}}"
|
||||||
|
},
|
||||||
|
"host": "{{.Host}}",
|
||||||
|
"basePath": "{{.BasePath}}",
|
||||||
|
"paths": {
|
||||||
|
"/create-new-customer": {
|
||||||
|
"post": {
|
||||||
|
"description": "Creates a new customer based on the provided policy information.",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"customers"
|
||||||
|
],
|
||||||
|
"summary": "Create a new customer",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "Customer creation data",
|
||||||
|
"name": "NewCustomerPost",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/core.NewCustomerPost"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/core.CreateNewCustomerResp"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"core.CreateNewCustomerResp": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"customer_id": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"core.NKodePolicy": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"distinct_attributes": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"distinct_sets": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"expiration": {
|
||||||
|
"description": "seconds, -1 no expiration",
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"lock_out": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"max_nkode_len": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"min_nkode_len": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"core.NewCustomerPost": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"nkode_policy": {
|
||||||
|
"$ref": "#/definitions/core.NKodePolicy"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"securityDefinitions": {
|
||||||
|
"ApiKeyAuth": {
|
||||||
|
"type": "apiKey",
|
||||||
|
"name": "Authorization",
|
||||||
|
"in": "header"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
|
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||||
|
var SwaggerInfo = &swag.Spec{
|
||||||
|
Version: "1.0",
|
||||||
|
Host: "localhost:8080",
|
||||||
|
BasePath: "/",
|
||||||
|
Schemes: []string{},
|
||||||
|
Title: "NKode API",
|
||||||
|
Description: "This is the NKode API server.",
|
||||||
|
InfoInstanceName: "swagger",
|
||||||
|
SwaggerTemplate: docTemplate,
|
||||||
|
LeftDelim: "{{",
|
||||||
|
RightDelim: "}}",
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
||||||
|
}
|
||||||
105
docs/swagger.json
Normal file
105
docs/swagger.json
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
{
|
||||||
|
"swagger": "2.0",
|
||||||
|
"info": {
|
||||||
|
"description": "This is the NKode API server.",
|
||||||
|
"title": "NKode API",
|
||||||
|
"termsOfService": "http://nkode.example.com/terms/",
|
||||||
|
"contact": {
|
||||||
|
"name": "API Support",
|
||||||
|
"url": "http://nkode.example.com/support",
|
||||||
|
"email": "support@nkode.example.com"
|
||||||
|
},
|
||||||
|
"license": {
|
||||||
|
"name": "MIT",
|
||||||
|
"url": "https://opensource.org/licenses/MIT"
|
||||||
|
},
|
||||||
|
"version": "1.0"
|
||||||
|
},
|
||||||
|
"host": "localhost:8080",
|
||||||
|
"basePath": "/",
|
||||||
|
"paths": {
|
||||||
|
"/create-new-customer": {
|
||||||
|
"post": {
|
||||||
|
"description": "Creates a new customer based on the provided policy information.",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"customers"
|
||||||
|
],
|
||||||
|
"summary": "Create a new customer",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "Customer creation data",
|
||||||
|
"name": "NewCustomerPost",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/core.NewCustomerPost"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/core.CreateNewCustomerResp"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"core.CreateNewCustomerResp": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"customer_id": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"core.NKodePolicy": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"distinct_attributes": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"distinct_sets": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"expiration": {
|
||||||
|
"description": "seconds, -1 no expiration",
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"lock_out": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"max_nkode_len": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"min_nkode_len": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"core.NewCustomerPost": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"nkode_policy": {
|
||||||
|
"$ref": "#/definitions/core.NKodePolicy"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"securityDefinitions": {
|
||||||
|
"ApiKeyAuth": {
|
||||||
|
"type": "apiKey",
|
||||||
|
"name": "Authorization",
|
||||||
|
"in": "header"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
70
docs/swagger.yaml
Normal file
70
docs/swagger.yaml
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
basePath: /
|
||||||
|
definitions:
|
||||||
|
core.CreateNewCustomerResp:
|
||||||
|
properties:
|
||||||
|
customer_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
core.NKodePolicy:
|
||||||
|
properties:
|
||||||
|
distinct_attributes:
|
||||||
|
type: integer
|
||||||
|
distinct_sets:
|
||||||
|
type: integer
|
||||||
|
expiration:
|
||||||
|
description: seconds, -1 no expiration
|
||||||
|
type: integer
|
||||||
|
lock_out:
|
||||||
|
type: integer
|
||||||
|
max_nkode_len:
|
||||||
|
type: integer
|
||||||
|
min_nkode_len:
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
|
core.NewCustomerPost:
|
||||||
|
properties:
|
||||||
|
nkode_policy:
|
||||||
|
$ref: '#/definitions/core.NKodePolicy'
|
||||||
|
type: object
|
||||||
|
host: localhost:8080
|
||||||
|
info:
|
||||||
|
contact:
|
||||||
|
email: support@nkode.example.com
|
||||||
|
name: API Support
|
||||||
|
url: http://nkode.example.com/support
|
||||||
|
description: This is the NKode API server.
|
||||||
|
license:
|
||||||
|
name: MIT
|
||||||
|
url: https://opensource.org/licenses/MIT
|
||||||
|
termsOfService: http://nkode.example.com/terms/
|
||||||
|
title: NKode API
|
||||||
|
version: "1.0"
|
||||||
|
paths:
|
||||||
|
/create-new-customer:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Creates a new customer based on the provided policy information.
|
||||||
|
parameters:
|
||||||
|
- description: Customer creation data
|
||||||
|
in: body
|
||||||
|
name: NewCustomerPost
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/core.NewCustomerPost'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/core.CreateNewCustomerResp'
|
||||||
|
summary: Create a new customer
|
||||||
|
tags:
|
||||||
|
- customers
|
||||||
|
securityDefinitions:
|
||||||
|
ApiKeyAuth:
|
||||||
|
in: header
|
||||||
|
name: Authorization
|
||||||
|
type: apiKey
|
||||||
|
swagger: "2.0"
|
||||||
47
go.mod
47
go.mod
@@ -5,15 +5,22 @@ go 1.22.0
|
|||||||
toolchain go1.23.0
|
toolchain go1.23.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/aws/aws-sdk-go-v2 v1.31.0
|
||||||
|
github.com/aws/aws-sdk-go-v2/config v1.27.37
|
||||||
|
github.com/aws/aws-sdk-go-v2/service/ses v1.27.1
|
||||||
|
github.com/golang-jwt/jwt/v5 v5.2.1
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/mattn/go-sqlite3 v1.14.22
|
github.com/mattn/go-sqlite3 v1.14.22
|
||||||
|
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
golang.org/x/crypto v0.26.0
|
github.com/swaggo/http-swagger v1.3.4
|
||||||
|
github.com/swaggo/swag v1.16.4
|
||||||
|
github.com/swaggo/swag/example/celler v0.0.0-20241025062444-99698582709d
|
||||||
|
golang.org/x/crypto v0.29.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/aws/aws-sdk-go-v2 v1.31.0 // indirect
|
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.27.37 // indirect
|
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.35 // indirect
|
github.com/aws/aws-sdk-go-v2/credentials v1.17.35 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.14 // indirect
|
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.14 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.18 // indirect
|
||||||
@@ -21,15 +28,43 @@ require (
|
|||||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.5 // indirect
|
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.5 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.20 // indirect
|
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.20 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/ses v1.27.1 // indirect
|
|
||||||
github.com/aws/aws-sdk-go-v2/service/sso v1.23.1 // indirect
|
github.com/aws/aws-sdk-go-v2/service/sso v1.23.1 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.1 // indirect
|
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.27.1 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/service/sts v1.31.1 // indirect
|
github.com/aws/aws-sdk-go-v2/service/sts v1.31.1 // indirect
|
||||||
github.com/aws/smithy-go v1.21.0 // indirect
|
github.com/aws/smithy-go v1.21.0 // indirect
|
||||||
|
github.com/bytedance/sonic v1.9.1 // indirect
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||||
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
|
github.com/gin-gonic/gin v1.9.1 // indirect
|
||||||
|
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
||||||
|
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
||||||
|
github.com/go-openapi/spec v0.21.0 // indirect
|
||||||
|
github.com/go-openapi/swag v0.23.0 // indirect
|
||||||
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
|
github.com/go-playground/validator/v10 v10.14.0 // indirect
|
||||||
|
github.com/goccy/go-json v0.10.2 // indirect
|
||||||
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
github.com/jmespath/go-jmespath v0.4.0 // indirect
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
|
||||||
|
github.com/leodido/go-urn v1.2.4 // indirect
|
||||||
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
|
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/swaggo/files v1.0.1 // indirect
|
||||||
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
|
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||||
|
golang.org/x/arch v0.3.0 // indirect
|
||||||
|
golang.org/x/net v0.31.0 // indirect
|
||||||
|
golang.org/x/sys v0.27.0 // indirect
|
||||||
|
golang.org/x/text v0.20.0 // indirect
|
||||||
|
golang.org/x/tools v0.27.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.33.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
144
go.sum
144
go.sum
@@ -1,5 +1,5 @@
|
|||||||
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
|
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
||||||
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
|
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
||||||
github.com/aws/aws-sdk-go-v2 v1.31.0 h1:3V05LbxTSItI5kUqNwhJrrrY1BAXxXt0sN0l72QmG5U=
|
github.com/aws/aws-sdk-go-v2 v1.31.0 h1:3V05LbxTSItI5kUqNwhJrrrY1BAXxXt0sN0l72QmG5U=
|
||||||
github.com/aws/aws-sdk-go-v2 v1.31.0/go.mod h1:ztolYtaEUtdpf9Wftr31CJfLVjOnD/CVRkKOOYgF8hA=
|
github.com/aws/aws-sdk-go-v2 v1.31.0/go.mod h1:ztolYtaEUtdpf9Wftr31CJfLVjOnD/CVRkKOOYgF8hA=
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.27.37 h1:xaoIwzHVuRWRHFI0jhgEdEGc8xE1l91KaeRDsWEIncU=
|
github.com/aws/aws-sdk-go-v2/config v1.27.37 h1:xaoIwzHVuRWRHFI0jhgEdEGc8xE1l91KaeRDsWEIncU=
|
||||||
@@ -28,31 +28,161 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.31.1 h1:8K0UNOkZiK9Uh3HIF6Bx0rcNCftq
|
|||||||
github.com/aws/aws-sdk-go-v2/service/sts v1.31.1/go.mod h1:yMWe0F+XG0DkRZK5ODZhG7BEFYhLXi2dqGsv6tX0cgI=
|
github.com/aws/aws-sdk-go-v2/service/sts v1.31.1/go.mod h1:yMWe0F+XG0DkRZK5ODZhG7BEFYhLXi2dqGsv6tX0cgI=
|
||||||
github.com/aws/smithy-go v1.21.0 h1:H7L8dtDRk0P1Qm6y0ji7MCYMQObJ5R9CRpyPhRUkLYA=
|
github.com/aws/smithy-go v1.21.0 h1:H7L8dtDRk0P1Qm6y0ji7MCYMQObJ5R9CRpyPhRUkLYA=
|
||||||
github.com/aws/smithy-go v1.21.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
|
github.com/aws/smithy-go v1.21.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
|
||||||
|
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
|
||||||
|
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
|
||||||
|
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
|
||||||
|
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||||
|
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
|
||||||
|
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||||
|
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||||
|
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
|
||||||
|
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
|
||||||
|
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
|
||||||
|
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
|
||||||
|
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
|
||||||
|
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
|
||||||
|
github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY=
|
||||||
|
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
|
||||||
|
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
|
||||||
|
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
|
||||||
|
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||||
|
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||||
|
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
||||||
|
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||||
|
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||||
|
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||||
|
github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js=
|
||||||
|
github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
||||||
|
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||||
|
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||||
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
|
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
|
||||||
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
|
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
|
||||||
|
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
|
||||||
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
|
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
|
||||||
|
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||||
|
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||||
|
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||||
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
|
||||||
|
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
|
||||||
|
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
||||||
|
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||||
|
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||||
|
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||||
|
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||||
|
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||||
|
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
|
||||||
|
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||||
|
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
github.com/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE=
|
||||||
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg=
|
||||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
|
github.com/swaggo/http-swagger v1.3.4 h1:q7t/XLx0n15H1Q9/tk3Y9L4n210XzJF5WtnDX64a5ww=
|
||||||
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
|
github.com/swaggo/http-swagger v1.3.4/go.mod h1:9dAh0unqMBAlbp1uE2Uc2mQTxNMU/ha4UbucIg1MFkQ=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
github.com/swaggo/swag v1.16.4 h1:clWJtd9LStiG3VeijiCfOVODP6VpHtKdQy9ELFG3s1A=
|
||||||
|
github.com/swaggo/swag v1.16.4/go.mod h1:VBsHJRsDvfYvqoiMKnsdwhNV9LEMHgEDZcyVYX0sxPg=
|
||||||
|
github.com/swaggo/swag/example/celler v0.0.0-20241025062444-99698582709d h1:zyYK35EKMhtoXGSxZJm9yxO9KzYEr0M9/63FhaBKr4c=
|
||||||
|
github.com/swaggo/swag/example/celler v0.0.0-20241025062444-99698582709d/go.mod h1:kw/fmH4DXH7Dp7d8aLEU1ub7UA82GhJJ0ZABDxEJaM0=
|
||||||
|
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||||
|
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||||
|
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||||
|
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||||
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
|
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
|
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
|
||||||
|
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
|
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
|
||||||
|
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
|
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
|
||||||
|
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
|
||||||
|
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
|
||||||
|
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
||||||
|
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
|
||||||
|
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o=
|
||||||
|
golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||||
|
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||||
|
|||||||
20
internal/api/db_interface.go
Normal file
20
internal/api/db_interface.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-nkode/internal/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DbAccessor interface {
|
||||||
|
GetCustomer(models.CustomerId) (*models.Customer, error)
|
||||||
|
GetUser(models.UserEmail, models.CustomerId) (*models.User, error)
|
||||||
|
WriteNewCustomer(models.Customer) error
|
||||||
|
WriteNewUser(models.User) error
|
||||||
|
UpdateUserNKode(models.User) error
|
||||||
|
UpdateUserInterface(models.UserId, models.UserInterface) error
|
||||||
|
UpdateUserRefreshToken(models.UserId, string) error
|
||||||
|
Renew(models.CustomerId) error
|
||||||
|
RefreshUserPasscode(models.User, []int, models.CustomerAttributes) error
|
||||||
|
RandomSvgInterface(models.KeypadDimension) ([]string, error)
|
||||||
|
RandomSvgIdxInterface(models.KeypadDimension) (models.SvgIdInterface, error)
|
||||||
|
GetSvgStringInterface(models.SvgIdInterface) ([]string, error)
|
||||||
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
package core
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"go-nkode/config"
|
||||||
|
"go-nkode/internal/models"
|
||||||
|
"go-nkode/internal/security"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -63,13 +66,22 @@ func (h *NKodeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateNewCustomerHandler handles the creation of a new customer.
|
||||||
|
// @Summary Create a new customer
|
||||||
|
// @Description Creates a new customer based on the provided policy information.
|
||||||
|
// @Tags customers
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param NewCustomerPost body NewCustomerPost true "Customer creation data"
|
||||||
|
// @Success 200 {object} CreateNewCustomerResp
|
||||||
|
// @Router /create-new-customer [post]
|
||||||
func (h *NKodeHandler) CreateNewCustomerHandler(w http.ResponseWriter, r *http.Request) {
|
func (h *NKodeHandler) CreateNewCustomerHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Print("create new customer")
|
log.Print("create new customer")
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
methodNotAllowed(w)
|
methodNotAllowed(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var customerPost NewCustomerPost
|
var customerPost models.NewCustomerPost
|
||||||
if err := decodeJson(w, r, &customerPost); err != nil {
|
if err := decodeJson(w, r, &customerPost); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -78,7 +90,7 @@ func (h *NKodeHandler) CreateNewCustomerHandler(w http.ResponseWriter, r *http.R
|
|||||||
handleError(w, err)
|
handleError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
respBody := CreateNewCustomerResp{
|
respBody := models.CreateNewCustomerResp{
|
||||||
CustomerId: uuid.UUID(*customerId).String(),
|
CustomerId: uuid.UUID(*customerId).String(),
|
||||||
}
|
}
|
||||||
marshalAndWriteBytes(w, respBody)
|
marshalAndWriteBytes(w, respBody)
|
||||||
@@ -91,12 +103,12 @@ func (h *NKodeHandler) GenerateSignupResetInterfaceHandler(w http.ResponseWriter
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var signupResetPost GenerateSignupRestInterfacePost
|
var signupResetPost models.GenerateSignupRestInterfacePost
|
||||||
if err := decodeJson(w, r, &signupResetPost); err != nil {
|
if err := decodeJson(w, r, &signupResetPost); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
kp := KeypadDimension{
|
kp := models.KeypadDimension{
|
||||||
AttrsPerKey: signupResetPost.AttrsPerKey,
|
AttrsPerKey: signupResetPost.AttrsPerKey,
|
||||||
NumbOfKeys: signupResetPost.NumbOfKeys,
|
NumbOfKeys: signupResetPost.NumbOfKeys,
|
||||||
}
|
}
|
||||||
@@ -109,12 +121,12 @@ func (h *NKodeHandler) GenerateSignupResetInterfaceHandler(w http.ResponseWriter
|
|||||||
badRequest(w, malformedCustomerId)
|
badRequest(w, malformedCustomerId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userEmail, err := ParseEmail(signupResetPost.UserEmail)
|
userEmail, err := models.ParseEmail(signupResetPost.UserEmail)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
badRequest(w, malformedUserEmail)
|
badRequest(w, malformedUserEmail)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp, err := h.Api.GenerateSignupResetInterface(userEmail, CustomerId(customerId), kp, signupResetPost.Reset)
|
resp, err := h.Api.GenerateSignupResetInterface(userEmail, models.CustomerId(customerId), kp, signupResetPost.Reset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(w, err)
|
handleError(w, err)
|
||||||
return
|
return
|
||||||
@@ -129,7 +141,7 @@ func (h *NKodeHandler) SetNKodeHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
methodNotAllowed(w)
|
methodNotAllowed(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var setNKodePost SetNKodePost
|
var setNKodePost models.SetNKodePost
|
||||||
if err := decodeJson(w, r, &setNKodePost); err != nil {
|
if err := decodeJson(w, r, &setNKodePost); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -143,12 +155,12 @@ func (h *NKodeHandler) SetNKodeHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
badRequest(w, malformedSessionId)
|
badRequest(w, malformedSessionId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
confirmInterface, err := h.Api.SetNKode(CustomerId(customerId), SessionId(sessionId), setNKodePost.KeySelection)
|
confirmInterface, err := h.Api.SetNKode(models.CustomerId(customerId), models.SessionId(sessionId), setNKodePost.KeySelection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(w, err)
|
handleError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
respBody := SetNKodeResp{UserInterface: confirmInterface}
|
respBody := models.SetNKodeResp{UserInterface: confirmInterface}
|
||||||
marshalAndWriteBytes(w, respBody)
|
marshalAndWriteBytes(w, respBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,7 +171,7 @@ func (h *NKodeHandler) ConfirmNKodeHandler(w http.ResponseWriter, r *http.Reques
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var confirmNKodePost ConfirmNKodePost
|
var confirmNKodePost models.ConfirmNKodePost
|
||||||
if err := decodeJson(w, r, &confirmNKodePost); err != nil {
|
if err := decodeJson(w, r, &confirmNKodePost); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -173,7 +185,7 @@ func (h *NKodeHandler) ConfirmNKodeHandler(w http.ResponseWriter, r *http.Reques
|
|||||||
badRequest(w, malformedSessionId)
|
badRequest(w, malformedSessionId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = h.Api.ConfirmNKode(CustomerId(customerId), SessionId(sessionId), confirmNKodePost.KeySelection); err != nil {
|
if err = h.Api.ConfirmNKode(models.CustomerId(customerId), models.SessionId(sessionId), confirmNKodePost.KeySelection); err != nil {
|
||||||
handleError(w, err)
|
handleError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -186,7 +198,7 @@ func (h *NKodeHandler) GetLoginInterfaceHandler(w http.ResponseWriter, r *http.R
|
|||||||
methodNotAllowed(w)
|
methodNotAllowed(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var loginInterfacePost GetLoginInterfacePost
|
var loginInterfacePost models.GetLoginInterfacePost
|
||||||
if err := decodeJson(w, r, &loginInterfacePost); err != nil {
|
if err := decodeJson(w, r, &loginInterfacePost); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -195,11 +207,11 @@ func (h *NKodeHandler) GetLoginInterfaceHandler(w http.ResponseWriter, r *http.R
|
|||||||
badRequest(w, malformedCustomerId)
|
badRequest(w, malformedCustomerId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userEmail, err := ParseEmail(loginInterfacePost.UserEmail)
|
userEmail, err := models.ParseEmail(loginInterfacePost.UserEmail)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
badRequest(w, malformedUserEmail)
|
badRequest(w, malformedUserEmail)
|
||||||
}
|
}
|
||||||
loginInterface, err := h.Api.GetLoginInterface(userEmail, CustomerId(customerId))
|
loginInterface, err := h.Api.GetLoginInterface(userEmail, models.CustomerId(customerId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(w, err)
|
handleError(w, err)
|
||||||
return
|
return
|
||||||
@@ -214,7 +226,7 @@ func (h *NKodeHandler) LoginHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
methodNotAllowed(w)
|
methodNotAllowed(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var loginPost LoginPost
|
var loginPost models.LoginPost
|
||||||
if err := decodeJson(w, r, &loginPost); err != nil {
|
if err := decodeJson(w, r, &loginPost); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -223,12 +235,12 @@ func (h *NKodeHandler) LoginHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
badRequest(w, malformedCustomerId)
|
badRequest(w, malformedCustomerId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userEmail, err := ParseEmail(loginPost.UserEmail)
|
userEmail, err := models.ParseEmail(loginPost.UserEmail)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
badRequest(w, malformedUserEmail)
|
badRequest(w, malformedUserEmail)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
jwtTokens, err := h.Api.Login(CustomerId(customerId), userEmail, loginPost.KeySelection)
|
jwtTokens, err := h.Api.Login(models.CustomerId(customerId), userEmail, loginPost.KeySelection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(w, err)
|
handleError(w, err)
|
||||||
return
|
return
|
||||||
@@ -243,7 +255,7 @@ func (h *NKodeHandler) RenewAttributesHandler(w http.ResponseWriter, r *http.Req
|
|||||||
methodNotAllowed(w)
|
methodNotAllowed(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var renewAttributesPost RenewAttributesPost
|
var renewAttributesPost models.RenewAttributesPost
|
||||||
if err := decodeJson(w, r, &renewAttributesPost); err != nil {
|
if err := decodeJson(w, r, &renewAttributesPost); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -252,7 +264,7 @@ func (h *NKodeHandler) RenewAttributesHandler(w http.ResponseWriter, r *http.Req
|
|||||||
badRequest(w, malformedCustomerId)
|
badRequest(w, malformedCustomerId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = h.Api.RenewAttributes(CustomerId(customerId)); err != nil {
|
if err = h.Api.RenewAttributes(models.CustomerId(customerId)); err != nil {
|
||||||
handleError(w, err)
|
handleError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -271,9 +283,9 @@ func (h *NKodeHandler) RandomSvgInterfaceHandler(w http.ResponseWriter, r *http.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
respBody := RandomSvgInterfaceResp{
|
respBody := models.RandomSvgInterfaceResp{
|
||||||
Svgs: svgs,
|
Svgs: svgs,
|
||||||
Colors: SetColors,
|
Colors: models.SetColors,
|
||||||
}
|
}
|
||||||
|
|
||||||
marshalAndWriteBytes(w, respBody)
|
marshalAndWriteBytes(w, respBody)
|
||||||
@@ -289,26 +301,26 @@ func (h *NKodeHandler) RefreshTokenHandler(w http.ResponseWriter, r *http.Reques
|
|||||||
forbidden(w)
|
forbidden(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
refreshClaims, err := ParseRegisteredClaimToken(refreshToken)
|
refreshClaims, err := security.ParseRegisteredClaimToken(refreshToken)
|
||||||
customerId, err := uuid.Parse(refreshClaims.Issuer)
|
customerId, err := uuid.Parse(refreshClaims.Issuer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
badRequest(w, malformedCustomerId)
|
badRequest(w, malformedCustomerId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userEmail, err := ParseEmail(refreshClaims.Subject)
|
userEmail, err := models.ParseEmail(refreshClaims.Subject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
badRequest(w, malformedUserEmail)
|
badRequest(w, malformedUserEmail)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accessToken, err := h.Api.RefreshToken(userEmail, CustomerId(customerId), refreshToken)
|
accessToken, err := h.Api.RefreshToken(userEmail, models.CustomerId(customerId), refreshToken)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handleError(w, err)
|
handleError(w, err)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
marshalAndWriteBytes(w, RefreshTokenResp{AccessToken: accessToken})
|
marshalAndWriteBytes(w, models.RefreshTokenResp{AccessToken: accessToken})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *NKodeHandler) ResetNKode(w http.ResponseWriter, r *http.Request) {
|
func (h *NKodeHandler) ResetNKode(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -316,7 +328,7 @@ func (h *NKodeHandler) ResetNKode(w http.ResponseWriter, r *http.Request) {
|
|||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
methodNotAllowed(w)
|
methodNotAllowed(w)
|
||||||
}
|
}
|
||||||
var resetNKodePost ResetNKodePost
|
var resetNKodePost models.ResetNKodePost
|
||||||
if err := decodeJson(w, r, &resetNKodePost); err != nil {
|
if err := decodeJson(w, r, &resetNKodePost); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -327,13 +339,13 @@ func (h *NKodeHandler) ResetNKode(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userEmail, err := ParseEmail(resetNKodePost.UserEmail)
|
userEmail, err := models.ParseEmail(resetNKodePost.UserEmail)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
badRequest(w, malformedUserEmail)
|
badRequest(w, malformedUserEmail)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = h.Api.ResetNKode(userEmail, CustomerId(customerId)); err != nil {
|
if err = h.Api.ResetNKode(userEmail, models.CustomerId(customerId)); err != nil {
|
||||||
internalServerError(w)
|
internalServerError(w)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
return
|
||||||
@@ -386,7 +398,7 @@ func forbidden(w http.ResponseWriter) {
|
|||||||
|
|
||||||
func handleError(w http.ResponseWriter, err error) {
|
func handleError(w http.ResponseWriter, err error) {
|
||||||
log.Print("handling error: ", err)
|
log.Print("handling error: ", err)
|
||||||
statusCode, exists := HttpErrMap[err]
|
statusCode, exists := config.HttpErrMap[err]
|
||||||
if !exists {
|
if !exists {
|
||||||
internalServerError(w)
|
internalServerError(w)
|
||||||
return
|
return
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
package core
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/patrickmn/go-cache"
|
"github.com/patrickmn/go-cache"
|
||||||
|
"go-nkode/config"
|
||||||
|
"go-nkode/internal/email"
|
||||||
|
"go-nkode/internal/models"
|
||||||
|
"go-nkode/internal/security"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@@ -17,10 +21,10 @@ const (
|
|||||||
type NKodeAPI struct {
|
type NKodeAPI struct {
|
||||||
Db DbAccessor
|
Db DbAccessor
|
||||||
SignupSessionCache *cache.Cache
|
SignupSessionCache *cache.Cache
|
||||||
EmailQueue *EmailQueue
|
EmailQueue *email.EmailQueue
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNKodeAPI(db DbAccessor, queue *EmailQueue) NKodeAPI {
|
func NewNKodeAPI(db DbAccessor, queue *email.EmailQueue) NKodeAPI {
|
||||||
return NKodeAPI{
|
return NKodeAPI{
|
||||||
Db: db,
|
Db: db,
|
||||||
EmailQueue: queue,
|
EmailQueue: queue,
|
||||||
@@ -28,8 +32,8 @@ func NewNKodeAPI(db DbAccessor, queue *EmailQueue) NKodeAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) CreateNewCustomer(nkodePolicy NKodePolicy, id *CustomerId) (*CustomerId, error) {
|
func (n *NKodeAPI) CreateNewCustomer(nkodePolicy models.NKodePolicy, id *models.CustomerId) (*models.CustomerId, error) {
|
||||||
newCustomer, err := NewCustomer(nkodePolicy)
|
newCustomer, err := models.NewCustomer(nkodePolicy)
|
||||||
if id != nil {
|
if id != nil {
|
||||||
newCustomer.Id = *id
|
newCustomer.Id = *id
|
||||||
}
|
}
|
||||||
@@ -44,20 +48,20 @@ func (n *NKodeAPI) CreateNewCustomer(nkodePolicy NKodePolicy, id *CustomerId) (*
|
|||||||
return &newCustomer.Id, nil
|
return &newCustomer.Id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) GenerateSignupResetInterface(userEmail UserEmail, customerId CustomerId, kp KeypadDimension, reset bool) (*GenerateSignupResetInterfaceResp, error) {
|
func (n *NKodeAPI) GenerateSignupResetInterface(userEmail models.UserEmail, customerId models.CustomerId, kp models.KeypadDimension, reset bool) (*models.GenerateSignupResetInterfaceResp, error) {
|
||||||
user, err := n.Db.GetUser(userEmail, customerId)
|
user, err := n.Db.GetUser(userEmail, customerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if user != nil && !reset {
|
if user != nil && !reset {
|
||||||
log.Printf("user %s already exists", string(userEmail))
|
log.Printf("user %s already exists", string(userEmail))
|
||||||
return nil, ErrUserAlreadyExists
|
return nil, config.ErrUserAlreadyExists
|
||||||
}
|
}
|
||||||
svgIdxInterface, err := n.Db.RandomSvgIdxInterface(kp)
|
svgIdxInterface, err := n.Db.RandomSvgIdxInterface(kp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
signupSession, err := NewSignupResetSession(userEmail, kp, customerId, svgIdxInterface, reset)
|
signupSession, err := models.NewSignupResetSession(userEmail, kp, customerId, svgIdxInterface, reset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -70,7 +74,7 @@ func (n *NKodeAPI) GenerateSignupResetInterface(userEmail UserEmail, customerId
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp := GenerateSignupResetInterfaceResp{
|
resp := models.GenerateSignupResetInterfaceResp{
|
||||||
UserIdxInterface: signupSession.SetIdxInterface,
|
UserIdxInterface: signupSession.SetIdxInterface,
|
||||||
SvgInterface: svgInterface,
|
SvgInterface: svgInterface,
|
||||||
SessionId: uuid.UUID(signupSession.Id).String(),
|
SessionId: uuid.UUID(signupSession.Id).String(),
|
||||||
@@ -79,7 +83,7 @@ func (n *NKodeAPI) GenerateSignupResetInterface(userEmail UserEmail, customerId
|
|||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) SetNKode(customerId CustomerId, sessionId SessionId, keySelection KeySelection) (IdxInterface, error) {
|
func (n *NKodeAPI) SetNKode(customerId models.CustomerId, sessionId models.SessionId, keySelection models.KeySelection) (models.IdxInterface, error) {
|
||||||
_, err := n.Db.GetCustomer(customerId)
|
_, err := n.Db.GetCustomer(customerId)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -88,12 +92,12 @@ func (n *NKodeAPI) SetNKode(customerId CustomerId, sessionId SessionId, keySelec
|
|||||||
session, exists := n.SignupSessionCache.Get(sessionId.String())
|
session, exists := n.SignupSessionCache.Get(sessionId.String())
|
||||||
if !exists {
|
if !exists {
|
||||||
log.Printf("session id does not exist %s", sessionId)
|
log.Printf("session id does not exist %s", sessionId)
|
||||||
return nil, ErrSignupSessionDNE
|
return nil, config.ErrSignupSessionDNE
|
||||||
}
|
}
|
||||||
userSession, ok := session.(UserSignSession)
|
userSession, ok := session.(models.UserSignSession)
|
||||||
if !ok {
|
if !ok {
|
||||||
// handle the case where the type assertion fails
|
// handle the case where the type assertion fails
|
||||||
return nil, ErrSignupSessionDNE
|
return nil, config.ErrSignupSessionDNE
|
||||||
}
|
}
|
||||||
confirmInterface, err := userSession.SetUserNKode(keySelection)
|
confirmInterface, err := userSession.SetUserNKode(keySelection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -103,16 +107,16 @@ func (n *NKodeAPI) SetNKode(customerId CustomerId, sessionId SessionId, keySelec
|
|||||||
return confirmInterface, nil
|
return confirmInterface, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) ConfirmNKode(customerId CustomerId, sessionId SessionId, keySelection KeySelection) error {
|
func (n *NKodeAPI) ConfirmNKode(customerId models.CustomerId, sessionId models.SessionId, keySelection models.KeySelection) error {
|
||||||
session, exists := n.SignupSessionCache.Get(sessionId.String())
|
session, exists := n.SignupSessionCache.Get(sessionId.String())
|
||||||
if !exists {
|
if !exists {
|
||||||
log.Printf("session id does not exist %s", sessionId)
|
log.Printf("session id does not exist %s", sessionId)
|
||||||
return ErrSignupSessionDNE
|
return config.ErrSignupSessionDNE
|
||||||
}
|
}
|
||||||
userSession, ok := session.(UserSignSession)
|
userSession, ok := session.(models.UserSignSession)
|
||||||
if !ok {
|
if !ok {
|
||||||
// handle the case where the type assertion fails
|
// handle the case where the type assertion fails
|
||||||
return ErrSignupSessionDNE
|
return config.ErrSignupSessionDNE
|
||||||
}
|
}
|
||||||
customer, err := n.Db.GetCustomer(customerId)
|
customer, err := n.Db.GetCustomer(customerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -125,7 +129,7 @@ func (n *NKodeAPI) ConfirmNKode(customerId CustomerId, sessionId SessionId, keyS
|
|||||||
if err = customer.IsValidNKode(userSession.Kp, passcode); err != nil {
|
if err = customer.IsValidNKode(userSession.Kp, passcode); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user, err := NewUser(*customer, string(userSession.UserEmail), passcode, userSession.LoginUserInterface, userSession.Kp)
|
user, err := models.NewUser(*customer, string(userSession.UserEmail), passcode, userSession.LoginUserInterface, userSession.Kp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -138,14 +142,14 @@ func (n *NKodeAPI) ConfirmNKode(customerId CustomerId, sessionId SessionId, keyS
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) GetLoginInterface(userEmail UserEmail, customerId CustomerId) (*GetLoginInterfaceResp, error) {
|
func (n *NKodeAPI) GetLoginInterface(userEmail models.UserEmail, customerId models.CustomerId) (*models.GetLoginInterfaceResp, error) {
|
||||||
user, err := n.Db.GetUser(userEmail, customerId)
|
user, err := n.Db.GetUser(userEmail, customerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if user == nil {
|
if user == nil {
|
||||||
log.Printf("user %s for customer %s dne", userEmail, customerId)
|
log.Printf("user %s for customer %s dne", userEmail, customerId)
|
||||||
return nil, ErrUserForCustomerDNE
|
return nil, config.ErrUserForCustomerDNE
|
||||||
}
|
}
|
||||||
err = user.Interface.PartialInterfaceShuffle()
|
err = user.Interface.PartialInterfaceShuffle()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -159,17 +163,17 @@ func (n *NKodeAPI) GetLoginInterface(userEmail UserEmail, customerId CustomerId)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp := GetLoginInterfaceResp{
|
resp := models.GetLoginInterfaceResp{
|
||||||
UserIdxInterface: user.Interface.IdxInterface,
|
UserIdxInterface: user.Interface.IdxInterface,
|
||||||
SvgInterface: svgInterface,
|
SvgInterface: svgInterface,
|
||||||
NumbOfKeys: user.Kp.NumbOfKeys,
|
NumbOfKeys: user.Kp.NumbOfKeys,
|
||||||
AttrsPerKey: user.Kp.AttrsPerKey,
|
AttrsPerKey: user.Kp.AttrsPerKey,
|
||||||
Colors: SetColors,
|
Colors: models.SetColors,
|
||||||
}
|
}
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) Login(customerId CustomerId, userEmail UserEmail, keySelection KeySelection) (*AuthenticationTokens, error) {
|
func (n *NKodeAPI) Login(customerId models.CustomerId, userEmail models.UserEmail, keySelection models.KeySelection) (*security.AuthenticationTokens, error) {
|
||||||
customer, err := n.Db.GetCustomer(customerId)
|
customer, err := n.Db.GetCustomer(customerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -180,9 +184,9 @@ func (n *NKodeAPI) Login(customerId CustomerId, userEmail UserEmail, keySelectio
|
|||||||
}
|
}
|
||||||
if user == nil {
|
if user == nil {
|
||||||
log.Printf("user %s for customer %s dne", userEmail, customerId)
|
log.Printf("user %s for customer %s dne", userEmail, customerId)
|
||||||
return nil, ErrUserForCustomerDNE
|
return nil, config.ErrUserForCustomerDNE
|
||||||
}
|
}
|
||||||
passcode, err := ValidKeyEntry(*user, *customer, keySelection)
|
passcode, err := models.ValidKeyEntry(*user, *customer, keySelection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -193,7 +197,7 @@ func (n *NKodeAPI) Login(customerId CustomerId, userEmail UserEmail, keySelectio
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jwtToken, err := NewAuthenticationTokens(string(user.Email), customerId)
|
jwtToken, err := security.NewAuthenticationTokens(string(user.Email), uuid.UUID(customerId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -204,38 +208,38 @@ func (n *NKodeAPI) Login(customerId CustomerId, userEmail UserEmail, keySelectio
|
|||||||
return &jwtToken, nil
|
return &jwtToken, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) RenewAttributes(customerId CustomerId) error {
|
func (n *NKodeAPI) RenewAttributes(customerId models.CustomerId) error {
|
||||||
return n.Db.Renew(customerId)
|
return n.Db.Renew(customerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) RandomSvgInterface() ([]string, error) {
|
func (n *NKodeAPI) RandomSvgInterface() ([]string, error) {
|
||||||
return n.Db.RandomSvgInterface(KeypadMax)
|
return n.Db.RandomSvgInterface(models.KeypadMax)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) RefreshToken(userEmail UserEmail, customerId CustomerId, refreshToken string) (string, error) {
|
func (n *NKodeAPI) RefreshToken(userEmail models.UserEmail, customerId models.CustomerId, refreshToken string) (string, error) {
|
||||||
user, err := n.Db.GetUser(userEmail, customerId)
|
user, err := n.Db.GetUser(userEmail, customerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if user == nil {
|
if user == nil {
|
||||||
log.Printf("user %s for customer %s dne", userEmail, customerId)
|
log.Printf("user %s for customer %s dne", userEmail, customerId)
|
||||||
return "", ErrUserForCustomerDNE
|
return "", config.ErrUserForCustomerDNE
|
||||||
}
|
}
|
||||||
if user.RefreshToken != refreshToken {
|
if user.RefreshToken != refreshToken {
|
||||||
return "", ErrRefreshTokenInvalid
|
return "", config.ErrRefreshTokenInvalid
|
||||||
}
|
}
|
||||||
refreshClaims, err := ParseRegisteredClaimToken(refreshToken)
|
refreshClaims, err := security.ParseRegisteredClaimToken(refreshToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if err = ClaimExpired(*refreshClaims); err != nil {
|
if err = security.ClaimExpired(*refreshClaims); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
newAccessClaims := NewAccessClaim(string(userEmail), customerId)
|
newAccessClaims := security.NewAccessClaim(string(userEmail), uuid.UUID(customerId))
|
||||||
return EncodeAndSignClaims(newAccessClaims)
|
return security.EncodeAndSignClaims(newAccessClaims)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NKodeAPI) ResetNKode(userEmail UserEmail, customerId CustomerId) error {
|
func (n *NKodeAPI) ResetNKode(userEmail models.UserEmail, customerId models.CustomerId) error {
|
||||||
user, err := n.Db.GetUser(userEmail, customerId)
|
user, err := n.Db.GetUser(userEmail, customerId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error getting user in rest nkode %v", err)
|
return fmt.Errorf("error getting user in rest nkode %v", err)
|
||||||
@@ -245,16 +249,16 @@ func (n *NKodeAPI) ResetNKode(userEmail UserEmail, customerId CustomerId) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
nkodeResetJwt, err := ResetNKodeToken(userEmail, customerId)
|
nkodeResetJwt, err := security.ResetNKodeToken(string(userEmail), uuid.UUID(customerId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
frontendHost := os.Getenv("FRONTEND_HOST")
|
frontendHost := os.Getenv("FRONTEND_HOST")
|
||||||
if frontendHost == "" {
|
if frontendHost == "" {
|
||||||
frontendHost = FrontendHost
|
frontendHost = config.FrontendHost
|
||||||
}
|
}
|
||||||
htmlBody := fmt.Sprintf("<h1>Hello!</h1><p>Click the link to reset your nKode.</p><a href=\"%s?token=%s\">Reset nKode</a>", frontendHost, nkodeResetJwt)
|
htmlBody := fmt.Sprintf("<h1>Hello!</h1><p>Click the link to reset your nKode.</p><a href=\"%s?token=%s\">Reset nKode</a>", frontendHost, nkodeResetJwt)
|
||||||
email := Email{
|
email := email.Email{
|
||||||
Sender: "no-reply@nkode.tech",
|
Sender: "no-reply@nkode.tech",
|
||||||
Recipient: string(userEmail),
|
Recipient: string(userEmail),
|
||||||
Subject: "nKode Reset",
|
Subject: "nKode Reset",
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
package core
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"go-nkode/util"
|
"go-nkode/internal/db"
|
||||||
|
"go-nkode/internal/email"
|
||||||
|
"go-nkode/internal/models"
|
||||||
|
"go-nkode/internal/security"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -13,7 +16,7 @@ func TestNKodeAPI(t *testing.T) {
|
|||||||
|
|
||||||
dbFile := os.Getenv("TEST_DB")
|
dbFile := os.Getenv("TEST_DB")
|
||||||
|
|
||||||
db2 := NewSqliteDB(dbFile)
|
db2 := db.NewSqliteDB(dbFile)
|
||||||
defer db2.CloseDb()
|
defer db2.CloseDb()
|
||||||
testNKodeAPI(t, db2)
|
testNKodeAPI(t, db2)
|
||||||
|
|
||||||
@@ -28,17 +31,17 @@ func TestNKodeAPI(t *testing.T) {
|
|||||||
func testNKodeAPI(t *testing.T, db DbAccessor) {
|
func testNKodeAPI(t *testing.T, db DbAccessor) {
|
||||||
bufferSize := 100
|
bufferSize := 100
|
||||||
emailsPerSec := 14
|
emailsPerSec := 14
|
||||||
testClient := TestEmailClient{}
|
testClient := email.TestEmailClient{}
|
||||||
queue := NewEmailQueue(bufferSize, emailsPerSec, &testClient)
|
queue := email.NewEmailQueue(bufferSize, emailsPerSec, &testClient)
|
||||||
queue.Start()
|
queue.Start()
|
||||||
defer queue.Stop()
|
defer queue.Stop()
|
||||||
attrsPerKey := 5
|
attrsPerKey := 5
|
||||||
numbOfKeys := 4
|
numbOfKeys := 4
|
||||||
for idx := 0; idx < 1; idx++ {
|
for idx := 0; idx < 1; idx++ {
|
||||||
userEmail := UserEmail("test_username" + util.GenerateRandomString(12) + "@example.com")
|
userEmail := models.UserEmail("test_username" + security.GenerateRandomString(12) + "@example.com")
|
||||||
passcodeLen := 4
|
passcodeLen := 4
|
||||||
nkodePolicy := NewDefaultNKodePolicy()
|
nkodePolicy := models.NewDefaultNKodePolicy()
|
||||||
keypadSize := KeypadDimension{AttrsPerKey: attrsPerKey, NumbOfKeys: numbOfKeys}
|
keypadSize := models.KeypadDimension{AttrsPerKey: attrsPerKey, NumbOfKeys: numbOfKeys}
|
||||||
nkodeApi := NewNKodeAPI(db, queue)
|
nkodeApi := NewNKodeAPI(db, queue)
|
||||||
customerId, err := nkodeApi.CreateNewCustomer(nkodePolicy, nil)
|
customerId, err := nkodeApi.CreateNewCustomer(nkodePolicy, nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@@ -46,22 +49,22 @@ func testNKodeAPI(t *testing.T, db DbAccessor) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
setInterface := signupResponse.UserIdxInterface
|
setInterface := signupResponse.UserIdxInterface
|
||||||
sessionIdStr := signupResponse.SessionId
|
sessionIdStr := signupResponse.SessionId
|
||||||
sessionId, err := SessionIdFromString(sessionIdStr)
|
sessionId, err := models.SessionIdFromString(sessionIdStr)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
keypadSize = KeypadDimension{AttrsPerKey: numbOfKeys, NumbOfKeys: numbOfKeys}
|
keypadSize = models.KeypadDimension{AttrsPerKey: numbOfKeys, NumbOfKeys: numbOfKeys}
|
||||||
userPasscode := setInterface[:passcodeLen]
|
userPasscode := setInterface[:passcodeLen]
|
||||||
setKeySelect, err := SelectKeyByAttrIdx(setInterface, userPasscode, keypadSize)
|
setKeySelect, err := models.SelectKeyByAttrIdx(setInterface, userPasscode, keypadSize)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
confirmInterface, err := nkodeApi.SetNKode(*customerId, sessionId, setKeySelect)
|
confirmInterface, err := nkodeApi.SetNKode(*customerId, sessionId, setKeySelect)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
confirmKeySelect, err := SelectKeyByAttrIdx(confirmInterface, userPasscode, keypadSize)
|
confirmKeySelect, err := models.SelectKeyByAttrIdx(confirmInterface, userPasscode, keypadSize)
|
||||||
err = nkodeApi.ConfirmNKode(*customerId, sessionId, confirmKeySelect)
|
err = nkodeApi.ConfirmNKode(*customerId, sessionId, confirmKeySelect)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
keypadSize = KeypadDimension{AttrsPerKey: attrsPerKey, NumbOfKeys: numbOfKeys}
|
keypadSize = models.KeypadDimension{AttrsPerKey: attrsPerKey, NumbOfKeys: numbOfKeys}
|
||||||
loginInterface, err := nkodeApi.GetLoginInterface(userEmail, *customerId)
|
loginInterface, err := nkodeApi.GetLoginInterface(userEmail, *customerId)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
loginKeySelection, err := SelectKeyByAttrIdx(loginInterface.UserIdxInterface, userPasscode, keypadSize)
|
loginKeySelection, err := models.SelectKeyByAttrIdx(loginInterface.UserIdxInterface, userPasscode, keypadSize)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
_, err = nkodeApi.Login(*customerId, userEmail, loginKeySelection)
|
_, err = nkodeApi.Login(*customerId, userEmail, loginKeySelection)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@@ -71,34 +74,34 @@ func testNKodeAPI(t *testing.T, db DbAccessor) {
|
|||||||
|
|
||||||
loginInterface, err = nkodeApi.GetLoginInterface(userEmail, *customerId)
|
loginInterface, err = nkodeApi.GetLoginInterface(userEmail, *customerId)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
loginKeySelection, err = SelectKeyByAttrIdx(loginInterface.UserIdxInterface, userPasscode, keypadSize)
|
loginKeySelection, err = models.SelectKeyByAttrIdx(loginInterface.UserIdxInterface, userPasscode, keypadSize)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
_, err = nkodeApi.Login(*customerId, userEmail, loginKeySelection)
|
_, err = nkodeApi.Login(*customerId, userEmail, loginKeySelection)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
/// Reset nKode
|
/// Reset nKode
|
||||||
attrsPerKey = 6
|
attrsPerKey = 6
|
||||||
keypadSize = KeypadDimension{AttrsPerKey: attrsPerKey, NumbOfKeys: numbOfKeys}
|
keypadSize = models.KeypadDimension{AttrsPerKey: attrsPerKey, NumbOfKeys: numbOfKeys}
|
||||||
resetResponse, err := nkodeApi.GenerateSignupResetInterface(userEmail, *customerId, keypadSize, true)
|
resetResponse, err := nkodeApi.GenerateSignupResetInterface(userEmail, *customerId, keypadSize, true)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
setInterface = resetResponse.UserIdxInterface
|
setInterface = resetResponse.UserIdxInterface
|
||||||
sessionIdStr = resetResponse.SessionId
|
sessionIdStr = resetResponse.SessionId
|
||||||
sessionId, err = SessionIdFromString(sessionIdStr)
|
sessionId, err = models.SessionIdFromString(sessionIdStr)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
keypadSize = KeypadDimension{AttrsPerKey: numbOfKeys, NumbOfKeys: numbOfKeys}
|
keypadSize = models.KeypadDimension{AttrsPerKey: numbOfKeys, NumbOfKeys: numbOfKeys}
|
||||||
userPasscode = setInterface[:passcodeLen]
|
userPasscode = setInterface[:passcodeLen]
|
||||||
setKeySelect, err = SelectKeyByAttrIdx(setInterface, userPasscode, keypadSize)
|
setKeySelect, err = models.SelectKeyByAttrIdx(setInterface, userPasscode, keypadSize)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
confirmInterface, err = nkodeApi.SetNKode(*customerId, sessionId, setKeySelect)
|
confirmInterface, err = nkodeApi.SetNKode(*customerId, sessionId, setKeySelect)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
confirmKeySelect, err = SelectKeyByAttrIdx(confirmInterface, userPasscode, keypadSize)
|
confirmKeySelect, err = models.SelectKeyByAttrIdx(confirmInterface, userPasscode, keypadSize)
|
||||||
err = nkodeApi.ConfirmNKode(*customerId, sessionId, confirmKeySelect)
|
err = nkodeApi.ConfirmNKode(*customerId, sessionId, confirmKeySelect)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
keypadSize = KeypadDimension{AttrsPerKey: attrsPerKey, NumbOfKeys: numbOfKeys}
|
keypadSize = models.KeypadDimension{AttrsPerKey: attrsPerKey, NumbOfKeys: numbOfKeys}
|
||||||
loginInterface2, err := nkodeApi.GetLoginInterface(userEmail, *customerId)
|
loginInterface2, err := nkodeApi.GetLoginInterface(userEmail, *customerId)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
loginKeySelection, err = SelectKeyByAttrIdx(loginInterface2.UserIdxInterface, userPasscode, keypadSize)
|
loginKeySelection, err = models.SelectKeyByAttrIdx(loginInterface2.UserIdxInterface, userPasscode, keypadSize)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
_, err = nkodeApi.Login(*customerId, userEmail, loginKeySelection)
|
_, err = nkodeApi.Login(*customerId, userEmail, loginKeySelection)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@@ -1,25 +1,26 @@
|
|||||||
package core
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go-nkode/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InMemoryDb struct {
|
type InMemoryDb struct {
|
||||||
Customers map[CustomerId]Customer
|
Customers map[models.CustomerId]models.Customer
|
||||||
Users map[UserId]User
|
Users map[models.UserId]models.User
|
||||||
userIdMap map[string]UserId
|
userIdMap map[string]models.UserId
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInMemoryDb() InMemoryDb {
|
func NewInMemoryDb() InMemoryDb {
|
||||||
return InMemoryDb{
|
return InMemoryDb{
|
||||||
Customers: make(map[CustomerId]Customer),
|
Customers: make(map[models.CustomerId]models.Customer),
|
||||||
Users: make(map[UserId]User),
|
Users: make(map[models.UserId]models.User),
|
||||||
userIdMap: make(map[string]UserId),
|
userIdMap: make(map[string]models.UserId),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *InMemoryDb) GetCustomer(id CustomerId) (*Customer, error) {
|
func (db *InMemoryDb) GetCustomer(id models.CustomerId) (*models.Customer, error) {
|
||||||
customer, exists := db.Customers[id]
|
customer, exists := db.Customers[id]
|
||||||
if !exists {
|
if !exists {
|
||||||
return nil, errors.New(fmt.Sprintf("customer %s dne", customer.Id))
|
return nil, errors.New(fmt.Sprintf("customer %s dne", customer.Id))
|
||||||
@@ -27,7 +28,7 @@ func (db *InMemoryDb) GetCustomer(id CustomerId) (*Customer, error) {
|
|||||||
return &customer, nil
|
return &customer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *InMemoryDb) GetUser(username UserEmail, customerId CustomerId) (*User, error) {
|
func (db *InMemoryDb) GetUser(username models.UserEmail, customerId models.CustomerId) (*models.User, error) {
|
||||||
key := userIdKey(customerId, username)
|
key := userIdKey(customerId, username)
|
||||||
userId, exists := db.userIdMap[key]
|
userId, exists := db.userIdMap[key]
|
||||||
if !exists {
|
if !exists {
|
||||||
@@ -40,7 +41,7 @@ func (db *InMemoryDb) GetUser(username UserEmail, customerId CustomerId) (*User,
|
|||||||
return &user, nil
|
return &user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *InMemoryDb) WriteNewCustomer(customer Customer) error {
|
func (db *InMemoryDb) WriteNewCustomer(customer models.Customer) error {
|
||||||
_, exists := db.Customers[customer.Id]
|
_, exists := db.Customers[customer.Id]
|
||||||
|
|
||||||
if exists {
|
if exists {
|
||||||
@@ -50,7 +51,7 @@ func (db *InMemoryDb) WriteNewCustomer(customer Customer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *InMemoryDb) WriteNewUser(user User) error {
|
func (db *InMemoryDb) WriteNewUser(user models.User) error {
|
||||||
_, exists := db.Customers[user.CustomerId]
|
_, exists := db.Customers[user.CustomerId]
|
||||||
if !exists {
|
if !exists {
|
||||||
return errors.New(fmt.Sprintf("can't add user %s to customer %s: customer dne", user.Email, user.CustomerId))
|
return errors.New(fmt.Sprintf("can't add user %s to customer %s: customer dne", user.Email, user.CustomerId))
|
||||||
@@ -66,11 +67,11 @@ func (db *InMemoryDb) WriteNewUser(user User) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *InMemoryDb) UpdateUserNKode(user User) error {
|
func (db *InMemoryDb) UpdateUserNKode(user models.User) error {
|
||||||
return errors.ErrUnsupported
|
return errors.ErrUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *InMemoryDb) UpdateUserInterface(userId UserId, ui UserInterface) error {
|
func (db *InMemoryDb) UpdateUserInterface(userId models.UserId, ui models.UserInterface) error {
|
||||||
user, exists := db.Users[userId]
|
user, exists := db.Users[userId]
|
||||||
if !exists {
|
if !exists {
|
||||||
return errors.New(fmt.Sprintf("can't update user %s, dne", user.Id))
|
return errors.New(fmt.Sprintf("can't update user %s, dne", user.Id))
|
||||||
@@ -80,11 +81,11 @@ func (db *InMemoryDb) UpdateUserInterface(userId UserId, ui UserInterface) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *InMemoryDb) UpdateUserRefreshToken(userId UserId, refreshToken string) error {
|
func (db *InMemoryDb) UpdateUserRefreshToken(userId models.UserId, refreshToken string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *InMemoryDb) Renew(id CustomerId) error {
|
func (db *InMemoryDb) Renew(id models.CustomerId) error {
|
||||||
customer, exists := db.Customers[id]
|
customer, exists := db.Customers[id]
|
||||||
if !exists {
|
if !exists {
|
||||||
return errors.New(fmt.Sprintf("customer %s does not exist", id))
|
return errors.New(fmt.Sprintf("customer %s does not exist", id))
|
||||||
@@ -106,7 +107,7 @@ func (db *InMemoryDb) Renew(id CustomerId) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *InMemoryDb) RefreshUserPasscode(user User, passocode []int, customerAttr CustomerAttributes) error {
|
func (db *InMemoryDb) RefreshUserPasscode(user models.User, passocode []int, customerAttr models.CustomerAttributes) error {
|
||||||
err := user.RefreshPasscode(passocode, customerAttr)
|
err := user.RefreshPasscode(passocode, customerAttr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -115,23 +116,23 @@ func (db *InMemoryDb) RefreshUserPasscode(user User, passocode []int, customerAt
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *InMemoryDb) RandomSvgInterface(kp KeypadDimension) ([]string, error) {
|
func (db *InMemoryDb) RandomSvgInterface(kp models.KeypadDimension) ([]string, error) {
|
||||||
return make([]string, kp.TotalAttrs()), nil
|
return make([]string, kp.TotalAttrs()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *InMemoryDb) RandomSvgIdxInterface(kp KeypadDimension) (SvgIdInterface, error) {
|
func (db *InMemoryDb) RandomSvgIdxInterface(kp models.KeypadDimension) (models.SvgIdInterface, error) {
|
||||||
svgs := make(SvgIdInterface, kp.TotalAttrs())
|
svgs := make(models.SvgIdInterface, kp.TotalAttrs())
|
||||||
for idx := range svgs {
|
for idx := range svgs {
|
||||||
svgs[idx] = idx
|
svgs[idx] = idx
|
||||||
}
|
}
|
||||||
return svgs, nil
|
return svgs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *InMemoryDb) GetSvgStringInterface(idxs SvgIdInterface) ([]string, error) {
|
func (db *InMemoryDb) GetSvgStringInterface(idxs models.SvgIdInterface) ([]string, error) {
|
||||||
return make([]string, len(idxs)), nil
|
return make([]string, len(idxs)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func userIdKey(customerId CustomerId, username UserEmail) string {
|
func userIdKey(customerId models.CustomerId, username models.UserEmail) string {
|
||||||
key := fmt.Sprintf("%s:%s", customerId, username)
|
key := fmt.Sprintf("%s:%s", customerId, username)
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
package core
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
_ "github.com/mattn/go-sqlite3" // Import the SQLite3 driver
|
_ "github.com/mattn/go-sqlite3" // Import the SQLite3 driver
|
||||||
"go-nkode/util"
|
"go-nkode/config"
|
||||||
|
"go-nkode/internal/models"
|
||||||
|
"go-nkode/internal/security"
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -58,7 +60,7 @@ func (d *SqliteDB) CloseDb() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteDB) WriteNewCustomer(c Customer) error {
|
func (d *SqliteDB) WriteNewCustomer(c models.Customer) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO customer (
|
INSERT INTO customer (
|
||||||
id
|
id
|
||||||
@@ -83,7 +85,7 @@ VALUES (?,?,?,?,?,?,?,?,?,?,?)
|
|||||||
return d.addWriteTx(query, args)
|
return d.addWriteTx(query, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteDB) WriteNewUser(u User) error {
|
func (d *SqliteDB) WriteNewUser(u models.User) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO user (
|
INSERT INTO user (
|
||||||
id
|
id
|
||||||
@@ -117,16 +119,16 @@ VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
|||||||
args := []any{
|
args := []any{
|
||||||
uuid.UUID(u.Id), u.Email, renew, u.RefreshToken, uuid.UUID(u.CustomerId),
|
uuid.UUID(u.Id), u.Email, renew, u.RefreshToken, uuid.UUID(u.CustomerId),
|
||||||
u.EncipheredPasscode.Code, u.EncipheredPasscode.Mask, u.Kp.AttrsPerKey, u.Kp.NumbOfKeys,
|
u.EncipheredPasscode.Code, u.EncipheredPasscode.Mask, u.Kp.AttrsPerKey, u.Kp.NumbOfKeys,
|
||||||
util.Uint64ArrToByteArr(u.CipherKeys.AlphaKey), util.Uint64ArrToByteArr(u.CipherKeys.SetKey),
|
security.Uint64ArrToByteArr(u.CipherKeys.AlphaKey), security.Uint64ArrToByteArr(u.CipherKeys.SetKey),
|
||||||
util.Uint64ArrToByteArr(u.CipherKeys.PassKey), util.Uint64ArrToByteArr(u.CipherKeys.MaskKey),
|
security.Uint64ArrToByteArr(u.CipherKeys.PassKey), security.Uint64ArrToByteArr(u.CipherKeys.MaskKey),
|
||||||
u.CipherKeys.Salt, u.CipherKeys.MaxNKodeLen, util.IntArrToByteArr(u.Interface.IdxInterface),
|
u.CipherKeys.Salt, u.CipherKeys.MaxNKodeLen, security.IntArrToByteArr(u.Interface.IdxInterface),
|
||||||
util.IntArrToByteArr(u.Interface.SvgId), timeStamp(),
|
security.IntArrToByteArr(u.Interface.SvgId), timeStamp(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return d.addWriteTx(query, args)
|
return d.addWriteTx(query, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteDB) UpdateUserNKode(u User) error {
|
func (d *SqliteDB) UpdateUserNKode(u models.User) error {
|
||||||
query := `
|
query := `
|
||||||
UPDATE user
|
UPDATE user
|
||||||
SET renew = ?
|
SET renew = ?
|
||||||
@@ -151,21 +153,21 @@ WHERE email = ? AND customer_id = ?
|
|||||||
} else {
|
} else {
|
||||||
renew = 0
|
renew = 0
|
||||||
}
|
}
|
||||||
args := []any{renew, u.RefreshToken, u.EncipheredPasscode.Code, u.EncipheredPasscode.Mask, u.Kp.AttrsPerKey, u.Kp.NumbOfKeys, util.Uint64ArrToByteArr(u.CipherKeys.AlphaKey), util.Uint64ArrToByteArr(u.CipherKeys.SetKey), util.Uint64ArrToByteArr(u.CipherKeys.PassKey), util.Uint64ArrToByteArr(u.CipherKeys.MaskKey), u.CipherKeys.Salt, u.CipherKeys.MaxNKodeLen, util.IntArrToByteArr(u.Interface.IdxInterface), util.IntArrToByteArr(u.Interface.SvgId), string(u.Email), uuid.UUID(u.CustomerId)}
|
args := []any{renew, u.RefreshToken, u.EncipheredPasscode.Code, u.EncipheredPasscode.Mask, u.Kp.AttrsPerKey, u.Kp.NumbOfKeys, security.Uint64ArrToByteArr(u.CipherKeys.AlphaKey), security.Uint64ArrToByteArr(u.CipherKeys.SetKey), security.Uint64ArrToByteArr(u.CipherKeys.PassKey), security.Uint64ArrToByteArr(u.CipherKeys.MaskKey), u.CipherKeys.Salt, u.CipherKeys.MaxNKodeLen, security.IntArrToByteArr(u.Interface.IdxInterface), security.IntArrToByteArr(u.Interface.SvgId), string(u.Email), uuid.UUID(u.CustomerId)}
|
||||||
|
|
||||||
return d.addWriteTx(query, args)
|
return d.addWriteTx(query, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteDB) UpdateUserInterface(id UserId, ui UserInterface) error {
|
func (d *SqliteDB) UpdateUserInterface(id models.UserId, ui models.UserInterface) error {
|
||||||
query := `
|
query := `
|
||||||
UPDATE user SET idx_interface = ?, last_login = ? WHERE id = ?
|
UPDATE user SET idx_interface = ?, last_login = ? WHERE id = ?
|
||||||
`
|
`
|
||||||
args := []any{util.IntArrToByteArr(ui.IdxInterface), timeStamp(), uuid.UUID(id).String()}
|
args := []any{security.IntArrToByteArr(ui.IdxInterface), timeStamp(), uuid.UUID(id).String()}
|
||||||
|
|
||||||
return d.addWriteTx(query, args)
|
return d.addWriteTx(query, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteDB) UpdateUserRefreshToken(id UserId, refreshToken string) error {
|
func (d *SqliteDB) UpdateUserRefreshToken(id models.UserId, refreshToken string) error {
|
||||||
query := `
|
query := `
|
||||||
UPDATE user SET refresh_token = ? WHERE id = ?
|
UPDATE user SET refresh_token = ? WHERE id = ?
|
||||||
`
|
`
|
||||||
@@ -174,7 +176,7 @@ UPDATE user SET refresh_token = ? WHERE id = ?
|
|||||||
return d.addWriteTx(query, args)
|
return d.addWriteTx(query, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteDB) Renew(id CustomerId) error {
|
func (d *SqliteDB) Renew(id models.CustomerId) error {
|
||||||
// TODO: How long does a renew take?
|
// TODO: How long does a renew take?
|
||||||
customer, err := d.GetCustomer(id)
|
customer, err := d.GetCustomer(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -184,7 +186,7 @@ func (d *SqliteDB) Renew(id CustomerId) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
renewArgs := []any{util.Uint64ArrToByteArr(customer.Attributes.AttrVals), util.Uint64ArrToByteArr(customer.Attributes.SetVals), uuid.UUID(customer.Id).String()}
|
renewArgs := []any{security.Uint64ArrToByteArr(customer.Attributes.AttrVals), security.Uint64ArrToByteArr(customer.Attributes.SetVals), uuid.UUID(customer.Id).String()}
|
||||||
// TODO: replace with tx
|
// TODO: replace with tx
|
||||||
renewQuery := `
|
renewQuery := `
|
||||||
UPDATE customer
|
UPDATE customer
|
||||||
@@ -217,20 +219,20 @@ WHERE customer_id = ?
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user := User{
|
user := models.User{
|
||||||
Id: UserId{},
|
Id: models.UserId{},
|
||||||
CustomerId: CustomerId{},
|
CustomerId: models.CustomerId{},
|
||||||
Email: "",
|
Email: "",
|
||||||
EncipheredPasscode: EncipheredNKode{},
|
EncipheredPasscode: models.EncipheredNKode{},
|
||||||
Kp: KeypadDimension{
|
Kp: models.KeypadDimension{
|
||||||
AttrsPerKey: attrsPerKey,
|
AttrsPerKey: attrsPerKey,
|
||||||
NumbOfKeys: numbOfKeys,
|
NumbOfKeys: numbOfKeys,
|
||||||
},
|
},
|
||||||
CipherKeys: UserCipherKeys{
|
CipherKeys: models.UserCipherKeys{
|
||||||
AlphaKey: util.ByteArrToUint64Arr(alphaBytes),
|
AlphaKey: security.ByteArrToUint64Arr(alphaBytes),
|
||||||
SetKey: util.ByteArrToUint64Arr(setBytes),
|
SetKey: security.ByteArrToUint64Arr(setBytes),
|
||||||
},
|
},
|
||||||
Interface: UserInterface{},
|
Interface: models.UserInterface{},
|
||||||
Renew: false,
|
Renew: false,
|
||||||
}
|
}
|
||||||
err = user.RenewKeys(setXor, attrXor)
|
err = user.RenewKeys(setXor, attrXor)
|
||||||
@@ -242,7 +244,7 @@ UPDATE user
|
|||||||
SET alpha_key = ?, set_key = ?, renew = ?
|
SET alpha_key = ?, set_key = ?, renew = ?
|
||||||
WHERE id = ?;
|
WHERE id = ?;
|
||||||
`
|
`
|
||||||
renewArgs = append(renewArgs, util.Uint64ArrToByteArr(user.CipherKeys.AlphaKey), util.Uint64ArrToByteArr(user.CipherKeys.SetKey), 1, userId)
|
renewArgs = append(renewArgs, security.Uint64ArrToByteArr(user.CipherKeys.AlphaKey), security.Uint64ArrToByteArr(user.CipherKeys.SetKey), 1, userId)
|
||||||
}
|
}
|
||||||
renewQuery += `
|
renewQuery += `
|
||||||
`
|
`
|
||||||
@@ -253,7 +255,7 @@ WHERE id = ?;
|
|||||||
return d.addWriteTx(renewQuery, renewArgs)
|
return d.addWriteTx(renewQuery, renewArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteDB) RefreshUserPasscode(user User, passcodeIdx []int, customerAttr CustomerAttributes) error {
|
func (d *SqliteDB) RefreshUserPasscode(user models.User, passcodeIdx []int, customerAttr models.CustomerAttributes) error {
|
||||||
err := user.RefreshPasscode(passcodeIdx, customerAttr)
|
err := user.RefreshPasscode(passcodeIdx, customerAttr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -271,10 +273,10 @@ SET
|
|||||||
,salt = ?
|
,salt = ?
|
||||||
WHERE id = ?;
|
WHERE id = ?;
|
||||||
`
|
`
|
||||||
args := []any{user.RefreshToken, 0, user.EncipheredPasscode.Code, user.EncipheredPasscode.Mask, util.Uint64ArrToByteArr(user.CipherKeys.AlphaKey), util.Uint64ArrToByteArr(user.CipherKeys.SetKey), util.Uint64ArrToByteArr(user.CipherKeys.PassKey), util.Uint64ArrToByteArr(user.CipherKeys.MaskKey), user.CipherKeys.Salt, uuid.UUID(user.Id).String()}
|
args := []any{user.RefreshToken, 0, user.EncipheredPasscode.Code, user.EncipheredPasscode.Mask, security.Uint64ArrToByteArr(user.CipherKeys.AlphaKey), security.Uint64ArrToByteArr(user.CipherKeys.SetKey), security.Uint64ArrToByteArr(user.CipherKeys.PassKey), security.Uint64ArrToByteArr(user.CipherKeys.MaskKey), user.CipherKeys.Salt, uuid.UUID(user.Id).String()}
|
||||||
return d.addWriteTx(query, args)
|
return d.addWriteTx(query, args)
|
||||||
}
|
}
|
||||||
func (d *SqliteDB) GetCustomer(id CustomerId) (*Customer, error) {
|
func (d *SqliteDB) GetCustomer(id models.CustomerId) (*models.Customer, error) {
|
||||||
tx, err := d.db.Begin()
|
tx, err := d.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -307,7 +309,7 @@ WHERE id = ?
|
|||||||
|
|
||||||
if !rows.Next() {
|
if !rows.Next() {
|
||||||
log.Printf("no new row for customer %s with err %s", id, rows.Err())
|
log.Printf("no new row for customer %s with err %s", id, rows.Err())
|
||||||
return nil, ErrCustomerDne
|
return nil, config.ErrCustomerDne
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxNKodeLen int
|
var maxNKodeLen int
|
||||||
@@ -322,9 +324,9 @@ WHERE id = ?
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
customer := Customer{
|
customer := models.Customer{
|
||||||
Id: id,
|
Id: id,
|
||||||
NKodePolicy: NKodePolicy{
|
NKodePolicy: models.NKodePolicy{
|
||||||
MaxNkodeLen: maxNKodeLen,
|
MaxNkodeLen: maxNKodeLen,
|
||||||
MinNkodeLen: minNKodeLen,
|
MinNkodeLen: minNKodeLen,
|
||||||
DistinctSets: distinctSets,
|
DistinctSets: distinctSets,
|
||||||
@@ -332,7 +334,7 @@ WHERE id = ?
|
|||||||
LockOut: lockOut,
|
LockOut: lockOut,
|
||||||
Expiration: expiration,
|
Expiration: expiration,
|
||||||
},
|
},
|
||||||
Attributes: NewCustomerAttributesFromBytes(attributeValues, setValues),
|
Attributes: models.NewCustomerAttributesFromBytes(attributeValues, setValues),
|
||||||
}
|
}
|
||||||
if err = tx.Commit(); err != nil {
|
if err = tx.Commit(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -340,7 +342,7 @@ WHERE id = ?
|
|||||||
return &customer, nil
|
return &customer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteDB) GetUser(email UserEmail, customerId CustomerId) (*User, error) {
|
func (d *SqliteDB) GetUser(email models.UserEmail, customerId models.CustomerId) (*models.User, error) {
|
||||||
tx, err := d.db.Begin()
|
tx, err := d.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -399,30 +401,30 @@ WHERE user.email = ? AND user.customer_id = ?
|
|||||||
renew = true
|
renew = true
|
||||||
}
|
}
|
||||||
|
|
||||||
user := User{
|
user := models.User{
|
||||||
Id: UserId(userId),
|
Id: models.UserId(userId),
|
||||||
CustomerId: customerId,
|
CustomerId: customerId,
|
||||||
Email: email,
|
Email: email,
|
||||||
EncipheredPasscode: EncipheredNKode{
|
EncipheredPasscode: models.EncipheredNKode{
|
||||||
Code: code,
|
Code: code,
|
||||||
Mask: mask,
|
Mask: mask,
|
||||||
},
|
},
|
||||||
Kp: KeypadDimension{
|
Kp: models.KeypadDimension{
|
||||||
AttrsPerKey: attrsPerKey,
|
AttrsPerKey: attrsPerKey,
|
||||||
NumbOfKeys: numbOfKeys,
|
NumbOfKeys: numbOfKeys,
|
||||||
},
|
},
|
||||||
CipherKeys: UserCipherKeys{
|
CipherKeys: models.UserCipherKeys{
|
||||||
AlphaKey: util.ByteArrToUint64Arr(alphaKey),
|
AlphaKey: security.ByteArrToUint64Arr(alphaKey),
|
||||||
SetKey: util.ByteArrToUint64Arr(setKey),
|
SetKey: security.ByteArrToUint64Arr(setKey),
|
||||||
PassKey: util.ByteArrToUint64Arr(passKey),
|
PassKey: security.ByteArrToUint64Arr(passKey),
|
||||||
MaskKey: util.ByteArrToUint64Arr(maskKey),
|
MaskKey: security.ByteArrToUint64Arr(maskKey),
|
||||||
Salt: salt,
|
Salt: salt,
|
||||||
MaxNKodeLen: maxNKodeLen,
|
MaxNKodeLen: maxNKodeLen,
|
||||||
Kp: nil,
|
Kp: nil,
|
||||||
},
|
},
|
||||||
Interface: UserInterface{
|
Interface: models.UserInterface{
|
||||||
IdxInterface: util.ByteArrToIntArr(idxInterface),
|
IdxInterface: security.ByteArrToIntArr(idxInterface),
|
||||||
SvgId: util.ByteArrToIntArr(svgIdInterface),
|
SvgId: security.ByteArrToIntArr(svgIdInterface),
|
||||||
Kp: nil,
|
Kp: nil,
|
||||||
},
|
},
|
||||||
Renew: renew,
|
Renew: renew,
|
||||||
@@ -436,7 +438,7 @@ WHERE user.email = ? AND user.customer_id = ?
|
|||||||
return &user, nil
|
return &user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteDB) RandomSvgInterface(kp KeypadDimension) ([]string, error) {
|
func (d *SqliteDB) RandomSvgInterface(kp models.KeypadDimension) ([]string, error) {
|
||||||
ids, err := d.getRandomIds(kp.TotalAttrs())
|
ids, err := d.getRandomIds(kp.TotalAttrs())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -444,11 +446,11 @@ func (d *SqliteDB) RandomSvgInterface(kp KeypadDimension) ([]string, error) {
|
|||||||
return d.getSvgsById(ids)
|
return d.getSvgsById(ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteDB) RandomSvgIdxInterface(kp KeypadDimension) (SvgIdInterface, error) {
|
func (d *SqliteDB) RandomSvgIdxInterface(kp models.KeypadDimension) (models.SvgIdInterface, error) {
|
||||||
return d.getRandomIds(kp.TotalAttrs())
|
return d.getRandomIds(kp.TotalAttrs())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteDB) GetSvgStringInterface(idxs SvgIdInterface) ([]string, error) {
|
func (d *SqliteDB) GetSvgStringInterface(idxs models.SvgIdInterface) ([]string, error) {
|
||||||
return d.getSvgsById(idxs)
|
return d.getSvgsById(idxs)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,7 +472,7 @@ WHERE id = ?
|
|||||||
}
|
}
|
||||||
if !rows.Next() {
|
if !rows.Next() {
|
||||||
log.Printf("id not found: %d", id)
|
log.Printf("id not found: %d", id)
|
||||||
return nil, ErrSvgDne
|
return nil, config.ErrSvgDne
|
||||||
}
|
}
|
||||||
if err = rows.Scan(&svgs[idx]); err != nil {
|
if err = rows.Scan(&svgs[idx]); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -506,7 +508,7 @@ func (d *SqliteDB) writeToDb(query string, args []any) error {
|
|||||||
|
|
||||||
func (d *SqliteDB) addWriteTx(query string, args []any) error {
|
func (d *SqliteDB) addWriteTx(query string, args []any) error {
|
||||||
if d.stop {
|
if d.stop {
|
||||||
return ErrStoppingDatabase
|
return config.ErrStoppingDatabase
|
||||||
}
|
}
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
writeTx := WriteTx{
|
writeTx := WriteTx{
|
||||||
@@ -523,23 +525,23 @@ func (d *SqliteDB) getRandomIds(count int) ([]int, error) {
|
|||||||
tx, err := d.db.Begin()
|
tx, err := d.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
return nil, ErrSqliteTx
|
return nil, config.ErrSqliteTx
|
||||||
}
|
}
|
||||||
rows, err := tx.Query("SELECT COUNT(*) as count FROM svg_icon;")
|
rows, err := tx.Query("SELECT COUNT(*) as count FROM svg_icon;")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
return nil, ErrSqliteTx
|
return nil, config.ErrSqliteTx
|
||||||
}
|
}
|
||||||
var tableLen int
|
var tableLen int
|
||||||
if !rows.Next() {
|
if !rows.Next() {
|
||||||
return nil, ErrEmptySvgTable
|
return nil, config.ErrEmptySvgTable
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = rows.Scan(&tableLen); err != nil {
|
if err = rows.Scan(&tableLen); err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
return nil, ErrSqliteTx
|
return nil, config.ErrSqliteTx
|
||||||
}
|
}
|
||||||
perm, err := util.RandomPermutation(tableLen)
|
perm, err := security.RandomPermutation(tableLen)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -551,7 +553,7 @@ func (d *SqliteDB) getRandomIds(count int) ([]int, error) {
|
|||||||
|
|
||||||
if err = tx.Commit(); err != nil {
|
if err = tx.Commit(); err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
return nil, ErrSqliteTx
|
return nil, config.ErrSqliteTx
|
||||||
}
|
}
|
||||||
|
|
||||||
return perm[:count], nil
|
return perm[:count], nil
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package core
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"go-nkode/internal/api"
|
||||||
|
"go-nkode/internal/models"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -22,9 +24,9 @@ func TestNewSqliteDB(t *testing.T) {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSignupLoginRenew(t *testing.T, db DbAccessor) {
|
func testSignupLoginRenew(t *testing.T, db api.DbAccessor) {
|
||||||
nkodePolicy := NewDefaultNKodePolicy()
|
nkodePolicy := models.NewDefaultNKodePolicy()
|
||||||
customerOrig, err := NewCustomer(nkodePolicy)
|
customerOrig, err := models.NewCustomer(nkodePolicy)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = db.WriteNewCustomer(*customerOrig)
|
err = db.WriteNewCustomer(*customerOrig)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@@ -32,16 +34,16 @@ func testSignupLoginRenew(t *testing.T, db DbAccessor) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, customerOrig, customer)
|
assert.Equal(t, customerOrig, customer)
|
||||||
username := "test_user@example.com"
|
username := "test_user@example.com"
|
||||||
kp := KeypadDefault
|
kp := models.KeypadDefault
|
||||||
passcodeIdx := []int{0, 1, 2, 3}
|
passcodeIdx := []int{0, 1, 2, 3}
|
||||||
mockSvgInterface := make(SvgIdInterface, kp.TotalAttrs())
|
mockSvgInterface := make(models.SvgIdInterface, kp.TotalAttrs())
|
||||||
ui, err := NewUserInterface(&kp, mockSvgInterface)
|
ui, err := models.NewUserInterface(&kp, mockSvgInterface)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
userOrig, err := NewUser(*customer, username, passcodeIdx, *ui, kp)
|
userOrig, err := models.NewUser(*customer, username, passcodeIdx, *ui, kp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
err = db.WriteNewUser(*userOrig)
|
err = db.WriteNewUser(*userOrig)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
user, err := db.GetUser(UserEmail(username), customer.Id)
|
user, err := db.GetUser(models.UserEmail(username), customer.Id)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, userOrig, user)
|
assert.Equal(t, userOrig, user)
|
||||||
|
|
||||||
@@ -50,8 +52,8 @@ func testSignupLoginRenew(t *testing.T, db DbAccessor) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testSqliteDBRandomSvgInterface(t *testing.T, db DbAccessor) {
|
func testSqliteDBRandomSvgInterface(t *testing.T, db api.DbAccessor) {
|
||||||
kp := KeypadMax
|
kp := models.KeypadMax
|
||||||
svgs, err := db.RandomSvgInterface(kp)
|
svgs, err := db.RandomSvgInterface(kp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, svgs, kp.TotalAttrs())
|
assert.Len(t, svgs, kp.TotalAttrs())
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package core
|
package email
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/aws/aws-sdk-go-v2/service/ses"
|
"github.com/aws/aws-sdk-go-v2/service/ses"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/ses/types"
|
"github.com/aws/aws-sdk-go-v2/service/ses/types"
|
||||||
"github.com/patrickmn/go-cache"
|
"github.com/patrickmn/go-cache"
|
||||||
|
config2 "go-nkode/config"
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -52,7 +53,7 @@ func NewSESClient() SESClient {
|
|||||||
func (s *SESClient) SendEmail(email Email) error {
|
func (s *SESClient) SendEmail(email Email) error {
|
||||||
if _, exists := s.ResetCache.Get(email.Recipient); exists {
|
if _, exists := s.ResetCache.Get(email.Recipient); exists {
|
||||||
log.Printf("email already sent to %s with subject %s", email.Recipient, email.Subject)
|
log.Printf("email already sent to %s with subject %s", email.Recipient, email.Subject)
|
||||||
return ErrEmailAlreadySent
|
return config2.ErrEmailAlreadySent
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load AWS configuration
|
// Load AWS configuration
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package core
|
package email
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
package core
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"go-nkode/hashset"
|
"go-nkode/config"
|
||||||
"go-nkode/util"
|
"go-nkode/internal/security"
|
||||||
|
"go-nkode/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Customer struct {
|
type Customer struct {
|
||||||
@@ -29,14 +30,14 @@ func NewCustomer(nkodePolicy NKodePolicy) (*Customer, error) {
|
|||||||
func (c *Customer) IsValidNKode(kp KeypadDimension, passcodeAttrIdx []int) error {
|
func (c *Customer) IsValidNKode(kp KeypadDimension, passcodeAttrIdx []int) error {
|
||||||
nkodeLen := len(passcodeAttrIdx)
|
nkodeLen := len(passcodeAttrIdx)
|
||||||
if nkodeLen < c.NKodePolicy.MinNkodeLen || nkodeLen > c.NKodePolicy.MaxNkodeLen {
|
if nkodeLen < c.NKodePolicy.MinNkodeLen || nkodeLen > c.NKodePolicy.MaxNkodeLen {
|
||||||
return ErrInvalidNKodeLength
|
return config.ErrInvalidNKodeLength
|
||||||
}
|
}
|
||||||
|
|
||||||
if validIdx := kp.ValidateAttributeIndices(passcodeAttrIdx); !validIdx {
|
if validIdx := kp.ValidateAttributeIndices(passcodeAttrIdx); !validIdx {
|
||||||
return ErrInvalidNKodeIdx
|
return config.ErrInvalidNKodeIdx
|
||||||
}
|
}
|
||||||
passcodeSetVals := make(hashset.Set[uint64])
|
passcodeSetVals := make(utils.Set[uint64])
|
||||||
passcodeAttrVals := make(hashset.Set[uint64])
|
passcodeAttrVals := make(utils.Set[uint64])
|
||||||
attrVals, err := c.Attributes.AttrValsForKp(kp)
|
attrVals, err := c.Attributes.AttrValsForKp(kp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -52,11 +53,11 @@ func (c *Customer) IsValidNKode(kp KeypadDimension, passcodeAttrIdx []int) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
if passcodeSetVals.Size() < c.NKodePolicy.DistinctSets {
|
if passcodeSetVals.Size() < c.NKodePolicy.DistinctSets {
|
||||||
return ErrTooFewDistinctSet
|
return config.ErrTooFewDistinctSet
|
||||||
}
|
}
|
||||||
|
|
||||||
if passcodeAttrVals.Size() < c.NKodePolicy.DistinctAttributes {
|
if passcodeAttrVals.Size() < c.NKodePolicy.DistinctAttributes {
|
||||||
return ErrTooFewDistinctAttributes
|
return config.ErrTooFewDistinctAttributes
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -71,11 +72,11 @@ func (c *Customer) RenewKeys() ([]uint64, []uint64, error) {
|
|||||||
if err := c.Attributes.Renew(); err != nil {
|
if err := c.Attributes.Renew(); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
attrsXor, err := util.XorLists(oldAttrs, c.Attributes.AttrVals)
|
attrsXor, err := security.XorLists(oldAttrs, c.Attributes.AttrVals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
setXor, err := util.XorLists(oldSets, c.Attributes.SetVals)
|
setXor, err := security.XorLists(oldSets, c.Attributes.SetVals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package core
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go-nkode/util"
|
"go-nkode/internal/security"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -11,12 +11,12 @@ type CustomerAttributes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewCustomerAttributes() (*CustomerAttributes, error) {
|
func NewCustomerAttributes() (*CustomerAttributes, error) {
|
||||||
attrVals, err := util.GenerateRandomNonRepeatingUint64(KeypadMax.TotalAttrs())
|
attrVals, err := security.GenerateRandomNonRepeatingUint64(KeypadMax.TotalAttrs())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("unable to generate attribute vals: ", err)
|
log.Print("unable to generate attribute vals: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
setVals, err := util.GenerateRandomNonRepeatingUint64(KeypadMax.AttrsPerKey)
|
setVals, err := security.GenerateRandomNonRepeatingUint64(KeypadMax.AttrsPerKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print("unable to generate set vals: ", err)
|
log.Print("unable to generate set vals: ", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -31,17 +31,17 @@ func NewCustomerAttributes() (*CustomerAttributes, error) {
|
|||||||
|
|
||||||
func NewCustomerAttributesFromBytes(attrBytes []byte, setBytes []byte) CustomerAttributes {
|
func NewCustomerAttributesFromBytes(attrBytes []byte, setBytes []byte) CustomerAttributes {
|
||||||
return CustomerAttributes{
|
return CustomerAttributes{
|
||||||
AttrVals: util.ByteArrToUint64Arr(attrBytes),
|
AttrVals: security.ByteArrToUint64Arr(attrBytes),
|
||||||
SetVals: util.ByteArrToUint64Arr(setBytes),
|
SetVals: security.ByteArrToUint64Arr(setBytes),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CustomerAttributes) Renew() error {
|
func (c *CustomerAttributes) Renew() error {
|
||||||
attrVals, err := util.GenerateRandomNonRepeatingUint64(KeypadMax.TotalAttrs())
|
attrVals, err := security.GenerateRandomNonRepeatingUint64(KeypadMax.TotalAttrs())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
setVals, err := util.GenerateRandomNonRepeatingUint64(KeypadMax.AttrsPerKey)
|
setVals, err := security.GenerateRandomNonRepeatingUint64(KeypadMax.AttrsPerKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -52,12 +52,12 @@ func (c *CustomerAttributes) Renew() error {
|
|||||||
|
|
||||||
func (c *CustomerAttributes) IndexOfAttr(attrVal uint64) (int, error) {
|
func (c *CustomerAttributes) IndexOfAttr(attrVal uint64) (int, error) {
|
||||||
// TODO: should this be mapped instead?
|
// TODO: should this be mapped instead?
|
||||||
return util.IndexOf[uint64](c.AttrVals, attrVal)
|
return security.IndexOf[uint64](c.AttrVals, attrVal)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CustomerAttributes) IndexOfSet(setVal uint64) (int, error) {
|
func (c *CustomerAttributes) IndexOfSet(setVal uint64) (int, error) {
|
||||||
// TODO: should this be mapped instead?
|
// TODO: should this be mapped instead?
|
||||||
return util.IndexOf[uint64](c.SetVals, setVal)
|
return security.IndexOf[uint64](c.SetVals, setVal)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CustomerAttributes) GetAttrSetVal(attrVal uint64, userKeypad KeypadDimension) (uint64, error) {
|
func (c *CustomerAttributes) GetAttrSetVal(attrVal uint64, userKeypad KeypadDimension) (uint64, error) {
|
||||||
@@ -86,9 +86,9 @@ func (c *CustomerAttributes) SetValsForKp(userKp KeypadDimension) ([]uint64, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *CustomerAttributes) AttrBytes() []byte {
|
func (c *CustomerAttributes) AttrBytes() []byte {
|
||||||
return util.Uint64ArrToByteArr(c.AttrVals)
|
return security.Uint64ArrToByteArr(c.AttrVals)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CustomerAttributes) SetBytes() []byte {
|
func (c *CustomerAttributes) SetBytes() []byte {
|
||||||
return util.Uint64ArrToByteArr(c.SetVals)
|
return security.Uint64ArrToByteArr(c.SetVals)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package core
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package core
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
py "go-nkode/py-builtin"
|
"go-nkode/config"
|
||||||
|
py "go-nkode/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type KeypadDimension struct {
|
type KeypadDimension struct {
|
||||||
@@ -19,7 +20,7 @@ func (kp *KeypadDimension) IsDispersable() bool {
|
|||||||
|
|
||||||
func (kp *KeypadDimension) IsValidKeypadDimension() error {
|
func (kp *KeypadDimension) IsValidKeypadDimension() error {
|
||||||
if KeypadMin.AttrsPerKey > kp.AttrsPerKey || KeypadMax.AttrsPerKey < kp.AttrsPerKey || KeypadMin.NumbOfKeys > kp.NumbOfKeys || KeypadMax.NumbOfKeys < kp.NumbOfKeys {
|
if KeypadMin.AttrsPerKey > kp.AttrsPerKey || KeypadMax.AttrsPerKey < kp.AttrsPerKey || KeypadMin.NumbOfKeys > kp.NumbOfKeys || KeypadMax.NumbOfKeys < kp.NumbOfKeys {
|
||||||
return ErrInvalidKeypadDimensions
|
return config.ErrInvalidKeypadDimensions
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package core
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -88,6 +88,7 @@ type GetLoginInterfaceResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type KeySelection []int
|
type KeySelection []int
|
||||||
|
|
||||||
type CustomerId uuid.UUID
|
type CustomerId uuid.UUID
|
||||||
|
|
||||||
func CustomerIdToString(customerId CustomerId) string {
|
func CustomerIdToString(customerId CustomerId) string {
|
||||||
@@ -138,17 +139,21 @@ type RGBColor struct {
|
|||||||
Blue int `json:"blue"`
|
Blue int `json:"blue"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DbAccessor interface {
|
var SetColors = []RGBColor{
|
||||||
GetCustomer(CustomerId) (*Customer, error)
|
{0, 0, 0}, // Black
|
||||||
GetUser(UserEmail, CustomerId) (*User, error)
|
{255, 0, 0}, // Red
|
||||||
WriteNewCustomer(Customer) error
|
{0, 128, 0}, // Dark Green
|
||||||
WriteNewUser(User) error
|
{0, 0, 255}, // Blue
|
||||||
UpdateUserNKode(User) error
|
{244, 200, 60}, // Yellow
|
||||||
UpdateUserInterface(UserId, UserInterface) error
|
{255, 0, 255}, // Magenta
|
||||||
UpdateUserRefreshToken(UserId, string) error
|
{0, 200, 200}, // Cyan
|
||||||
Renew(CustomerId) error
|
{127, 0, 127}, // Purple
|
||||||
RefreshUserPasscode(User, []int, CustomerAttributes) error
|
{232, 92, 13}, // Orange
|
||||||
RandomSvgInterface(KeypadDimension) ([]string, error)
|
{0, 127, 127}, // Teal
|
||||||
RandomSvgIdxInterface(KeypadDimension) (SvgIdInterface, error)
|
{127, 127, 0}, // Olive
|
||||||
GetSvgStringInterface(SvgIdInterface) ([]string, error)
|
{127, 0, 0}, // Dark Red
|
||||||
|
{128, 128, 128}, // Gray
|
||||||
|
{228, 102, 102}, // Dark Purple
|
||||||
|
{185, 17, 240}, // Salmon
|
||||||
|
{16, 200, 100}, // Green
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
package core
|
package models
|
||||||
|
|
||||||
|
import "go-nkode/config"
|
||||||
|
|
||||||
type NKodePolicy struct {
|
type NKodePolicy struct {
|
||||||
MaxNkodeLen int `json:"max_nkode_len"`
|
MaxNkodeLen int `json:"max_nkode_len"`
|
||||||
@@ -23,7 +25,7 @@ func NewDefaultNKodePolicy() NKodePolicy {
|
|||||||
func (p *NKodePolicy) ValidLength(nkodeLen int) error {
|
func (p *NKodePolicy) ValidLength(nkodeLen int) error {
|
||||||
|
|
||||||
if nkodeLen < p.MinNkodeLen || nkodeLen > p.MaxNkodeLen {
|
if nkodeLen < p.MinNkodeLen || nkodeLen > p.MaxNkodeLen {
|
||||||
return ErrInvalidNKodeLength
|
return config.ErrInvalidNKodeLength
|
||||||
}
|
}
|
||||||
// TODO: validate Max > Min
|
// TODO: validate Max > Min
|
||||||
// Validate lockout
|
// Validate lockout
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
package core
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go-nkode/util"
|
"go-nkode/internal/security"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SelectKeyByAttrIdx(interfaceUser []int, passcodeIdxs []int, keypadSize KeypadDimension) ([]int, error) {
|
func SelectKeyByAttrIdx(interfaceUser []int, passcodeIdxs []int, keypadSize KeypadDimension) ([]int, error) {
|
||||||
selectedKeys := make([]int, len(passcodeIdxs))
|
selectedKeys := make([]int, len(passcodeIdxs))
|
||||||
for idx := range passcodeIdxs {
|
for idx := range passcodeIdxs {
|
||||||
attrIdx, err := util.IndexOf[int](interfaceUser, passcodeIdxs[idx])
|
attrIdx, err := security.IndexOf[int](interfaceUser, passcodeIdxs[idx])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package core
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"go-nkode/util"
|
"go-nkode/config"
|
||||||
|
"go-nkode/internal/security"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,11 +26,11 @@ func (u *User) DecipherMask(setVals []uint64, passcodeLen int) ([]uint64, error)
|
|||||||
func (u *User) RenewKeys(setXor []uint64, attrXor []uint64) error {
|
func (u *User) RenewKeys(setXor []uint64, attrXor []uint64) error {
|
||||||
u.Renew = true
|
u.Renew = true
|
||||||
var err error
|
var err error
|
||||||
u.CipherKeys.SetKey, err = util.XorLists(setXor[:u.Kp.AttrsPerKey], u.CipherKeys.SetKey)
|
u.CipherKeys.SetKey, err = security.XorLists(setXor[:u.Kp.AttrsPerKey], u.CipherKeys.SetKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u.CipherKeys.AlphaKey, err = util.XorLists(attrXor[:u.Kp.TotalAttrs()], u.CipherKeys.AlphaKey)
|
u.CipherKeys.AlphaKey, err = security.XorLists(attrXor[:u.Kp.TotalAttrs()], u.CipherKeys.AlphaKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ func (u *User) GetLoginInterface() ([]int, error) {
|
|||||||
func ValidKeyEntry(user User, customer Customer, selectedKeys []int) ([]int, error) {
|
func ValidKeyEntry(user User, customer Customer, selectedKeys []int) ([]int, error) {
|
||||||
if validKeys := user.Kp.ValidKeySelections(selectedKeys); !validKeys {
|
if validKeys := user.Kp.ValidKeySelections(selectedKeys); !validKeys {
|
||||||
|
|
||||||
return nil, ErrKeyIndexOutOfRange
|
return nil, config.ErrKeyIndexOutOfRange
|
||||||
}
|
}
|
||||||
|
|
||||||
passcodeLen := len(selectedKeys)
|
passcodeLen := len(selectedKeys)
|
||||||
@@ -74,13 +75,13 @@ func ValidKeyEntry(user User, customer Customer, selectedKeys []int) ([]int, err
|
|||||||
setVals, err := customer.Attributes.SetValsForKp(user.Kp)
|
setVals, err := customer.Attributes.SetValsForKp(user.Kp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("fatal error in validate key entry;invalid user keypad dimensions for user %s with error %v", user.Email, err)
|
log.Printf("fatal error in validate key entry;invalid user keypad dimensions for user %s with error %v", user.Email, err)
|
||||||
return nil, ErrInternalValidKeyEntry
|
return nil, config.ErrInternalValidKeyEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
passcodeSetVals, err := user.DecipherMask(setVals, passcodeLen)
|
passcodeSetVals, err := user.DecipherMask(setVals, passcodeLen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("fatal error in validate key entry;something when wrong deciphering mask;user email %s; error %v", user.Email, err)
|
log.Printf("fatal error in validate key entry;something when wrong deciphering mask;user email %s; error %v", user.Email, err)
|
||||||
return nil, ErrInternalValidKeyEntry
|
return nil, config.ErrInternalValidKeyEntry
|
||||||
}
|
}
|
||||||
presumedAttrIdxVals := make([]int, passcodeLen)
|
presumedAttrIdxVals := make([]int, passcodeLen)
|
||||||
|
|
||||||
@@ -89,12 +90,12 @@ func ValidKeyEntry(user User, customer Customer, selectedKeys []int) ([]int, err
|
|||||||
setIdx, err := customer.Attributes.IndexOfSet(passcodeSetVals[idx])
|
setIdx, err := customer.Attributes.IndexOfSet(passcodeSetVals[idx])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("fatal error in validate key entry;something when wrong getting the IndexOfSet;user email %s; error %v", user.Email, err)
|
log.Printf("fatal error in validate key entry;something when wrong getting the IndexOfSet;user email %s; error %v", user.Email, err)
|
||||||
return nil, ErrInternalValidKeyEntry
|
return nil, config.ErrInternalValidKeyEntry
|
||||||
}
|
}
|
||||||
selectedAttrIdx, err := user.Interface.GetAttrIdxByKeyNumbSetIdx(setIdx, keyNumb)
|
selectedAttrIdx, err := user.Interface.GetAttrIdxByKeyNumbSetIdx(setIdx, keyNumb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("fatal error in validate key entry;something when wrong getting the GetAttrIdxByKeyNumbSetIdx;user email %s; error %v", user.Email, err)
|
log.Printf("fatal error in validate key entry;something when wrong getting the GetAttrIdxByKeyNumbSetIdx;user email %s; error %v", user.Email, err)
|
||||||
return nil, ErrInternalValidKeyEntry
|
return nil, config.ErrInternalValidKeyEntry
|
||||||
}
|
}
|
||||||
presumedAttrIdxVals[idx] = selectedAttrIdx
|
presumedAttrIdxVals[idx] = selectedAttrIdx
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
package core
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"errors"
|
"errors"
|
||||||
"go-nkode/util"
|
"go-nkode/config"
|
||||||
|
"go-nkode/internal/security"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -22,19 +23,19 @@ func NewUserCipherKeys(kp *KeypadDimension, setVals []uint64, maxNKodeLen int) (
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
setKey, err := util.GenerateRandomNonRepeatingUint64(kp.AttrsPerKey)
|
setKey, err := security.GenerateRandomNonRepeatingUint64(kp.AttrsPerKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
setKey, err = util.XorLists(setKey, setVals)
|
setKey, err = security.XorLists(setKey, setVals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
alphaKey, _ := util.GenerateRandomNonRepeatingUint64(kp.TotalAttrs())
|
alphaKey, _ := security.GenerateRandomNonRepeatingUint64(kp.TotalAttrs())
|
||||||
passKey, _ := util.GenerateRandomNonRepeatingUint64(maxNKodeLen)
|
passKey, _ := security.GenerateRandomNonRepeatingUint64(maxNKodeLen)
|
||||||
maskKey, _ := util.GenerateRandomNonRepeatingUint64(maxNKodeLen)
|
maskKey, _ := security.GenerateRandomNonRepeatingUint64(maxNKodeLen)
|
||||||
salt, _ := util.RandomBytes(10)
|
salt, _ := security.RandomBytes(10)
|
||||||
userCipherKeys := UserCipherKeys{
|
userCipherKeys := UserCipherKeys{
|
||||||
AlphaKey: alphaKey,
|
AlphaKey: alphaKey,
|
||||||
PassKey: passKey,
|
PassKey: passKey,
|
||||||
@@ -49,7 +50,7 @@ func NewUserCipherKeys(kp *KeypadDimension, setVals []uint64, maxNKodeLen int) (
|
|||||||
|
|
||||||
func (u *UserCipherKeys) PadUserMask(userMask []uint64, setVals []uint64) ([]uint64, error) {
|
func (u *UserCipherKeys) PadUserMask(userMask []uint64, setVals []uint64) ([]uint64, error) {
|
||||||
if len(userMask) > u.MaxNKodeLen {
|
if len(userMask) > u.MaxNKodeLen {
|
||||||
return nil, ErrUserMaskTooLong
|
return nil, config.ErrUserMaskTooLong
|
||||||
}
|
}
|
||||||
paddedUserMask := make([]uint64, len(userMask))
|
paddedUserMask := make([]uint64, len(userMask))
|
||||||
copy(paddedUserMask, userMask)
|
copy(paddedUserMask, userMask)
|
||||||
@@ -66,7 +67,7 @@ func (u *UserCipherKeys) ValidPassword(hashedPassword string, passcodeAttrIdx []
|
|||||||
err := bcrypt.CompareHashAndPassword(hashBytes, passwordDigest)
|
err := bcrypt.CompareHashAndPassword(hashBytes, passwordDigest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, bcrypt.ErrMismatchedHashAndPassword) {
|
if errors.Is(err, bcrypt.ErrMismatchedHashAndPassword) {
|
||||||
return ErrInvalidNKode
|
return config.ErrInvalidNKode
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -99,7 +100,7 @@ func (u *UserCipherKeys) encipherCode(passcodeAttrIdx []int, attrVals []uint64)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserCipherKeys) saltAndDigest(passcode []uint64) []byte {
|
func (u *UserCipherKeys) saltAndDigest(passcode []uint64) []byte {
|
||||||
passcodeBytes := util.Uint64ArrToByteArr(passcode)
|
passcodeBytes := security.Uint64ArrToByteArr(passcode)
|
||||||
passcodeBytes = append(passcodeBytes, u.Salt...)
|
passcodeBytes = append(passcodeBytes, u.Salt...)
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
h.Write(passcodeBytes)
|
h.Write(passcodeBytes)
|
||||||
@@ -136,27 +137,27 @@ func (u *UserCipherKeys) EncipherMask(passcodeSet []uint64, customerAttrs Custom
|
|||||||
setVal := paddedPasscodeSets[idx]
|
setVal := paddedPasscodeSets[idx]
|
||||||
cipheredMask[idx] = setKeyVal ^ maskKeyVal ^ setVal
|
cipheredMask[idx] = setKeyVal ^ maskKeyVal ^ setVal
|
||||||
}
|
}
|
||||||
mask := util.EncodeBase64Str(cipheredMask)
|
mask := security.EncodeBase64Str(cipheredMask)
|
||||||
return mask, nil
|
return mask, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserCipherKeys) DecipherMask(mask string, setVals []uint64, passcodeLen int) ([]uint64, error) {
|
func (u *UserCipherKeys) DecipherMask(mask string, setVals []uint64, passcodeLen int) ([]uint64, error) {
|
||||||
decodedMask, err := util.DecodeBase64Str(mask)
|
decodedMask, err := security.DecodeBase64Str(mask)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
decipheredMask, err := util.XorLists(decodedMask, u.MaskKey)
|
decipheredMask, err := security.XorLists(decodedMask, u.MaskKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
setKeyRandComponent, err := util.XorLists(setVals, u.SetKey)
|
setKeyRandComponent, err := security.XorLists(setVals, u.SetKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
passcodeSet := make([]uint64, passcodeLen)
|
passcodeSet := make([]uint64, passcodeLen)
|
||||||
for idx, setCipher := range decipheredMask[:passcodeLen] {
|
for idx, setCipher := range decipheredMask[:passcodeLen] {
|
||||||
setIdx, err := util.IndexOf(setKeyRandComponent, setCipher)
|
setIdx, err := security.IndexOf(setKeyRandComponent, setCipher)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package core
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go-nkode/hashset"
|
"go-nkode/config"
|
||||||
"go-nkode/util"
|
"go-nkode/internal/security"
|
||||||
|
"go-nkode/internal/utils"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ type UserInterface struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewUserInterface(kp *KeypadDimension, svgId SvgIdInterface) (*UserInterface, error) {
|
func NewUserInterface(kp *KeypadDimension, svgId SvgIdInterface) (*UserInterface, error) {
|
||||||
idxInterface := util.IdentityArray(kp.TotalAttrs())
|
idxInterface := security.IdentityArray(kp.TotalAttrs())
|
||||||
userInterface := UserInterface{
|
userInterface := UserInterface{
|
||||||
IdxInterface: idxInterface,
|
IdxInterface: idxInterface,
|
||||||
SvgId: svgId,
|
SvgId: svgId,
|
||||||
@@ -32,29 +33,29 @@ func (u *UserInterface) RandomShuffle() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
setView, err := util.MatrixTranspose(keypadView)
|
setView, err := security.MatrixTranspose(keypadView)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for idx, set := range setView {
|
for idx, set := range setView {
|
||||||
err := util.FisherYatesShuffle(&set)
|
err := security.FisherYatesShuffle(&set)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
setView[idx] = set
|
setView[idx] = set
|
||||||
}
|
}
|
||||||
|
|
||||||
keypadView, err = util.MatrixTranspose(setView)
|
keypadView, err = security.MatrixTranspose(setView)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u.IdxInterface = util.MatrixToList(keypadView)
|
u.IdxInterface = security.MatrixToList(keypadView)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) InterfaceMatrix() ([][]int, error) {
|
func (u *UserInterface) InterfaceMatrix() ([][]int, error) {
|
||||||
return util.ListToMatrix(u.IdxInterface, u.Kp.AttrsPerKey)
|
return security.ListToMatrix(u.IdxInterface, u.Kp.AttrsPerKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) SetViewMatrix() ([][]int, error) {
|
func (u *UserInterface) SetViewMatrix() ([][]int, error) {
|
||||||
@@ -62,12 +63,12 @@ func (u *UserInterface) SetViewMatrix() ([][]int, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return util.MatrixTranspose(keypadView)
|
return security.MatrixTranspose(keypadView)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) DisperseInterface() error {
|
func (u *UserInterface) DisperseInterface() error {
|
||||||
if !u.Kp.IsDispersable() {
|
if !u.Kp.IsDispersable() {
|
||||||
return ErrInterfaceNotDispersible
|
return config.ErrInterfaceNotDispersible
|
||||||
}
|
}
|
||||||
|
|
||||||
err := u.shuffleKeys()
|
err := u.shuffleKeys()
|
||||||
@@ -83,15 +84,15 @@ func (u *UserInterface) DisperseInterface() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) shuffleKeys() error {
|
func (u *UserInterface) shuffleKeys() error {
|
||||||
userInterfaceMatrix, err := util.ListToMatrix(u.IdxInterface, u.Kp.AttrsPerKey)
|
userInterfaceMatrix, err := security.ListToMatrix(u.IdxInterface, u.Kp.AttrsPerKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = util.FisherYatesShuffle[[]int](&userInterfaceMatrix)
|
err = security.FisherYatesShuffle[[]int](&userInterfaceMatrix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u.IdxInterface = util.MatrixToList(userInterfaceMatrix)
|
u.IdxInterface = security.MatrixToList(userInterfaceMatrix)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,9 +102,9 @@ func (u *UserInterface) randomAttributeRotation() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
transposeUserInterface, err := util.MatrixTranspose(userInterface)
|
transposeUserInterface, err := security.MatrixTranspose(userInterface)
|
||||||
|
|
||||||
attrRotation, err := util.RandomPermutation(len(transposeUserInterface))
|
attrRotation, err := security.RandomPermutation(len(transposeUserInterface))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -112,23 +113,23 @@ func (u *UserInterface) randomAttributeRotation() error {
|
|||||||
rotation := attrRotation[idx]
|
rotation := attrRotation[idx]
|
||||||
transposeUserInterface[idx] = append(attrSet[rotation:], attrSet[:rotation]...)
|
transposeUserInterface[idx] = append(attrSet[rotation:], attrSet[:rotation]...)
|
||||||
}
|
}
|
||||||
userInterface, err = util.MatrixTranspose(transposeUserInterface)
|
userInterface, err = security.MatrixTranspose(transposeUserInterface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u.IdxInterface = util.MatrixToList(userInterface)
|
u.IdxInterface = security.MatrixToList(userInterface)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) AttributeAdjacencyGraph() (map[int]hashset.Set[int], error) {
|
func (u *UserInterface) AttributeAdjacencyGraph() (map[int]utils.Set[int], error) {
|
||||||
interfaceKeypad, err := u.InterfaceMatrix()
|
interfaceKeypad, err := u.InterfaceMatrix()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
graph := make(map[int]hashset.Set[int])
|
graph := make(map[int]utils.Set[int])
|
||||||
|
|
||||||
for _, key := range interfaceKeypad {
|
for _, key := range interfaceKeypad {
|
||||||
keySet := hashset.NewSetFromSlice(key)
|
keySet := utils.NewSetFromSlice(key)
|
||||||
for _, attr := range key {
|
for _, attr := range key {
|
||||||
attrAdjacency := keySet.Copy()
|
attrAdjacency := keySet.Copy()
|
||||||
attrAdjacency.Remove(attr)
|
attrAdjacency.Remove(attr)
|
||||||
@@ -145,13 +146,13 @@ func (u *UserInterface) PartialInterfaceShuffle() error {
|
|||||||
}
|
}
|
||||||
numbOfSelectedSets := u.Kp.AttrsPerKey / 2
|
numbOfSelectedSets := u.Kp.AttrsPerKey / 2
|
||||||
if u.Kp.AttrsPerKey&1 == 1 {
|
if u.Kp.AttrsPerKey&1 == 1 {
|
||||||
numbOfSelectedSets += util.Choice[int]([]int{0, 1})
|
numbOfSelectedSets += security.Choice[int]([]int{0, 1})
|
||||||
}
|
}
|
||||||
setIdxs, err := util.RandomPermutation(u.Kp.AttrsPerKey)
|
setIdxs, err := security.RandomPermutation(u.Kp.AttrsPerKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
selectedSets := hashset.NewSetFromSlice[int](setIdxs[:numbOfSelectedSets])
|
selectedSets := utils.NewSetFromSlice[int](setIdxs[:numbOfSelectedSets])
|
||||||
|
|
||||||
keypadSetView, err := u.SetViewMatrix()
|
keypadSetView, err := u.SetViewMatrix()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -160,30 +161,30 @@ func (u *UserInterface) PartialInterfaceShuffle() error {
|
|||||||
interfaceBySet := make([][]int, u.Kp.AttrsPerKey)
|
interfaceBySet := make([][]int, u.Kp.AttrsPerKey)
|
||||||
for idx, attrs := range keypadSetView {
|
for idx, attrs := range keypadSetView {
|
||||||
if selectedSets.Contains(idx) {
|
if selectedSets.Contains(idx) {
|
||||||
err = util.FisherYatesShuffle[int](&attrs)
|
err = security.FisherYatesShuffle[int](&attrs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
interfaceBySet[idx] = attrs
|
interfaceBySet[idx] = attrs
|
||||||
}
|
}
|
||||||
keypadView, err := util.MatrixTranspose(interfaceBySet)
|
keypadView, err := security.MatrixTranspose(interfaceBySet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u.IdxInterface = util.MatrixToList(keypadView)
|
u.IdxInterface = security.MatrixToList(keypadView)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) GetAttrIdxByKeyNumbSetIdx(setIdx int, keyNumb int) (int, error) {
|
func (u *UserInterface) GetAttrIdxByKeyNumbSetIdx(setIdx int, keyNumb int) (int, error) {
|
||||||
if keyNumb < 0 || u.Kp.NumbOfKeys <= keyNumb {
|
if keyNumb < 0 || u.Kp.NumbOfKeys <= keyNumb {
|
||||||
log.Printf("keyNumb %d is out of range 0-%d", keyNumb, u.Kp.NumbOfKeys)
|
log.Printf("keyNumb %d is out of range 0-%d", keyNumb, u.Kp.NumbOfKeys)
|
||||||
return -1, ErrKeyIndexOutOfRange
|
return -1, config.ErrKeyIndexOutOfRange
|
||||||
}
|
}
|
||||||
|
|
||||||
if setIdx < 0 || u.Kp.AttrsPerKey <= setIdx {
|
if setIdx < 0 || u.Kp.AttrsPerKey <= setIdx {
|
||||||
log.Printf("setIdx %d is out of range 0-%d", setIdx, u.Kp.AttrsPerKey)
|
log.Printf("setIdx %d is out of range 0-%d", setIdx, u.Kp.AttrsPerKey)
|
||||||
return -1, ErrAttributeIndexOutOfRange
|
return -1, config.ErrAttributeIndexOutOfRange
|
||||||
}
|
}
|
||||||
keypadView, err := u.InterfaceMatrix()
|
keypadView, err := u.InterfaceMatrix()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package core
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"go-nkode/hashset"
|
"go-nkode/config"
|
||||||
py "go-nkode/py-builtin"
|
"go-nkode/internal/security"
|
||||||
"go-nkode/util"
|
py "go-nkode/internal/utils"
|
||||||
"log"
|
"log"
|
||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
@@ -55,32 +55,32 @@ func (s *UserSignSession) DeducePasscode(confirmKeyEntry KeySelection) ([]int, e
|
|||||||
|
|
||||||
if !validEntry {
|
if !validEntry {
|
||||||
log.Printf("Invalid Key entry. One or more key index: %#v, not in range 0-%d", confirmKeyEntry, s.Kp.NumbOfKeys)
|
log.Printf("Invalid Key entry. One or more key index: %#v, not in range 0-%d", confirmKeyEntry, s.Kp.NumbOfKeys)
|
||||||
return nil, ErrKeyIndexOutOfRange
|
return nil, config.ErrKeyIndexOutOfRange
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.SetIdxInterface == nil {
|
if s.SetIdxInterface == nil {
|
||||||
log.Print("signup session set interface is nil")
|
log.Print("signup session set interface is nil")
|
||||||
return nil, ErrIncompleteUserSignupSession
|
return nil, config.ErrIncompleteUserSignupSession
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.ConfirmIdxInterface == nil {
|
if s.ConfirmIdxInterface == nil {
|
||||||
log.Print("signup session confirm interface is nil")
|
log.Print("signup session confirm interface is nil")
|
||||||
return nil, ErrIncompleteUserSignupSession
|
return nil, config.ErrIncompleteUserSignupSession
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.SetKeySelection == nil {
|
if s.SetKeySelection == nil {
|
||||||
log.Print("signup session set key entry is nil")
|
log.Print("signup session set key entry is nil")
|
||||||
return nil, ErrIncompleteUserSignupSession
|
return nil, config.ErrIncompleteUserSignupSession
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.UserEmail == "" {
|
if s.UserEmail == "" {
|
||||||
log.Print("signup session username is nil")
|
log.Print("signup session username is nil")
|
||||||
return nil, ErrIncompleteUserSignupSession
|
return nil, config.ErrIncompleteUserSignupSession
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(confirmKeyEntry) != len(s.SetKeySelection) {
|
if len(confirmKeyEntry) != len(s.SetKeySelection) {
|
||||||
log.Printf("confirm and set key entry length mismatch %d != %d", len(confirmKeyEntry), len(s.SetKeySelection))
|
log.Printf("confirm and set key entry length mismatch %d != %d", len(confirmKeyEntry), len(s.SetKeySelection))
|
||||||
return nil, ErrSetConfirmSignupMismatch
|
return nil, config.ErrSetConfirmSignupMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
passcodeLen := len(confirmKeyEntry)
|
passcodeLen := len(confirmKeyEntry)
|
||||||
@@ -92,16 +92,16 @@ func (s *UserSignSession) DeducePasscode(confirmKeyEntry KeySelection) ([]int, e
|
|||||||
passcode := make([]int, passcodeLen)
|
passcode := make([]int, passcodeLen)
|
||||||
|
|
||||||
for idx := 0; idx < passcodeLen; idx++ {
|
for idx := 0; idx < passcodeLen; idx++ {
|
||||||
setKey := hashset.NewSetFromSlice[int](setKeyVals[idx])
|
setKey := py.NewSetFromSlice[int](setKeyVals[idx])
|
||||||
confirmKey := hashset.NewSetFromSlice[int](confirmKeyVals[idx])
|
confirmKey := py.NewSetFromSlice[int](confirmKeyVals[idx])
|
||||||
intersection := setKey.Intersect(confirmKey)
|
intersection := setKey.Intersect(confirmKey)
|
||||||
if intersection.Size() < 1 {
|
if intersection.Size() < 1 {
|
||||||
log.Printf("set and confirm do not intersect at index %d", idx)
|
log.Printf("set and confirm do not intersect at index %d", idx)
|
||||||
return nil, ErrSetConfirmSignupMismatch
|
return nil, config.ErrSetConfirmSignupMismatch
|
||||||
}
|
}
|
||||||
if intersection.Size() > 1 {
|
if intersection.Size() > 1 {
|
||||||
log.Printf("set and confirm intersect at more than one point at index %d", idx)
|
log.Printf("set and confirm intersect at more than one point at index %d", idx)
|
||||||
return nil, ErrSetConfirmSignupMismatch
|
return nil, config.ErrSetConfirmSignupMismatch
|
||||||
}
|
}
|
||||||
intersectionSlice := intersection.ToSlice()
|
intersectionSlice := intersection.ToSlice()
|
||||||
passcode[idx] = intersectionSlice[0]
|
passcode[idx] = intersectionSlice[0]
|
||||||
@@ -115,7 +115,7 @@ func (s *UserSignSession) SetUserNKode(keySelection KeySelection) (IdxInterface,
|
|||||||
})
|
})
|
||||||
if !validKeySelection {
|
if !validKeySelection {
|
||||||
log.Printf("one or key selection is out of range 0-%d", s.Kp.NumbOfKeys-1)
|
log.Printf("one or key selection is out of range 0-%d", s.Kp.NumbOfKeys-1)
|
||||||
return nil, ErrKeyIndexOutOfRange
|
return nil, config.ErrKeyIndexOutOfRange
|
||||||
}
|
}
|
||||||
|
|
||||||
s.SetKeySelection = keySelection
|
s.SetKeySelection = keySelection
|
||||||
@@ -131,7 +131,7 @@ func (s *UserSignSession) SetUserNKode(keySelection KeySelection) (IdxInterface,
|
|||||||
|
|
||||||
func (s *UserSignSession) getSelectedKeyVals(keySelections KeySelection, userInterface []int) ([][]int, error) {
|
func (s *UserSignSession) getSelectedKeyVals(keySelections KeySelection, userInterface []int) ([][]int, error) {
|
||||||
signupKp := s.SignupKeypad()
|
signupKp := s.SignupKeypad()
|
||||||
keypadInterface, err := util.ListToMatrix(userInterface, signupKp.AttrsPerKey)
|
keypadInterface, err := security.ListToMatrix(userInterface, signupKp.AttrsPerKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,7 @@ func (s *UserSignSession) getSelectedKeyVals(keySelections KeySelection, userInt
|
|||||||
func signupInterface(baseUserInterface UserInterface, kp KeypadDimension) (*UserInterface, []RGBColor, error) {
|
func signupInterface(baseUserInterface UserInterface, kp KeypadDimension) (*UserInterface, []RGBColor, error) {
|
||||||
// This method randomly drops sets from the base user interface so it is a square and dispersable matrix
|
// This method randomly drops sets from the base user interface so it is a square and dispersable matrix
|
||||||
if kp.IsDispersable() {
|
if kp.IsDispersable() {
|
||||||
return nil, nil, ErrKeypadIsNotDispersible
|
return nil, nil, config.ErrKeypadIsNotDispersible
|
||||||
}
|
}
|
||||||
err := baseUserInterface.RandomShuffle()
|
err := baseUserInterface.RandomShuffle()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -158,13 +158,13 @@ func signupInterface(baseUserInterface UserInterface, kp KeypadDimension) (*User
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
// attributes are arranged by set
|
// attributes are arranged by set
|
||||||
attrSetView, err := util.MatrixTranspose(interfaceMatrix)
|
attrSetView, err := security.MatrixTranspose(interfaceMatrix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
setIdxs := util.IdentityArray(kp.AttrsPerKey)
|
setIdxs := security.IdentityArray(kp.AttrsPerKey)
|
||||||
if err := util.FisherYatesShuffle[int](&setIdxs); err != nil {
|
if err := security.FisherYatesShuffle[int](&setIdxs); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
setIdxs = setIdxs[:kp.NumbOfKeys]
|
setIdxs = setIdxs[:kp.NumbOfKeys]
|
||||||
@@ -177,13 +177,13 @@ func signupInterface(baseUserInterface UserInterface, kp KeypadDimension) (*User
|
|||||||
selectedColors[idx] = SetColors[setIdx]
|
selectedColors[idx] = SetColors[setIdx]
|
||||||
}
|
}
|
||||||
// convert set view back into key view
|
// convert set view back into key view
|
||||||
selectedSets, err = util.MatrixTranspose(selectedSets)
|
selectedSets, err = security.MatrixTranspose(selectedSets)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
signupUserInterface := UserInterface{
|
signupUserInterface := UserInterface{
|
||||||
IdxInterface: util.MatrixToList(selectedSets),
|
IdxInterface: security.MatrixToList(selectedSets),
|
||||||
Kp: &KeypadDimension{
|
Kp: &KeypadDimension{
|
||||||
AttrsPerKey: kp.NumbOfKeys,
|
AttrsPerKey: kp.NumbOfKeys,
|
||||||
NumbOfKeys: kp.NumbOfKeys,
|
NumbOfKeys: kp.NumbOfKeys,
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package core
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
py "go-nkode/py-builtin"
|
py "go-nkode/internal/utils"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package core
|
package security
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
"go-nkode/util"
|
"github.com/google/uuid"
|
||||||
|
"go-nkode/config"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@@ -32,19 +33,19 @@ func getJwtSecret() []byte {
|
|||||||
log.Fatal("No JWT_SECRET found")
|
log.Fatal("No JWT_SECRET found")
|
||||||
}
|
}
|
||||||
|
|
||||||
jwtBytes, err := util.ParseHexString(jwtSecret)
|
jwtBytes, err := ParseHexString(jwtSecret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error parsing jwt secret %v", err)
|
log.Fatalf("error parsing jwt secret %v", err)
|
||||||
}
|
}
|
||||||
return jwtBytes
|
return jwtBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAuthenticationTokens(username string, customerId CustomerId) (AuthenticationTokens, error) {
|
func NewAuthenticationTokens(username string, customerId uuid.UUID) (AuthenticationTokens, error) {
|
||||||
accessClaims := NewAccessClaim(username, customerId)
|
accessClaims := NewAccessClaim(username, customerId)
|
||||||
|
|
||||||
refreshClaims := jwt.RegisteredClaims{
|
refreshClaims := jwt.RegisteredClaims{
|
||||||
Subject: username,
|
Subject: username,
|
||||||
Issuer: CustomerIdToString(customerId),
|
Issuer: customerId.String(),
|
||||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(refreshTokenExp)),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(refreshTokenExp)),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,10 +64,10 @@ func NewAuthenticationTokens(username string, customerId CustomerId) (Authentica
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAccessClaim(username string, customerId CustomerId) jwt.RegisteredClaims {
|
func NewAccessClaim(username string, customerId uuid.UUID) jwt.RegisteredClaims {
|
||||||
return jwt.RegisteredClaims{
|
return jwt.RegisteredClaims{
|
||||||
Subject: username,
|
Subject: username,
|
||||||
Issuer: CustomerIdToString(customerId),
|
Issuer: customerId.String(),
|
||||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(accessTokenExp)),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(accessTokenExp)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,31 +91,31 @@ func parseJwt[T *ResetNKodeClaims | *jwt.RegisteredClaims](tokenStr string, clai
|
|||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error parsing refresh token: %v", err)
|
log.Printf("error parsing refresh token: %v", err)
|
||||||
return nil, ErrInvalidJwt
|
return nil, config.ErrInvalidJwt
|
||||||
}
|
}
|
||||||
claims, ok := token.Claims.(T)
|
claims, ok := token.Claims.(T)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ErrInvalidJwt
|
return nil, config.ErrInvalidJwt
|
||||||
}
|
}
|
||||||
return claims, nil
|
return claims, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClaimExpired(claims jwt.RegisteredClaims) error {
|
func ClaimExpired(claims jwt.RegisteredClaims) error {
|
||||||
if claims.ExpiresAt == nil {
|
if claims.ExpiresAt == nil {
|
||||||
return ErrClaimExpOrNil
|
return config.ErrClaimExpOrNil
|
||||||
}
|
}
|
||||||
if claims.ExpiresAt.Time.After(time.Now()) {
|
if claims.ExpiresAt.Time.After(time.Now()) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return ErrClaimExpOrNil
|
return config.ErrClaimExpOrNil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResetNKodeToken(userEmail UserEmail, customerId CustomerId) (string, error) {
|
func ResetNKodeToken(userEmail string, customerId uuid.UUID) (string, error) {
|
||||||
resetClaims := ResetNKodeClaims{
|
resetClaims := ResetNKodeClaims{
|
||||||
true,
|
true,
|
||||||
jwt.RegisteredClaims{
|
jwt.RegisteredClaims{
|
||||||
Subject: string(userEmail),
|
Subject: userEmail,
|
||||||
Issuer: CustomerIdToString(customerId),
|
Issuer: customerId.String(),
|
||||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(resetNKodeTokenExp)),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(resetNKodeTokenExp)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package core
|
package security
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func TestJwtClaims(t *testing.T) {
|
func TestJwtClaims(t *testing.T) {
|
||||||
email := "testing@example.com"
|
email := "testing@example.com"
|
||||||
customerId := CustomerId(uuid.New())
|
customerId := uuid.New()
|
||||||
authTokens, err := NewAuthenticationTokens(email, customerId)
|
authTokens, err := NewAuthenticationTokens(email, customerId)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
accessToken, err := ParseRegisteredClaimToken(authTokens.AccessToken)
|
accessToken, err := ParseRegisteredClaimToken(authTokens.AccessToken)
|
||||||
@@ -19,7 +19,7 @@ func TestJwtClaims(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, refreshToken.Subject, email)
|
assert.Equal(t, refreshToken.Subject, email)
|
||||||
assert.NoError(t, ClaimExpired(*refreshToken))
|
assert.NoError(t, ClaimExpired(*refreshToken))
|
||||||
resetNKode, err := ResetNKodeToken(UserEmail(email), customerId)
|
resetNKode, err := ResetNKodeToken(email, customerId)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
resetToken, err := ParseRestNKodeToken(resetNKode)
|
resetToken, err := ParseRestNKodeToken(resetNKode)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package util
|
package security
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"go-nkode/hashset"
|
"go-nkode/internal/utils"
|
||||||
"log"
|
"log"
|
||||||
"math/big"
|
"math/big"
|
||||||
r "math/rand"
|
r "math/rand"
|
||||||
@@ -84,7 +84,7 @@ func GenerateRandomNonRepeatingUint64(listLen int) ([]uint64, error) {
|
|||||||
if listLen > int(1)<<32 {
|
if listLen > int(1)<<32 {
|
||||||
return nil, ErrRandNonRepeatingUint64
|
return nil, ErrRandNonRepeatingUint64
|
||||||
}
|
}
|
||||||
listSet := make(hashset.Set[uint64])
|
listSet := make(utils.Set[uint64])
|
||||||
for {
|
for {
|
||||||
if listSet.Size() == listLen {
|
if listSet.Size() == listLen {
|
||||||
break
|
break
|
||||||
@@ -104,7 +104,7 @@ func GenerateRandomNonRepeatingInt(listLen int) ([]int, error) {
|
|||||||
if listLen > int(1)<<31 {
|
if listLen > int(1)<<31 {
|
||||||
return nil, ErrRandNonRepeatingInt
|
return nil, ErrRandNonRepeatingInt
|
||||||
}
|
}
|
||||||
listSet := make(hashset.Set[int])
|
listSet := make(utils.Set[int])
|
||||||
for {
|
for {
|
||||||
if listSet.Size() == listLen {
|
if listSet.Size() == listLen {
|
||||||
break
|
break
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package util
|
package security
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package hashset
|
package utils
|
||||||
|
|
||||||
type Set[T comparable] map[T]struct{}
|
type Set[T comparable] map[T]struct{}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package hashset
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package py_builtin
|
package utils
|
||||||
|
|
||||||
func All[T comparable](slice []T, condition func(T) bool) bool {
|
func All[T comparable](slice []T, condition func(T) bool) bool {
|
||||||
|
|
||||||
77
main.go
77
main.go
@@ -1,77 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"go-nkode/core"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
emailQueueBufferSize = 100
|
|
||||||
maxEmailsPerSecond = 13 // SES allows 14, but I don't want to push it
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
dbPath := os.Getenv("SQLITE_DB")
|
|
||||||
if dbPath == "" {
|
|
||||||
log.Fatalf("SQLITE_DB=/path/to/nkode.db not set")
|
|
||||||
}
|
|
||||||
db := core.NewSqliteDB(dbPath)
|
|
||||||
defer db.CloseDb()
|
|
||||||
sesClient := core.NewSESClient()
|
|
||||||
emailQueue := core.NewEmailQueue(emailQueueBufferSize, maxEmailsPerSecond, &sesClient)
|
|
||||||
emailQueue.Start()
|
|
||||||
defer emailQueue.Stop()
|
|
||||||
nkodeApi := core.NewNKodeAPI(db, emailQueue)
|
|
||||||
AddDefaultCustomer(nkodeApi)
|
|
||||||
handler := core.NKodeHandler{Api: nkodeApi}
|
|
||||||
mux := http.NewServeMux()
|
|
||||||
mux.Handle(core.CreateNewCustomer, &handler)
|
|
||||||
mux.Handle(core.GenerateSignupResetInterface, &handler)
|
|
||||||
mux.Handle(core.SetNKode, &handler)
|
|
||||||
mux.Handle(core.ConfirmNKode, &handler)
|
|
||||||
mux.Handle(core.GetLoginInterface, &handler)
|
|
||||||
mux.Handle(core.Login, &handler)
|
|
||||||
mux.Handle(core.RenewAttributes, &handler)
|
|
||||||
mux.Handle(core.RandomSvgInterface, &handler)
|
|
||||||
mux.Handle(core.RefreshToken, &handler)
|
|
||||||
mux.Handle(core.ResetNKode, &handler)
|
|
||||||
fmt.Println("Running on localhost:8080...")
|
|
||||||
log.Fatal(http.ListenAndServe(":8080", corsMiddleware(mux)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func corsMiddleware(next http.Handler) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
// Set the CORS headers
|
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE")
|
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if r.Method == http.MethodOptions {
|
|
||||||
w.WriteHeader(http.StatusNoContent)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call the next handler
|
|
||||||
next.ServeHTTP(w, r)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddDefaultCustomer(api core.NKodeAPI) {
|
|
||||||
newId, err := uuid.Parse("ed9ed6e0-082c-4b57-8d8c-f00ed6493457")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
customerId := core.CustomerId(newId)
|
|
||||||
nkodePolicy := core.NewDefaultNKodePolicy()
|
|
||||||
_, err = api.CreateNewCustomer(nkodePolicy, &customerId)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
} else {
|
|
||||||
log.Println("created new customer: ", newId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user