Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TAG := $(shell git rev-list --tags --max-count=1)
VERSION := $(shell git describe --tags ${TAG})
.PHONY: build check fmt lint test test-race vet test-cover-html help install proto admin-app compose-up-dev
.DEFAULT_GOAL := build
PROTON_COMMIT := "330c7558f34570056814d418f99730fb45cfe80f"
PROTON_COMMIT := "08620d9bb9a3eb4f46adc2d828e61605e8503306"

admin-app:
@echo " > generating admin build"
Expand Down
6 changes: 6 additions & 0 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/raystack/frontier/core/kyc"
"github.com/raystack/frontier/core/prospect"
"github.com/raystack/frontier/core/userpat"

"golang.org/x/exp/slices"

Expand Down Expand Up @@ -387,6 +388,8 @@ func buildAPIDependencies(
prospectRepository := postgres.NewProspectRepository(dbc)
prospectService := prospect.NewService(prospectRepository)

userPATRepo := postgres.NewUserPATRepository(dbc)

svUserRepo := postgres.NewServiceUserRepository(dbc)
scUserCredRepo := postgres.NewServiceUserCredentialRepository(dbc)
serviceUserService := serviceuser.NewService(svUserRepo, scUserCredRepo, relationService)
Expand Down Expand Up @@ -430,6 +433,8 @@ func buildAPIDependencies(
organizationService := organization.NewService(organizationRepository, relationService, userService,
authnService, policyService, preferenceService, auditRecordRepository)

userPATService := userpat.NewService(logger, userPATRepo, cfg.App.PAT, organizationService, auditRecordRepository)

auditRecordService := auditrecord.NewService(auditRecordRepository, userService, serviceUserService, sessionService)

orgKycRepository := postgres.NewOrgKycRepository(dbc)
Expand Down Expand Up @@ -621,6 +626,7 @@ func buildAPIDependencies(
UserOrgsService: userOrgsService,
UserProjectsService: userProjectsService,
AuditRecordService: auditRecordService,
UserPATService: userPATService,
}
return dependencies, nil
}
Expand Down
20 changes: 20 additions & 0 deletions core/userpat/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package userpat

import "time"

type Config struct {
Enabled bool `yaml:"enabled" mapstructure:"enabled" default:"false"`
TokenPrefix string `yaml:"token_prefix" mapstructure:"token_prefix" default:"fpt"`
MaxTokensPerUserPerOrg int64 `yaml:"max_tokens_per_user_per_org" mapstructure:"max_tokens_per_user_per_org" default:"50"`
MaxTokenLifetime string `yaml:"max_token_lifetime" mapstructure:"max_token_lifetime" default:"8760h"`
DefaultTokenLifetime string `yaml:"default_token_lifetime" mapstructure:"default_token_lifetime" default:"2160h"`
DeniedRoles []string `yaml:"denied_roles" mapstructure:"denied_roles"`
}

func (c Config) MaxExpiry() time.Duration {
d, err := time.ParseDuration(c.MaxTokenLifetime)
if err != nil {
return 365 * 24 * time.Hour
}
return d
}
14 changes: 14 additions & 0 deletions core/userpat/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package userpat

import "errors"

var (
ErrNotFound = errors.New("personal access token not found")
ErrConflict = errors.New("personal access token with this name already exists")
ErrExpired = errors.New("personal access token has expired")
ErrInvalidToken = errors.New("personal access token is invalid")
ErrLimitExceeded = errors.New("maximum number of personal access tokens reached")
ErrDisabled = errors.New("personal access tokens are not enabled")
ErrExpiryExceeded = errors.New("expiry exceeds maximum allowed lifetime")
ErrExpiryInPast = errors.New("expiry must be in the future")
)
94 changes: 94 additions & 0 deletions core/userpat/mocks/audit_record_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions core/userpat/mocks/organization_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading