Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
17f1ebaf
Commit
17f1ebaf
authored
2 years ago
by
Alena Petraki
Browse files
Options
Downloads
Patches
Plain Diff
Revert лишних изменений
parent
52813347
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pkg/auth/client.go
+2
-2
2 additions, 2 deletions
pkg/auth/client.go
pkg/auth/principal.go
+39
-39
39 additions, 39 deletions
pkg/auth/principal.go
pkg/auth/user.go
+2
-3
2 additions, 3 deletions
pkg/auth/user.go
with
43 additions
and
44 deletions
pkg/auth/client.go
+
2
−
2
View file @
17f1ebaf
...
...
@@ -143,7 +143,7 @@ func (c *ClientPrincipal) Client(ctx context.Context) (*clients.Client, error) {
}
func
(
c
*
ClientPrincipal
)
HasEnvironmentAccess
(
ctx
context
.
Context
,
spaceID
,
envID
string
)
bool
{
return
c
.
Role
(
ctx
,
spaceID
)
.
CanAcces
sEnvironment
(
WithSystem
(
ctx
)
,
c
.
environments
,
spaceID
,
envID
)
return
ha
sEnvironment
Access
(
ctx
,
c
.
environments
,
c
.
Role
(
ctx
,
spaceID
)
,
envID
)
}
func
(
c
*
ClientPrincipal
)
getRoleID
(
ctx
context
.
Context
,
spaceID
string
)
(
string
,
bool
)
{
...
...
@@ -203,7 +203,7 @@ func (c *ClientPrincipal) Rules(ctx context.Context, spaceID, envID string) perm
return
permission
.
PrivilegedRuleset
{}
}
if
role
.
CanAcces
sEnvironment
(
WithSystem
(
ctx
)
,
c
.
environments
,
spaceID
,
envID
)
{
if
ha
sEnvironment
Access
(
ctx
,
c
.
environments
,
role
,
envID
)
{
return
role
.
Rules
}
return
nil
...
...
This diff is collapsed.
Click to expand it.
pkg/auth/principal.go
+
39
−
39
View file @
17f1ebaf
...
...
@@ -45,42 +45,42 @@ type OrganizationAccessor interface {
Member
(
ctx
context
.
Context
)
members
.
Role
}
//
func hasEnvironmentAccess(ctx context.Context, envsrv environments.Environments, role *roles.Role, envID string) bool {
//
if role == nil || role.SpaceID == "" || envID == "" {
//
return false
//
}
//
//
if role.AllowManagement {
//
return true
//
}
//
//
envs := role.Environments
//
//
// Если явно не указаны доступные окружения - доступ по умолчанию к окружению master
//
if len(envs) == 0 {
//
envs = []string{environments.DefaultEnvironment}
//
}
//
//
for _, ce := range envs {
//
if envID == ce || util.GlobMatch(envID, ce) {
//
return true
//
}
//
}
//
//
e, err := envsrv.Get(WithSystem(ctx), role.SpaceID, envID)
//
if err != nil || e == nil {
//
return false
//
}
//
//
aliases := append(e.Aliases, e.ID)
//
//
for _, ce := range envs {
//
for _, al := range aliases {
//
if al == ce || util.GlobMatch(al, ce) {
//
return true
//
}
//
}
//
}
//
//
return false
//
}
func
hasEnvironmentAccess
(
ctx
context
.
Context
,
envsrv
environments
.
Environments
,
role
*
roles
.
Role
,
envID
string
)
bool
{
if
role
==
nil
||
role
.
SpaceID
==
""
||
envID
==
""
{
return
false
}
if
role
.
AllowManagement
{
return
true
}
envs
:=
role
.
Environments
// Если явно не указаны доступные окружения - доступ по умолчанию к окружению master
if
len
(
envs
)
==
0
{
envs
=
[]
string
{
environments
.
DefaultEnvironment
}
}
for
_
,
ce
:=
range
envs
{
if
envID
==
ce
||
util
.
GlobMatch
(
envID
,
ce
)
{
return
true
}
}
e
,
err
:=
envsrv
.
Get
(
WithSystem
(
ctx
),
role
.
SpaceID
,
envID
)
if
err
!=
nil
||
e
==
nil
{
return
false
}
aliases
:=
append
(
e
.
Aliases
,
e
.
ID
)
for
_
,
ce
:=
range
envs
{
for
_
,
al
:=
range
aliases
{
if
al
==
ce
||
util
.
GlobMatch
(
al
,
ce
)
{
return
true
}
}
}
return
false
}
This diff is collapsed.
Click to expand it.
pkg/auth/user.go
+
2
−
3
View file @
17f1ebaf
...
...
@@ -12,7 +12,6 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/roles"
"git.perx.ru/perxis/perxis-go/pkg/spaces"
"git.perx.ru/perxis/perxis-go/pkg/users"
"git.perx.ru/perxis/perxis/services"
)
type
UserPrincipal
struct
{
...
...
@@ -306,7 +305,7 @@ func (u *UserPrincipal) Rules(ctx context.Context, spaceID, envID string) permis
return
nil
}
if
!
role
.
CanAcces
sEnvironment
(
WithSystem
(
ctx
)
,
u
.
environments
,
spaceID
,
envID
)
{
if
!
ha
sEnvironment
Access
(
ctx
,
u
.
environments
,
role
,
envID
)
{
return
nil
}
...
...
@@ -331,5 +330,5 @@ func User(ctx context.Context, p Principal) *users.User {
}
func
(
u
*
UserPrincipal
)
HasEnvironmentAccess
(
ctx
context
.
Context
,
spaceID
,
env
string
)
bool
{
return
u
.
Role
(
ctx
,
spaceID
)
.
CanAcces
sEnvironment
(
WithSystem
(
ctx
)
,
u
.
environments
,
spaceID
,
env
)
return
ha
sEnvironment
Access
(
ctx
,
u
.
environments
,
u
.
Role
(
ctx
,
spaceID
)
,
env
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment