Skip to content

Commit

Permalink
Move Tokenmanager to shared.Commons
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Richter <[email protected]>
  • Loading branch information
dragonchaser committed Apr 25, 2022
1 parent 699f929 commit f77c001
Show file tree
Hide file tree
Showing 22 changed files with 407 additions and 362 deletions.
7 changes: 1 addition & 6 deletions extensions/accounts/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Config struct {
HTTP HTTP `yaml:"http,omitempty"`
GRPC GRPC `yaml:"grpc,omitempty"`

TokenManager TokenManager `yaml:"token_manager"`
TokenManager *shared.TokenManager `yaml:"token_manager,omitempty"`

Asset Asset `yaml:"asset,omitempty"`
Repo Repo `yaml:"repo,omitempty"`
Expand All @@ -36,11 +36,6 @@ type Asset struct {
Path string `yaml:"path" env:"ACCOUNTS_ASSET_PATH" desc:"The path to the ui assets."`
}

// TokenManager is the config for using the reva token manager
type TokenManager struct {
JWTSecret string `yaml:"jwt_secret" env:"OCIS_JWT_SECRET;ACCOUNTS_JWT_SECRET" desc:"The secret to mint jwt tokens."`
}

// Repo defines which storage implementation is to be used.
type Repo struct {
Backend string `yaml:"backend" env:"ACCOUNTS_STORAGE_BACKEND" desc:"Defines which storage implementation is to be used"`
Expand Down
14 changes: 10 additions & 4 deletions extensions/accounts/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/owncloud/ocis/extensions/accounts/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
"github.com/owncloud/ocis/ocis-pkg/shared"
)

func FullDefaultConfig() *config.Config {
Expand Down Expand Up @@ -44,10 +45,7 @@ func DefaultConfig() *config.Config {
Service: config.Service{
Name: "accounts",
},
Asset: config.Asset{},
TokenManager: config.TokenManager{
JWTSecret: "Pive-Fumkiu4",
},
Asset: config.Asset{},
HashDifficulty: 11,
DemoUsersAndGroups: false,
Repo: config.Repo{
Expand Down Expand Up @@ -101,6 +99,14 @@ func EnsureDefaults(cfg *config.Config) {
} else if cfg.Tracing == nil {
cfg.Tracing = &config.Tracing{}
}

if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil {
cfg.TokenManager = &shared.TokenManager{
JWTSecret: cfg.Commons.TokenManager.JWTSecret,
}
} else {
cfg.TokenManager = &shared.TokenManager{}
}
}

func Sanitize(cfg *config.Config) {
Expand Down
4 changes: 2 additions & 2 deletions extensions/graph/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type Config struct {

HTTP HTTP `yaml:"http,omitempty"`

Reva Reva `yaml:"reva,omitempty"`
TokenManager TokenManager `yaml:"token_manager"`
Reva Reva `yaml:"reva,omitempty"`
TokenManager *shared.TokenManager `yaml:"token_manager,omitempty"`

Spaces Spaces `yaml:"spaces,omitempty"`
Identity Identity `yaml:"identity,omitempty"`
Expand Down
12 changes: 9 additions & 3 deletions extensions/graph/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

"github.com/owncloud/ocis/extensions/graph/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/shared"
)

func DefaultConfig() *config.Config {
Expand All @@ -23,9 +24,6 @@ func DefaultConfig() *config.Config {
Reva: config.Reva{
Address: "127.0.0.1:9142",
},
TokenManager: config.TokenManager{
JWTSecret: "Pive-Fumkiu4",
},
Spaces: config.Spaces{
WebDavBase: "https://localhost:9200",
WebDavPath: "/dav/spaces/",
Expand Down Expand Up @@ -89,6 +87,14 @@ func EnsureDefaults(cfg *config.Config) {
} else if cfg.Tracing == nil {
cfg.Tracing = &config.Tracing{}
}

if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil {
cfg.TokenManager = &shared.TokenManager{
JWTSecret: cfg.Commons.TokenManager.JWTSecret,
}
} else {
cfg.TokenManager = &shared.TokenManager{}
}
}

func Sanitize(cfg *config.Config) {
Expand Down
5 changes: 0 additions & 5 deletions extensions/graph/pkg/config/reva.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@ package config
type Reva struct {
Address string `yaml:"address" env:"REVA_GATEWAY"`
}

// TokenManager is the config for using the reva token manager
type TokenManager struct {
JWTSecret string `yaml:"jwt_secret" env:"OCIS_JWT_SECRET;GRAPH_JWT_SECRET"`
}
4 changes: 2 additions & 2 deletions extensions/ocs/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type Config struct {

HTTP HTTP `yaml:"http,omitempty"`

TokenManager TokenManager `yaml:"token_manager,omitempty"`
Reva Reva `yaml:"reva,omitempty"`
TokenManager *shared.TokenManager `yaml:"token_manager,omitempty"`
Reva Reva `yaml:"reva,omitempty"`

IdentityManagement IdentityManagement `yaml:"identity_management,omitempty"`

Expand Down
11 changes: 8 additions & 3 deletions extensions/ocs/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

"github.com/owncloud/ocis/extensions/ocs/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/shared"
)

func FullDefaultConfig() *config.Config {
Expand Down Expand Up @@ -38,9 +39,6 @@ func DefaultConfig() *config.Config {
Name: "ocs",
},

TokenManager: config.TokenManager{
JWTSecret: "Pive-Fumkiu4",
},
AccountBackend: "accounts",
Reva: config.Reva{
Address: "127.0.0.1:9142",
Expand Down Expand Up @@ -77,6 +75,13 @@ func EnsureDefaults(cfg *config.Config) {
cfg.Tracing = &config.Tracing{}
}

if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil {
cfg.TokenManager = &shared.TokenManager{
JWTSecret: cfg.Commons.TokenManager.JWTSecret,
}
} else {
cfg.TokenManager = &shared.TokenManager{}
}
}

func Sanitize(cfg *config.Config) {
Expand Down
5 changes: 0 additions & 5 deletions extensions/ocs/pkg/config/reva.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@ package config
type Reva struct {
Address string `yaml:"address" env:"REVA_GATEWAY"`
}

// TokenManager is the config for using the reva token manager
type TokenManager struct {
JWTSecret string `yaml:"jwt_secret" env:"OCIS_JWT_SECRET;OCS_JWT_SECRET"`
}
2 changes: 1 addition & 1 deletion extensions/ocs/pkg/server/http/svc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ func getService() svc.Service {
Root: "/",
Addr: "localhost:9110",
},
TokenManager: config.TokenManager{
TokenManager: &config.TokenManager{
JWTSecret: jwtSecret,
},
Log: &config.Log{
Expand Down
4 changes: 2 additions & 2 deletions extensions/proxy/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func loadMiddlewares(ctx context.Context, logger log.Logger, cfg *config.Config)
middleware.AccountResolver(
middleware.Logger(logger),
middleware.UserProvider(userProvider),
middleware.TokenManagerConfig(cfg.TokenManager),
middleware.TokenManagerConfig(*cfg.TokenManager),
middleware.UserOIDCClaim(cfg.UserOIDCClaim),
middleware.UserCS3Claim(cfg.UserCS3Claim),
middleware.AutoprovisionAccounts(cfg.AutoprovisionAccounts),
Expand All @@ -227,7 +227,7 @@ func loadMiddlewares(ctx context.Context, logger log.Logger, cfg *config.Config)
// finally, trigger home creation when a user logs in
middleware.CreateHome(
middleware.Logger(logger),
middleware.TokenManagerConfig(cfg.TokenManager),
middleware.TokenManagerConfig(*cfg.TokenManager),
middleware.RevaGatewayClient(revaClient),
),
middleware.PublicShareAuth(
Expand Down
2 changes: 1 addition & 1 deletion extensions/proxy/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Config struct {

Policies []Policy `yaml:"policies,omitempty"`
OIDC OIDC `yaml:"oidc,omitempty"`
TokenManager TokenManager `yaml:"token_manager,omitempty"`
TokenManager *TokenManager `yaml:"token_manager,omitempty"`
PolicySelector *PolicySelector `yaml:"policy_selector,omitempty"`
PreSignedURL PreSignedURL `yaml:"pre_signed_url,omitempty"`
AccountBackend string `yaml:"account_backend,omitempty" env:"PROXY_ACCOUNT_BACKEND_TYPE"`
Expand Down
10 changes: 7 additions & 3 deletions extensions/proxy/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ func DefaultConfig() *config.Config {
TTL: 10,
},
},
TokenManager: config.TokenManager{
JWTSecret: "Pive-Fumkiu4",
},
PolicySelector: nil,
Reva: config.Reva{
Address: "127.0.0.1:9142",
Expand Down Expand Up @@ -181,6 +178,13 @@ func EnsureDefaults(cfg *config.Config) {
cfg.Tracing = &config.Tracing{}
}

if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil {
cfg.TokenManager = &config.TokenManager{
JWTSecret: cfg.Commons.TokenManager.JWTSecret,
}
} else {
cfg.TokenManager = &config.TokenManager{}
}
}

func Sanitize(cfg *config.Config) {
Expand Down
4 changes: 2 additions & 2 deletions extensions/settings/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type Config struct {
DataPath string `yaml:"data_path,omitempty" env:"SETTINGS_DATA_PATH"`
Metadata Metadata `yaml:"metadata_config,omitempty"`

Asset Asset `yaml:"asset,omitempty"`
TokenManager TokenManager `yaml:"token_manager,omitempty"`
Asset Asset `yaml:"asset,omitempty"`
TokenManager *shared.TokenManager `yaml:"token_manager,omitempty"`

Context context.Context `yaml:"-"`
}
Expand Down
12 changes: 9 additions & 3 deletions extensions/settings/pkg/config/defaults/defaultconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/owncloud/ocis/extensions/settings/pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
"github.com/owncloud/ocis/ocis-pkg/shared"
)

func FullDefaultConfig() *config.Config {
Expand Down Expand Up @@ -50,9 +51,6 @@ func DefaultConfig() *config.Config {
Asset: config.Asset{
Path: "",
},
TokenManager: config.TokenManager{
JWTSecret: "Pive-Fumkiu4",
},

Metadata: config.Metadata{
GatewayAddress: "127.0.0.1:9142",
Expand Down Expand Up @@ -87,6 +85,14 @@ func EnsureDefaults(cfg *config.Config) {
} else if cfg.Tracing == nil {
cfg.Tracing = &config.Tracing{}
}

if cfg.TokenManager == nil && cfg.Commons != nil && cfg.Commons.TokenManager != nil {
cfg.TokenManager = &shared.TokenManager{
JWTSecret: cfg.Commons.TokenManager.JWTSecret,
}
} else {
cfg.TokenManager = &shared.TokenManager{}
}
}

func Sanitize(cfg *config.Config) {
Expand Down
Loading

0 comments on commit f77c001

Please sign in to comment.