From 07843042a5365427c472a9c26554c04f2be7b32a Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Tue, 16 Feb 2021 14:13:32 +0100 Subject: [PATCH] Separation of concerns --- changelog/unreleased/reva-group-provider.md | 11 ++- storage/pkg/flagset/groups.go | 69 +------------------ storage/pkg/flagset/rest.go | 75 +++++++++++++++++++++ storage/pkg/flagset/sharing.go | 36 +--------- storage/pkg/flagset/sharingsql.go | 47 +++++++++++++ storage/pkg/flagset/users.go | 67 +----------------- 6 files changed, 135 insertions(+), 170 deletions(-) create mode 100644 storage/pkg/flagset/rest.go create mode 100644 storage/pkg/flagset/sharingsql.go diff --git a/changelog/unreleased/reva-group-provider.md b/changelog/unreleased/reva-group-provider.md index 3aacb370076..043e8a6b548 100644 --- a/changelog/unreleased/reva-group-provider.md +++ b/changelog/unreleased/reva-group-provider.md @@ -1,3 +1,10 @@ -Enhancement: Add config for group provider service and sharing SQL driver +Enhancement: Enable group sharing and add config for sharing SQL driver -https://github.com/owncloud/ocis/pull/1626/files +This PR adds config to support sharing with groups. It also introduces a +breaking change for the CS3APIs definitions since grantees can now refer to both +users as well as groups. Since we store the grantee information in a json file, +`/var/tmp/ocis/storage/shares.json`, its previous version needs to be removed as +we won't be able to unmarshal data corresponding to the previous definitions. + +https://github.com/owncloud/ocis/pull/1626 +https://github.com/cs3org/reva/pull/1453 diff --git a/storage/pkg/flagset/groups.go b/storage/pkg/flagset/groups.go index c3f4e3f4168..e472a068e2a 100644 --- a/storage/pkg/flagset/groups.go +++ b/storage/pkg/flagset/groups.go @@ -64,85 +64,20 @@ func GroupsWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_GROUPPROVIDER_JSON"}, Destination: &cfg.Reva.Groups.JSON, }, - &cli.IntFlag{ + &cli.IntFlag{ Name: "group-members-cache-expiration", Value: 5, Usage: "Time in minutes for redis cache expiration.", EnvVars: []string{"STORAGE_GROUP_CACHE_EXPIRATION"}, Destination: &cfg.Reva.Groups.GroupMembersCacheExpiration, }, - - // rest driver - - &cli.StringFlag{ - Name: "rest-client-id", - Value: "", - Usage: "User/group rest driver Client ID", - EnvVars: []string{"STORAGE_REST_CLIENT_ID"}, - Destination: &cfg.Reva.UserGroupRest.ClientID, - }, - &cli.StringFlag{ - Name: "rest-client-secret", - Value: "", - Usage: "User/group rest driver Client Secret", - EnvVars: []string{"STORAGE_REST_CLIENT_SECRET"}, - Destination: &cfg.Reva.UserGroupRest.ClientSecret, - }, - &cli.StringFlag{ - Name: "rest-redis-address", - Value: "localhost:6379", - Usage: "Address for redis server", - EnvVars: []string{"STORAGE_REST_REDIS_ADDRESS"}, - Destination: &cfg.Reva.UserGroupRest.RedisAddress, - }, - &cli.StringFlag{ - Name: "rest-redis-username", - Value: "", - Usage: "Username for redis server", - EnvVars: []string{"STORAGE_REST_REDIS_USERNAME"}, - Destination: &cfg.Reva.UserGroupRest.RedisUsername, - }, - &cli.StringFlag{ - Name: "rest-redis-password", - Value: "", - Usage: "Password for redis server", - EnvVars: []string{"STORAGE_REST_REDIS_PASSWORD"}, - Destination: &cfg.Reva.UserGroupRest.RedisPassword, - }, - &cli.StringFlag{ - Name: "rest-id-provider", - Value: "", - Usage: "The OIDC Provider", - EnvVars: []string{"STORAGE_REST_ID_PROVIDER"}, - Destination: &cfg.Reva.UserGroupRest.IDProvider, - }, - &cli.StringFlag{ - Name: "rest-api-base-url", - Value: "", - Usage: "Base API Endpoint", - EnvVars: []string{"STORAGE_REST_API_BASE_URL"}, - Destination: &cfg.Reva.UserGroupRest.APIBaseURL, - }, - &cli.StringFlag{ - Name: "rest-oidc-token-endpoint", - Value: "", - Usage: "Endpoint to generate token to access the API", - EnvVars: []string{"STORAGE_REST_OIDC_TOKEN_ENDPOINT"}, - Destination: &cfg.Reva.UserGroupRest.OIDCTokenEndpoint, - }, - &cli.StringFlag{ - Name: "rest-target-api", - Value: "", - Usage: "The target application", - EnvVars: []string{"STORAGE_REST_TARGET_API"}, - Destination: &cfg.Reva.UserGroupRest.TargetAPI, - }, } flags = append(flags, TracingWithConfig(cfg)...) flags = append(flags, DebugWithConfig(cfg)...) flags = append(flags, SecretWithConfig(cfg)...) flags = append(flags, LDAPWithConfig(cfg)...) + flags = append(flags, RestWithConfig(cfg)...) return flags } diff --git a/storage/pkg/flagset/rest.go b/storage/pkg/flagset/rest.go new file mode 100644 index 00000000000..2e733596f63 --- /dev/null +++ b/storage/pkg/flagset/rest.go @@ -0,0 +1,75 @@ +package flagset + +import ( + "github.com/micro/cli/v2" + "github.com/owncloud/ocis/storage/pkg/config" +) + +// RestWithConfig applies REST user/group provider cfg to the flagset +func RestWithConfig(cfg *config.Config) []cli.Flag { + return []cli.Flag{ + &cli.StringFlag{ + Name: "rest-client-id", + Value: "", + Usage: "User/group rest driver Client ID", + EnvVars: []string{"STORAGE_REST_CLIENT_ID"}, + Destination: &cfg.Reva.UserGroupRest.ClientID, + }, + &cli.StringFlag{ + Name: "rest-client-secret", + Value: "", + Usage: "User/group rest driver Client Secret", + EnvVars: []string{"STORAGE_REST_CLIENT_SECRET"}, + Destination: &cfg.Reva.UserGroupRest.ClientSecret, + }, + &cli.StringFlag{ + Name: "rest-redis-address", + Value: "localhost:6379", + Usage: "Address for redis server", + EnvVars: []string{"STORAGE_REST_REDIS_ADDRESS"}, + Destination: &cfg.Reva.UserGroupRest.RedisAddress, + }, + &cli.StringFlag{ + Name: "rest-redis-username", + Value: "", + Usage: "Username for redis server", + EnvVars: []string{"STORAGE_REST_REDIS_USERNAME"}, + Destination: &cfg.Reva.UserGroupRest.RedisUsername, + }, + &cli.StringFlag{ + Name: "rest-redis-password", + Value: "", + Usage: "Password for redis server", + EnvVars: []string{"STORAGE_REST_REDIS_PASSWORD"}, + Destination: &cfg.Reva.UserGroupRest.RedisPassword, + }, + &cli.StringFlag{ + Name: "rest-id-provider", + Value: "", + Usage: "The OIDC Provider", + EnvVars: []string{"STORAGE_REST_ID_PROVIDER"}, + Destination: &cfg.Reva.UserGroupRest.IDProvider, + }, + &cli.StringFlag{ + Name: "rest-api-base-url", + Value: "", + Usage: "Base API Endpoint", + EnvVars: []string{"STORAGE_REST_API_BASE_URL"}, + Destination: &cfg.Reva.UserGroupRest.APIBaseURL, + }, + &cli.StringFlag{ + Name: "rest-oidc-token-endpoint", + Value: "", + Usage: "Endpoint to generate token to access the API", + EnvVars: []string{"STORAGE_REST_OIDC_TOKEN_ENDPOINT"}, + Destination: &cfg.Reva.UserGroupRest.OIDCTokenEndpoint, + }, + &cli.StringFlag{ + Name: "rest-target-api", + Value: "", + Usage: "The target application", + EnvVars: []string{"STORAGE_REST_TARGET_API"}, + Destination: &cfg.Reva.UserGroupRest.TargetAPI, + }, + } +} diff --git a/storage/pkg/flagset/sharing.go b/storage/pkg/flagset/sharing.go index f77fea73448..2926170c198 100644 --- a/storage/pkg/flagset/sharing.go +++ b/storage/pkg/flagset/sharing.go @@ -56,41 +56,6 @@ func SharingWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_SHARING_USER_JSON_FILE"}, Destination: &cfg.Reva.Sharing.UserJSONFile, }, - &cli.StringFlag{ - Name: "user-sql-username", - Value: "", - Usage: "Username to be used to connect to the SQL database", - EnvVars: []string{"STORAGE_SHARING_USER_SQL_USERNAME"}, - Destination: &cfg.Reva.Sharing.UserSQLUsername, - }, - &cli.StringFlag{ - Name: "user-sql-password", - Value: "", - Usage: "Password to be used to connect to the SQL database", - EnvVars: []string{"STORAGE_SHARING_USER_SQL_PASSWORD"}, - Destination: &cfg.Reva.Sharing.UserSQLPassword, - }, - &cli.StringFlag{ - Name: "user-sql-host", - Value: "", - Usage: "Hostname of the SQL database", - EnvVars: []string{"STORAGE_SHARING_USER_SQL_HOST"}, - Destination: &cfg.Reva.Sharing.UserSQLHost, - }, - &cli.IntFlag{ - Name: "user-sql-port", - Value: 1433, - Usage: "The port on which the SQL database is exposed", - EnvVars: []string{"STORAGE_SHARING_USER_SQL_PORT"}, - Destination: &cfg.Reva.Sharing.UserSQLPort, - }, - &cli.StringFlag{ - Name: "user-sql-name", - Value: "", - Usage: "Name of the SQL database", - EnvVars: []string{"STORAGE_SHARING_USER_SQL_Name"}, - Destination: &cfg.Reva.Sharing.UserSQLName, - }, &cli.StringFlag{ Name: "public-driver", Value: "json", @@ -110,6 +75,7 @@ func SharingWithConfig(cfg *config.Config) []cli.Flag { flags = append(flags, TracingWithConfig(cfg)...) flags = append(flags, DebugWithConfig(cfg)...) flags = append(flags, SecretWithConfig(cfg)...) + flags = append(flags, SharingSQLWithConfig(cfg)...) return flags } diff --git a/storage/pkg/flagset/sharingsql.go b/storage/pkg/flagset/sharingsql.go new file mode 100644 index 00000000000..7bbeeeabd65 --- /dev/null +++ b/storage/pkg/flagset/sharingsql.go @@ -0,0 +1,47 @@ +package flagset + +import ( + "github.com/micro/cli/v2" + "github.com/owncloud/ocis/storage/pkg/config" +) + +// SharingSQLWithConfig applies the Shring SQL driver cfg to the flagset +func SharingSQLWithConfig(cfg *config.Config) []cli.Flag { + return []cli.Flag{ + &cli.StringFlag{ + Name: "user-sql-username", + Value: "", + Usage: "Username to be used to connect to the SQL database", + EnvVars: []string{"STORAGE_SHARING_USER_SQL_USERNAME"}, + Destination: &cfg.Reva.Sharing.UserSQLUsername, + }, + &cli.StringFlag{ + Name: "user-sql-password", + Value: "", + Usage: "Password to be used to connect to the SQL database", + EnvVars: []string{"STORAGE_SHARING_USER_SQL_PASSWORD"}, + Destination: &cfg.Reva.Sharing.UserSQLPassword, + }, + &cli.StringFlag{ + Name: "user-sql-host", + Value: "", + Usage: "Hostname of the SQL database", + EnvVars: []string{"STORAGE_SHARING_USER_SQL_HOST"}, + Destination: &cfg.Reva.Sharing.UserSQLHost, + }, + &cli.IntFlag{ + Name: "user-sql-port", + Value: 1433, + Usage: "The port on which the SQL database is exposed", + EnvVars: []string{"STORAGE_SHARING_USER_SQL_PORT"}, + Destination: &cfg.Reva.Sharing.UserSQLPort, + }, + &cli.StringFlag{ + Name: "user-sql-name", + Value: "", + Usage: "Name of the SQL database", + EnvVars: []string{"STORAGE_SHARING_USER_SQL_Name"}, + Destination: &cfg.Reva.Sharing.UserSQLName, + }, + } +} diff --git a/storage/pkg/flagset/users.go b/storage/pkg/flagset/users.go index cf3fd72ab80..31120c8f990 100644 --- a/storage/pkg/flagset/users.go +++ b/storage/pkg/flagset/users.go @@ -71,78 +71,13 @@ func UsersWithConfig(cfg *config.Config) []cli.Flag { EnvVars: []string{"STORAGE_USER_CACHE_EXPIRATION"}, Destination: &cfg.Reva.Users.UserGroupsCacheExpiration, }, - - // rest driver - - &cli.StringFlag{ - Name: "rest-client-id", - Value: "", - Usage: "User/group rest driver Client ID", - EnvVars: []string{"STORAGE_REST_CLIENT_ID"}, - Destination: &cfg.Reva.UserGroupRest.ClientID, - }, - &cli.StringFlag{ - Name: "rest-client-secret", - Value: "", - Usage: "User/group rest driver Client Secret", - EnvVars: []string{"STORAGE_REST_CLIENT_SECRET"}, - Destination: &cfg.Reva.UserGroupRest.ClientSecret, - }, - &cli.StringFlag{ - Name: "rest-redis-address", - Value: "localhost:6379", - Usage: "Address for redis server", - EnvVars: []string{"STORAGE_REST_REDIS_ADDRESS"}, - Destination: &cfg.Reva.UserGroupRest.RedisAddress, - }, - &cli.StringFlag{ - Name: "rest-redis-username", - Value: "", - Usage: "Username for redis server", - EnvVars: []string{"STORAGE_REST_REDIS_USERNAME"}, - Destination: &cfg.Reva.UserGroupRest.RedisUsername, - }, - &cli.StringFlag{ - Name: "rest-redis-password", - Value: "", - Usage: "Password for redis server", - EnvVars: []string{"STORAGE_REST_REDIS_PASSWORD"}, - Destination: &cfg.Reva.UserGroupRest.RedisPassword, - }, - &cli.StringFlag{ - Name: "rest-id-provider", - Value: "", - Usage: "The OIDC Provider", - EnvVars: []string{"STORAGE_REST_ID_PROVIDER"}, - Destination: &cfg.Reva.UserGroupRest.IDProvider, - }, - &cli.StringFlag{ - Name: "rest-api-base-url", - Value: "", - Usage: "Base API Endpoint", - EnvVars: []string{"STORAGE_REST_API_BASE_URL"}, - Destination: &cfg.Reva.UserGroupRest.APIBaseURL, - }, - &cli.StringFlag{ - Name: "rest-oidc-token-endpoint", - Value: "", - Usage: "Endpoint to generate token to access the API", - EnvVars: []string{"STORAGE_REST_OIDC_TOKEN_ENDPOINT"}, - Destination: &cfg.Reva.UserGroupRest.OIDCTokenEndpoint, - }, - &cli.StringFlag{ - Name: "rest-target-api", - Value: "", - Usage: "The target application", - EnvVars: []string{"STORAGE_REST_TARGET_API"}, - Destination: &cfg.Reva.UserGroupRest.TargetAPI, - }, } flags = append(flags, TracingWithConfig(cfg)...) flags = append(flags, DebugWithConfig(cfg)...) flags = append(flags, SecretWithConfig(cfg)...) flags = append(flags, LDAPWithConfig(cfg)...) + flags = append(flags, RestWithConfig(cfg)...) return flags }