mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-01 00:10:17 -05:00
Adjust import paths and service urls in index.js
This commit is contained in:
@@ -9,9 +9,11 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v1"
|
||||
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v1"
|
||||
|
||||
revactx "github.com/cs3org/reva/pkg/ctx"
|
||||
"github.com/go-chi/chi/v5"
|
||||
accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0"
|
||||
"github.com/owncloud/ocis/ocs/pkg/service/v0/data"
|
||||
"github.com/owncloud/ocis/ocs/pkg/service/v0/response"
|
||||
ocstracing "github.com/owncloud/ocis/ocs/pkg/tracing"
|
||||
@@ -26,7 +28,7 @@ func (o Ocs) ListUserGroups(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
o.mustRender(w, r, response.ErrRender(data.MetaServerError.StatusCode, err.Error()))
|
||||
}
|
||||
var account *accounts.Account
|
||||
var account *accountsmsg.Account
|
||||
|
||||
// short circuit if there is a user already in the context
|
||||
if u, ok := revactx.ContextGetUser(r.Context()); ok {
|
||||
@@ -50,7 +52,7 @@ func (o Ocs) ListUserGroups(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if isValidUUID(userid) {
|
||||
account, err = o.getAccountService().GetAccount(r.Context(), &accounts.GetAccountRequest{
|
||||
account, err = o.getAccountService().GetAccount(r.Context(), &accountssvc.GetAccountRequest{
|
||||
Id: userid,
|
||||
})
|
||||
} else {
|
||||
@@ -73,7 +75,7 @@ func (o Ocs) ListUserGroups(w http.ResponseWriter, r *http.Request) {
|
||||
if account.MemberOf[i].OnPremisesSamAccountName == "" {
|
||||
o.logger.Warn().Str("groupid", account.MemberOf[i].Id).Msg("group on_premises_sam_account_name is empty, trying to lookup by id")
|
||||
// we can try to look up the name
|
||||
group, err := o.getGroupsService().GetGroup(r.Context(), &accounts.GetGroupRequest{
|
||||
group, err := o.getGroupsService().GetGroup(r.Context(), &accountssvc.GetGroupRequest{
|
||||
Id: account.MemberOf[i].Id,
|
||||
})
|
||||
|
||||
@@ -139,7 +141,7 @@ func (o Ocs) AddToGroup(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = o.getGroupsService().AddMember(r.Context(), &accounts.AddMemberRequest{
|
||||
_, err = o.getGroupsService().AddMember(r.Context(), &accountssvc.AddMemberRequest{
|
||||
AccountId: account.Id,
|
||||
GroupId: group.Id,
|
||||
})
|
||||
@@ -192,10 +194,10 @@ func (o Ocs) RemoveFromGroup(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var account *accounts.Account
|
||||
var account *accountsmsg.Account
|
||||
|
||||
if isValidUUID(userid) {
|
||||
account, _ = o.getAccountService().GetAccount(r.Context(), &accounts.GetAccountRequest{
|
||||
account, _ = o.getAccountService().GetAccount(r.Context(), &accountssvc.GetAccountRequest{
|
||||
Id: userid,
|
||||
})
|
||||
} else {
|
||||
@@ -225,7 +227,7 @@ func (o Ocs) RemoveFromGroup(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = o.getGroupsService().RemoveMember(r.Context(), &accounts.RemoveMemberRequest{
|
||||
_, err = o.getGroupsService().RemoveMember(r.Context(), &accountssvc.RemoveMemberRequest{
|
||||
AccountId: account.Id,
|
||||
GroupId: group.Id,
|
||||
})
|
||||
@@ -253,7 +255,7 @@ func (o Ocs) ListGroups(w http.ResponseWriter, r *http.Request) {
|
||||
query = fmt.Sprintf("id eq '%s' or on_premises_sam_account_name eq '%s'", escapeValue(search), escapeValue(search))
|
||||
}
|
||||
|
||||
res, err := o.getGroupsService().ListGroups(r.Context(), &accounts.ListGroupsRequest{
|
||||
res, err := o.getGroupsService().ListGroups(r.Context(), &accountssvc.ListGroupsRequest{
|
||||
Query: query,
|
||||
})
|
||||
|
||||
@@ -312,13 +314,13 @@ func (o Ocs) AddGroup(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
newGroup := &accounts.Group{
|
||||
newGroup := &accountsmsg.Group{
|
||||
Id: groupid,
|
||||
DisplayName: displayname,
|
||||
OnPremisesSamAccountName: groupid,
|
||||
GidNumber: gidNumber,
|
||||
}
|
||||
group, err := o.getGroupsService().CreateGroup(r.Context(), &accounts.CreateGroupRequest{
|
||||
group, err := o.getGroupsService().CreateGroup(r.Context(), &accountssvc.CreateGroupRequest{
|
||||
Group: newGroup,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -366,7 +368,7 @@ func (o Ocs) DeleteGroup(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = o.getGroupsService().DeleteGroup(r.Context(), &accounts.DeleteGroupRequest{
|
||||
_, err = o.getGroupsService().DeleteGroup(r.Context(), &accountssvc.DeleteGroupRequest{
|
||||
Id: group.Id,
|
||||
})
|
||||
|
||||
@@ -406,7 +408,7 @@ func (o Ocs) GetGroupMembers(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
res, err := o.getGroupsService().ListMembers(r.Context(), &accounts.ListMembersRequest{Id: group.Id})
|
||||
res, err := o.getGroupsService().ListMembers(r.Context(), &accountssvc.ListMembersRequest{Id: group.Id})
|
||||
|
||||
if err != nil {
|
||||
merr := merrors.FromError(err)
|
||||
@@ -433,9 +435,9 @@ func isValidUUID(uuid string) bool {
|
||||
return r.MatchString(uuid)
|
||||
}
|
||||
|
||||
func (o Ocs) fetchGroupByName(ctx context.Context, name string) (*accounts.Group, error) {
|
||||
var res *accounts.ListGroupsResponse
|
||||
res, err := o.getGroupsService().ListGroups(ctx, &accounts.ListGroupsRequest{
|
||||
func (o Ocs) fetchGroupByName(ctx context.Context, name string) (*accountsmsg.Group, error) {
|
||||
var res *accountssvc.ListGroupsResponse
|
||||
res, err := o.getGroupsService().ListGroups(ctx, &accountssvc.ListGroupsRequest{
|
||||
Query: fmt.Sprintf("on_premises_sam_account_name eq '%v'", escapeValue(name)),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -11,7 +11,8 @@ import (
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/go-chi/render"
|
||||
|
||||
accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0"
|
||||
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v1"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/account"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
opkgm "github.com/owncloud/ocis/ocis-pkg/middleware"
|
||||
@@ -158,8 +159,8 @@ func (o Ocs) NotFound(w http.ResponseWriter, r *http.Request) {
|
||||
o.mustRender(w, r, response.ErrRender(data.MetaNotFound.StatusCode, "not found"))
|
||||
}
|
||||
|
||||
func (o Ocs) getAccountService() accounts.AccountsService {
|
||||
return accounts.NewAccountsService("com.owncloud.api.accounts", grpc.DefaultClient)
|
||||
func (o Ocs) getAccountService() accountssvc.AccountsService {
|
||||
return accountssvc.NewAccountsService("com.owncloud.api.accounts", grpc.DefaultClient)
|
||||
}
|
||||
|
||||
func (o Ocs) getCS3Backend() backend.UserBackend {
|
||||
@@ -170,8 +171,8 @@ func (o Ocs) getCS3Backend() backend.UserBackend {
|
||||
return backend.NewCS3UserBackend(nil, revaClient, o.config.MachineAuthAPIKey, o.logger)
|
||||
}
|
||||
|
||||
func (o Ocs) getGroupsService() accounts.GroupsService {
|
||||
return accounts.NewGroupsService("com.owncloud.api.accounts", grpc.DefaultClient)
|
||||
func (o Ocs) getGroupsService() accountssvc.GroupsService {
|
||||
return accountssvc.NewGroupsService("com.owncloud.api.accounts", grpc.DefaultClient)
|
||||
}
|
||||
|
||||
// NotImplementedStub returns a not implemented error
|
||||
|
||||
+28
-26
@@ -10,6 +10,9 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
accountsmsg "github.com/owncloud/ocis/protogen/gen/ocis/messages/accounts/v1"
|
||||
accountssvc "github.com/owncloud/ocis/protogen/gen/ocis/services/accounts/v1"
|
||||
|
||||
"github.com/asim/go-micro/plugins/client/grpc/v4"
|
||||
revauser "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
@@ -21,7 +24,6 @@ import (
|
||||
"github.com/cs3org/reva/pkg/token/manager/jwt"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/google/uuid"
|
||||
accounts "github.com/owncloud/ocis/accounts/pkg/proto/v0"
|
||||
"github.com/owncloud/ocis/ocs/pkg/service/v0/data"
|
||||
"github.com/owncloud/ocis/ocs/pkg/service/v0/response"
|
||||
ocstracing "github.com/owncloud/ocis/ocs/pkg/tracing"
|
||||
@@ -35,7 +37,7 @@ import (
|
||||
|
||||
// GetSelf returns the currently logged in user
|
||||
func (o Ocs) GetSelf(w http.ResponseWriter, r *http.Request) {
|
||||
var account *accounts.Account
|
||||
var account *accountsmsg.Account
|
||||
var err error
|
||||
u, ok := revactx.ContextGetUser(r.Context())
|
||||
if !ok || u.Id == nil || u.Id.OpaqueId == "" {
|
||||
@@ -43,7 +45,7 @@ func (o Ocs) GetSelf(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
account, err = o.getAccountService().GetAccount(r.Context(), &accounts.GetAccountRequest{
|
||||
account, err = o.getAccountService().GetAccount(r.Context(), &accountssvc.GetAccountRequest{
|
||||
Id: u.Id.OpaqueId,
|
||||
})
|
||||
|
||||
@@ -92,7 +94,7 @@ func (o Ocs) GetUser(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
o.mustRender(w, r, response.ErrRender(data.MetaServerError.StatusCode, err.Error()))
|
||||
}
|
||||
var account *accounts.Account
|
||||
var account *accountsmsg.Account
|
||||
|
||||
switch {
|
||||
case userid == "":
|
||||
@@ -198,12 +200,12 @@ func (o Ocs) AddUser(w http.ResponseWriter, r *http.Request) {
|
||||
displayname = userid
|
||||
}
|
||||
|
||||
newAccount := &accounts.Account{
|
||||
newAccount := &accountsmsg.Account{
|
||||
Id: uuid.New().String(),
|
||||
DisplayName: displayname,
|
||||
PreferredName: userid,
|
||||
OnPremisesSamAccountName: userid,
|
||||
PasswordProfile: &accounts.PasswordProfile{
|
||||
PasswordProfile: &accountsmsg.PasswordProfile{
|
||||
Password: password,
|
||||
},
|
||||
Mail: email,
|
||||
@@ -218,11 +220,11 @@ func (o Ocs) AddUser(w http.ResponseWriter, r *http.Request) {
|
||||
newAccount.GidNumber = gidNumber
|
||||
}
|
||||
|
||||
var account *accounts.Account
|
||||
var account *accountsmsg.Account
|
||||
|
||||
switch o.config.AccountBackend {
|
||||
case "accounts":
|
||||
account, err = o.getAccountService().CreateAccount(r.Context(), &accounts.CreateAccountRequest{
|
||||
account, err = o.getAccountService().CreateAccount(r.Context(), &accountssvc.CreateAccountRequest{
|
||||
Account: newAccount,
|
||||
})
|
||||
case "cs3":
|
||||
@@ -284,7 +286,7 @@ func (o Ocs) EditUser(w http.ResponseWriter, r *http.Request) {
|
||||
o.mustRender(w, r, response.ErrRender(data.MetaServerError.StatusCode, err.Error()))
|
||||
}
|
||||
|
||||
var account *accounts.Account
|
||||
var account *accountsmsg.Account
|
||||
switch o.config.AccountBackend {
|
||||
case "accounts":
|
||||
account, err = o.fetchAccountByUsername(r.Context(), userid)
|
||||
@@ -305,8 +307,8 @@ func (o Ocs) EditUser(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
req := accounts.UpdateAccountRequest{
|
||||
Account: &accounts.Account{
|
||||
req := accountssvc.UpdateAccountRequest{
|
||||
Account: &accountsmsg.Account{
|
||||
Id: account.Id,
|
||||
},
|
||||
}
|
||||
@@ -322,7 +324,7 @@ func (o Ocs) EditUser(w http.ResponseWriter, r *http.Request) {
|
||||
req.Account.OnPremisesSamAccountName = value
|
||||
req.UpdateMask = &fieldmaskpb.FieldMask{Paths: []string{"PreferredName", "OnPremisesSamAccountName"}}
|
||||
case "password":
|
||||
req.Account.PasswordProfile = &accounts.PasswordProfile{
|
||||
req.Account.PasswordProfile = &accountsmsg.PasswordProfile{
|
||||
Password: value,
|
||||
}
|
||||
req.UpdateMask = &fieldmaskpb.FieldMask{Paths: []string{"PasswordProfile.Password"}}
|
||||
@@ -365,7 +367,7 @@ func (o Ocs) DeleteUser(w http.ResponseWriter, r *http.Request) {
|
||||
o.mustRender(w, r, response.ErrRender(data.MetaServerError.StatusCode, err.Error()))
|
||||
}
|
||||
|
||||
var account *accounts.Account
|
||||
var account *accountsmsg.Account
|
||||
switch o.config.AccountBackend {
|
||||
case "accounts":
|
||||
account, err = o.fetchAccountByUsername(r.Context(), userid)
|
||||
@@ -486,7 +488,7 @@ func (o Ocs) DeleteUser(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
req := accounts.DeleteAccountRequest{
|
||||
req := accountssvc.DeleteAccountRequest{
|
||||
Id: account.Id,
|
||||
}
|
||||
|
||||
@@ -507,7 +509,7 @@ func (o Ocs) DeleteUser(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// TODO(refs) this to ocis-pkg ... we are minting tokens all over the place ... or use a service? ... like reva?
|
||||
func (o Ocs) mintTokenForUser(ctx context.Context, account *accounts.Account) (string, error) {
|
||||
func (o Ocs) mintTokenForUser(ctx context.Context, account *accountsmsg.Account) (string, error) {
|
||||
tm, _ := jwt.New(map[string]interface{}{
|
||||
"secret": o.config.TokenManager.JWTSecret,
|
||||
"expires": int64(24 * 60 * 60),
|
||||
@@ -537,7 +539,7 @@ func (o Ocs) EnableUser(w http.ResponseWriter, r *http.Request) {
|
||||
o.mustRender(w, r, response.ErrRender(data.MetaServerError.StatusCode, err.Error()))
|
||||
}
|
||||
|
||||
var account *accounts.Account
|
||||
var account *accountsmsg.Account
|
||||
switch o.config.AccountBackend {
|
||||
case "accounts":
|
||||
account, err = o.fetchAccountByUsername(r.Context(), userid)
|
||||
@@ -560,7 +562,7 @@ func (o Ocs) EnableUser(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
account.AccountEnabled = true
|
||||
|
||||
req := accounts.UpdateAccountRequest{
|
||||
req := accountssvc.UpdateAccountRequest{
|
||||
Account: account,
|
||||
UpdateMask: &field_mask.FieldMask{
|
||||
Paths: []string{"AccountEnabled"},
|
||||
@@ -591,7 +593,7 @@ func (o Ocs) DisableUser(w http.ResponseWriter, r *http.Request) {
|
||||
o.mustRender(w, r, response.ErrRender(data.MetaServerError.StatusCode, err.Error()))
|
||||
}
|
||||
|
||||
var account *accounts.Account
|
||||
var account *accountsmsg.Account
|
||||
switch o.config.AccountBackend {
|
||||
case "accounts":
|
||||
account, err = o.fetchAccountByUsername(r.Context(), userid)
|
||||
@@ -614,7 +616,7 @@ func (o Ocs) DisableUser(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
account.AccountEnabled = false
|
||||
|
||||
req := accounts.UpdateAccountRequest{
|
||||
req := accountssvc.UpdateAccountRequest{
|
||||
Account: account,
|
||||
UpdateMask: &field_mask.FieldMask{
|
||||
Paths: []string{"AccountEnabled"},
|
||||
@@ -717,11 +719,11 @@ func (o Ocs) ListUsers(w http.ResponseWriter, r *http.Request) {
|
||||
query = fmt.Sprintf("on_premises_sam_account_name eq '%s'", escapeValue(search))
|
||||
}
|
||||
|
||||
var res *accounts.ListAccountsResponse
|
||||
var res *accountssvc.ListAccountsResponse
|
||||
var err error
|
||||
switch o.config.AccountBackend {
|
||||
case "accounts":
|
||||
res, err = o.getAccountService().ListAccounts(r.Context(), &accounts.ListAccountsRequest{
|
||||
res, err = o.getAccountService().ListAccounts(r.Context(), &accountssvc.ListAccountsRequest{
|
||||
Query: query,
|
||||
})
|
||||
case "cs3":
|
||||
@@ -750,9 +752,9 @@ func escapeValue(value string) string {
|
||||
return strings.ReplaceAll(value, "'", "''")
|
||||
}
|
||||
|
||||
func (o Ocs) fetchAccountByUsername(ctx context.Context, name string) (*accounts.Account, error) {
|
||||
var res *accounts.ListAccountsResponse
|
||||
res, err := o.getAccountService().ListAccounts(ctx, &accounts.ListAccountsRequest{
|
||||
func (o Ocs) fetchAccountByUsername(ctx context.Context, name string) (*accountsmsg.Account, error) {
|
||||
var res *accountssvc.ListAccountsResponse
|
||||
res, err := o.getAccountService().ListAccounts(ctx, &accountssvc.ListAccountsRequest{
|
||||
Query: fmt.Sprintf("on_premises_sam_account_name eq '%v'", escapeValue(name)),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -764,13 +766,13 @@ func (o Ocs) fetchAccountByUsername(ctx context.Context, name string) (*accounts
|
||||
return nil, merrors.NotFound("", data.MessageUserNotFound)
|
||||
}
|
||||
|
||||
func (o Ocs) fetchAccountFromCS3Backend(ctx context.Context, name string) (*accounts.Account, error) {
|
||||
func (o Ocs) fetchAccountFromCS3Backend(ctx context.Context, name string) (*accountsmsg.Account, error) {
|
||||
backend := o.getCS3Backend()
|
||||
u, _, err := backend.GetUserByClaims(ctx, "username", name, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &accounts.Account{
|
||||
return &accountsmsg.Account{
|
||||
OnPremisesSamAccountName: u.Username,
|
||||
DisplayName: u.DisplayName,
|
||||
Mail: u.Mail,
|
||||
|
||||
Reference in New Issue
Block a user