Initial QSfera import
This commit is contained in:
+121
@@ -0,0 +1,121 @@
|
||||
// Copyright 2018-2021 CERN
|
||||
// Copyright 2026 OpenCloud GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// In applying this license, CERN does not waive the privileges and immunities
|
||||
// granted to it by virtue of its status as an Intergovernmental Organization
|
||||
// or submit itself to any jurisdiction.
|
||||
|
||||
package ldap
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
tenantpb "github.com/cs3org/go-cs3apis/cs3/identity/tenant/v1beta1"
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/appctx"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/tenant"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/tenant/manager/registry"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/utils"
|
||||
ldapIdentity "github.com/opencloud-eu/reva/v2/pkg/utils/ldap"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register("ldap", New)
|
||||
}
|
||||
|
||||
type config struct {
|
||||
utils.LDAPConn `mapstructure:",squash"`
|
||||
LDAPIdentity ldapIdentity.Identity `mapstructure:",squash"`
|
||||
}
|
||||
|
||||
func parseConfig(m map[string]interface{}) (*config, error) {
|
||||
c := &config{
|
||||
LDAPIdentity: ldapIdentity.New(),
|
||||
}
|
||||
if err := mapstructure.Decode(m, c); err != nil {
|
||||
err = errors.Wrap(err, "error decoding conf")
|
||||
return nil, err
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
type manager struct {
|
||||
conf *config
|
||||
ldap ldap.Client
|
||||
}
|
||||
|
||||
// New returns a new user manager.
|
||||
func New(m map[string]interface{}) (tenant.Manager, error) {
|
||||
mgr := &manager{}
|
||||
err := mgr.Configure(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mgr.ldap, err = utils.GetLDAPClientWithReconnect(&mgr.conf.LDAPConn)
|
||||
|
||||
return mgr, err
|
||||
}
|
||||
|
||||
func (m *manager) Configure(ml map[string]interface{}) error {
|
||||
c, err := parseConfig(ml)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = c.LDAPIdentity.Setup(); err != nil {
|
||||
return fmt.Errorf("error setting up Identity config: %w", err)
|
||||
}
|
||||
m.conf = c
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *manager) GetTenant(ctx context.Context, id string) (*tenantpb.Tenant, error) {
|
||||
log := appctx.GetLogger(ctx)
|
||||
|
||||
tenantEntry, err := m.conf.LDAPIdentity.GetLDAPTenantByID(ctx, m.ldap, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debug().Interface("entry", tenantEntry).Msg("entries")
|
||||
|
||||
t, err := m.ldapEntryToTenant(tenantEntry)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (m *manager) GetTenantByClaim(ctx context.Context, claim, value string) (*tenantpb.Tenant, error) {
|
||||
tenantEntry, err := m.conf.LDAPIdentity.GetLDAPTenantByAttribute(ctx, m.ldap, claim, value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m.ldapEntryToTenant(tenantEntry)
|
||||
}
|
||||
|
||||
func (m *manager) ldapEntryToTenant(entry *ldap.Entry) (*tenantpb.Tenant, error) {
|
||||
t := &tenantpb.Tenant{
|
||||
Id: entry.GetEqualFoldAttributeValue(m.conf.LDAPIdentity.Tenant.Schema.ID),
|
||||
ExternalId: entry.GetEqualFoldAttributeValue(m.conf.LDAPIdentity.Tenant.Schema.ExternalID),
|
||||
Name: entry.GetEqualFoldAttributeValue(m.conf.LDAPIdentity.Tenant.Schema.Name),
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
Generated
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
// Copyright 2018-2021 CERN
|
||||
// Copyright 2026 OpenCloud GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// In applying this license, CERN does not waive the privileges and immunities
|
||||
// granted to it by virtue of its status as an Intergovernmental Organization
|
||||
// or submit itself to any jurisdiction.
|
||||
|
||||
package loader
|
||||
|
||||
import (
|
||||
// Load core user manager drivers.
|
||||
_ "github.com/opencloud-eu/reva/v2/pkg/tenant/manager/ldap"
|
||||
_ "github.com/opencloud-eu/reva/v2/pkg/tenant/manager/memory"
|
||||
_ "github.com/opencloud-eu/reva/v2/pkg/tenant/manager/null"
|
||||
// Add your own here
|
||||
)
|
||||
Generated
Vendored
+106
@@ -0,0 +1,106 @@
|
||||
// Copyright 2018-2021 CERN
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// In applying this license, CERN does not waive the privileges and immunities
|
||||
// granted to it by virtue of its status as an Intergovernmental Organization
|
||||
// or submit itself to any jurisdiction.
|
||||
|
||||
package memory
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
tenantpb "github.com/cs3org/go-cs3apis/cs3/identity/tenant/v1beta1"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/errtypes"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/tenant"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/tenant/manager/registry"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register("memory", New)
|
||||
}
|
||||
|
||||
// tenantEntry is used only for mapstructure decoding of the config.
|
||||
type tenantEntry struct {
|
||||
ID string `mapstructure:"id"`
|
||||
ExternalID string `mapstructure:"external_id"`
|
||||
Name string `mapstructure:"name"`
|
||||
}
|
||||
|
||||
type config struct {
|
||||
Tenants map[string]*tenantEntry `mapstructure:"tenants"`
|
||||
}
|
||||
|
||||
func parseConfig(m map[string]interface{}) (*config, error) {
|
||||
c := &config{}
|
||||
if err := mapstructure.Decode(m, c); err != nil {
|
||||
return nil, errors.Wrap(err, "error decoding conf")
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
type manager struct {
|
||||
catalog map[string]*tenantpb.Tenant
|
||||
}
|
||||
|
||||
// New returns a new tenant manager.
|
||||
func New(m map[string]interface{}) (tenant.Manager, error) {
|
||||
mgr := &manager{}
|
||||
err := mgr.Configure(m)
|
||||
return mgr, err
|
||||
}
|
||||
|
||||
func (m *manager) Configure(ml map[string]interface{}) error {
|
||||
c, err := parseConfig(ml)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.catalog = make(map[string]*tenantpb.Tenant, len(c.Tenants))
|
||||
for k, t := range c.Tenants {
|
||||
m.catalog[k] = &tenantpb.Tenant{
|
||||
Id: t.ID,
|
||||
ExternalId: t.ExternalID,
|
||||
Name: t.Name,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *manager) GetTenant(ctx context.Context, id string) (*tenantpb.Tenant, error) {
|
||||
if t, ok := m.catalog[id]; ok {
|
||||
return t, nil
|
||||
}
|
||||
return nil, errtypes.NotFound(id)
|
||||
}
|
||||
|
||||
func (m *manager) GetTenantByClaim(ctx context.Context, claim, value string) (*tenantpb.Tenant, error) {
|
||||
for _, t := range m.catalog {
|
||||
if tenantClaim, err := extractClaim(t, claim); err == nil && value == tenantClaim {
|
||||
return t, nil
|
||||
}
|
||||
}
|
||||
return nil, errtypes.NotFound(value)
|
||||
}
|
||||
|
||||
func extractClaim(t *tenantpb.Tenant, claim string) (string, error) {
|
||||
switch claim {
|
||||
case "id":
|
||||
return t.Id, nil
|
||||
case "externalid":
|
||||
return t.ExternalId, nil
|
||||
}
|
||||
return "", errors.New("memory: invalid claim")
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
// Copyright 2018-2020 CERN
|
||||
// Copyright 2026 OpenCloud GmbH
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// In applying this license, CERN does not waive the privileges and immunities
|
||||
// granted to it by virtue of its status as an Intergovernmental Organization
|
||||
// or submit itself to any jurisdiction.
|
||||
|
||||
package null
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
tenantpb "github.com/cs3org/go-cs3apis/cs3/identity/tenant/v1beta1"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/errtypes"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/tenant"
|
||||
"github.com/opencloud-eu/reva/v2/pkg/tenant/manager/registry"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register("null", New)
|
||||
}
|
||||
|
||||
type manager struct {
|
||||
}
|
||||
|
||||
// New returns a tenant manager implementation that return NOT FOUND or empty result set for every call
|
||||
func New(m map[string]interface{}) (tenant.Manager, error) {
|
||||
return &manager{}, nil
|
||||
}
|
||||
|
||||
func (m *manager) GetTenant(ctx context.Context, id string) (*tenantpb.Tenant, error) {
|
||||
return nil, errtypes.NotFound(id)
|
||||
}
|
||||
|
||||
func (m *manager) GetTenantByClaim(ctx context.Context, claim, value string) (*tenantpb.Tenant, error) {
|
||||
return nil, errtypes.NotFound(value)
|
||||
}
|
||||
Generated
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
// Copyright 2018-2021 CERN
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// In applying this license, CERN does not waive the privileges and immunities
|
||||
// granted to it by virtue of its status as an Intergovernmental Organization
|
||||
// or submit itself to any jurisdiction.
|
||||
|
||||
package registry
|
||||
|
||||
import (
|
||||
"github.com/opencloud-eu/reva/v2/pkg/tenant"
|
||||
)
|
||||
|
||||
// NewFunc is the function that tenant managers
|
||||
// should register at init time.
|
||||
type NewFunc func(map[string]interface{}) (tenant.Manager, error)
|
||||
|
||||
// NewFuncs is a map containing all the registered user managers.
|
||||
var NewFuncs = map[string]NewFunc{}
|
||||
|
||||
// Register registers a new user manager new function.
|
||||
// Not safe for concurrent use. Safe for use from package init.
|
||||
func Register(name string, f NewFunc) {
|
||||
NewFuncs[name] = f
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// Copyright 2018-2021 CERN
|
||||
// Copyright 2026 OpenCloud
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// In applying this license, CERN does not waive the privileges and immunities
|
||||
// granted to it by virtue of its status as an Intergovernmental Organization
|
||||
// or submit itself to any jurisdiction.
|
||||
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
tenant "github.com/cs3org/go-cs3apis/cs3/identity/tenant/v1beta1"
|
||||
)
|
||||
|
||||
// Manager is the interface to implement to manipulate users.
|
||||
type Manager interface {
|
||||
// GetTenant returns the tenant metadata identified by an id.
|
||||
GetTenant(ctx context.Context, id string) (*tenant.Tenant, error)
|
||||
// GetUserByClaim returns the user identified by a specific value for a given claim.
|
||||
GetTenantByClaim(ctx context.Context, claim, value string) (*tenant.Tenant, error)
|
||||
}
|
||||
Reference in New Issue
Block a user