mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-08 14:15:25 +08:00
* feat: api access tokens
* revoke all user tokens
* redefine access token api routes, add auto egress option to enrollment keys
* add server settings apis, add db table for settigs
* handle server settings updates
* switch to using settings from DB
* fix sever settings migration
* revet force migration for settings
* fix server settings database write
* fix revoked tokens to be unauthorized
* remove unused functions
* convert access token to sql schema
* switch access token to sql schema
* fix merge conflicts
* fix server settings types
* bypass basic auth setting for super admin
* add TODO comment
* publish peer update on settings update
* chore(go): import style changes from migration branch;
1. Singular file names for table schema.
2. No table name method.
3. Use .Model instead of .Table.
4. No unnecessary tagging.
* remove nat check on egress gateway request
* Revert "remove nat check on egress gateway request"
This reverts commit 0aff12a189
.
* feat(go): add db middleware;
* feat(go): restore method;
* feat(go): add user access token schema;
* fix user auth api:
* re initalise oauth and email config
* set verbosity
* sync auto update settings with hosts
* sync auto update settings with hosts
* mask secret and convert jwt duration to minutes
* convert jwt duration to minutes
* notify peers after settings update
* compare with curr settings before updating
* send host update to devices on auto update
---------
Co-authored-by: Vishal Dalwadi <dalwadivishal26@gmail.com>
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package schema
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/gravitl/netmaker/db"
|
|
)
|
|
|
|
// UserAccessToken - token used to access netmaker
|
|
type UserAccessToken struct {
|
|
ID string `gorm:"primaryKey" json:"id"`
|
|
Name string `json:"name"`
|
|
UserName string `json:"user_name"`
|
|
ExpiresAt time.Time `json:"expires_at"`
|
|
LastUsed time.Time `json:"last_used"`
|
|
CreatedBy string `json:"created_by"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
func (a *UserAccessToken) Get(ctx context.Context) error {
|
|
return db.FromContext(ctx).Model(&UserAccessToken{}).First(&a).Where("id = ?", a.ID).Error
|
|
}
|
|
|
|
func (a *UserAccessToken) Update(ctx context.Context) error {
|
|
return db.FromContext(ctx).Model(&UserAccessToken{}).Where("id = ?", a.ID).Updates(&a).Error
|
|
}
|
|
|
|
func (a *UserAccessToken) Create(ctx context.Context) error {
|
|
return db.FromContext(ctx).Model(&UserAccessToken{}).Create(&a).Error
|
|
}
|
|
|
|
func (a *UserAccessToken) List(ctx context.Context) (ats []UserAccessToken, err error) {
|
|
err = db.FromContext(ctx).Model(&UserAccessToken{}).Find(&ats).Error
|
|
return
|
|
}
|
|
|
|
func (a *UserAccessToken) ListByUser(ctx context.Context) (ats []UserAccessToken) {
|
|
db.FromContext(ctx).Model(&UserAccessToken{}).Where("user_name = ?", a.UserName).Find(&ats)
|
|
if ats == nil {
|
|
ats = []UserAccessToken{}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (a *UserAccessToken) Delete(ctx context.Context) error {
|
|
return db.FromContext(ctx).Model(&UserAccessToken{}).Where("id = ?", a.ID).Delete(&a).Error
|
|
}
|
|
|
|
func (a *UserAccessToken) DeleteAllUserTokens(ctx context.Context) error {
|
|
return db.FromContext(ctx).Model(&UserAccessToken{}).Where("user_name = ?", a.UserName).Delete(&a).Error
|
|
}
|