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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
d734f1eb
Commit
d734f1eb
authored
2 years ago
by
Alena Petraki
Browse files
Options
Downloads
Patches
Plain Diff
Объект роли вынесен в отдельный файл
parent
626af5bb
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/roles/role.go
+65
-0
65 additions, 0 deletions
pkg/roles/role.go
pkg/roles/service.go
+0
-60
0 additions, 60 deletions
pkg/roles/service.go
with
65 additions
and
60 deletions
pkg/roles/role.go
0 → 100644
+
65
−
0
View file @
d734f1eb
package
roles
import
(
"context"
"git.perx.ru/perxis/perxis-go/pkg/data"
"git.perx.ru/perxis/perxis-go/pkg/environments"
"git.perx.ru/perxis/perxis-go/pkg/permission"
)
const
(
AnonymousRole
=
"anonymous"
AuthorizedRole
=
"authorized"
ViewRole
=
"view"
)
type
Role
struct
{
// Внутренний идентификатор роли
ID
string
`json:"id" bson:"_id"`
// Идентификатор пространства
SpaceID
string
`json:"spaceId" bson:"-"`
// Описание роли, назначение
Description
string
`json:"description" bson:"description"`
// Список доступных окружений (ID или Alias)
Environments
[]
string
`json:"environments" bson:"environments"`
// Список правил доступа к коллекциям
Rules
permission
.
Rules
`json:"rules" bson:"rules"`
// Разрешить доступ API управления
AllowManagement
bool
`json:"allow_management" bson:"allow_management"`
}
func
(
r
Role
)
CanAccessEnvironment
(
ctx
context
.
Context
,
service
environments
.
Environments
,
spaceID
,
envID
string
)
bool
{
if
spaceID
==
""
||
envID
==
""
{
return
false
}
// Если явно не указаны доступные окружения - доступ по умолчанию к окружению master
if
len
(
r
.
Environments
)
==
0
{
r
.
Environments
=
[]
string
{
environments
.
DefaultEnvironment
}
}
if
data
.
Contains
(
envID
,
r
.
Environments
)
{
return
true
}
e
,
err
:=
service
.
Get
(
ctx
,
spaceID
,
envID
)
if
err
!=
nil
||
e
==
nil
{
return
false
}
aliases
:=
append
(
e
.
Aliases
,
e
.
ID
)
for
_
,
ce
:=
range
r
.
Environments
{
if
data
.
Contains
(
ce
,
aliases
)
{
return
true
}
}
return
false
}
This diff is collapsed.
Click to expand it.
pkg/roles/service.go
+
0
−
60
View file @
d734f1eb
...
@@ -2,38 +2,8 @@ package roles
...
@@ -2,38 +2,8 @@ package roles
import
(
import
(
"context"
"context"
"git.perx.ru/perxis/perxis-go/pkg/data"
"git.perx.ru/perxis/perxis-go/pkg/environments"
"git.perx.ru/perxis/perxis-go/pkg/permission"
)
const
(
AnonymousRole
=
"anonymous"
AuthorizedRole
=
"authorized"
ViewRole
=
"view"
)
)
type
Role
struct
{
// Внутренний идентификатор роли
ID
string
`json:"id" bson:"_id"`
// Идентификатор пространства
SpaceID
string
`json:"spaceId" bson:"-"`
// Описание роли, назначение
Description
string
`json:"description" bson:"description"`
// Список доступных окружений (ID или Alias)
Environments
[]
string
`json:"environments" bson:"environments"`
// Список правил доступа к коллекциям
Rules
permission
.
Rules
`json:"rules" bson:"rules"`
// Разрешить доступ API управления
AllowManagement
bool
`json:"allow_management" bson:"allow_management"`
}
// @microgen grpc
// @microgen grpc
// @protobuf git.perx.ru/perxis/perxis-go/proto/roles
// @protobuf git.perx.ru/perxis/perxis-go/proto/roles
// @grpc-addr content.roles.Roles
// @grpc-addr content.roles.Roles
...
@@ -44,33 +14,3 @@ type Roles interface {
...
@@ -44,33 +14,3 @@ type Roles interface {
Update
(
ctx
context
.
Context
,
role
*
Role
)
(
err
error
)
Update
(
ctx
context
.
Context
,
role
*
Role
)
(
err
error
)
Delete
(
ctx
context
.
Context
,
spaceId
,
roleId
string
)
(
err
error
)
Delete
(
ctx
context
.
Context
,
spaceId
,
roleId
string
)
(
err
error
)
}
}
func
(
r
Role
)
CanAccessEnvironment
(
ctx
context
.
Context
,
service
environments
.
Environments
,
spaceID
,
envID
string
)
bool
{
if
spaceID
==
""
||
envID
==
""
{
return
false
}
// Если явно не указаны доступные окружения - доступ по умолчанию к окружению master
if
len
(
r
.
Environments
)
==
0
{
r
.
Environments
=
[]
string
{
environments
.
DefaultEnvironment
}
}
if
data
.
Contains
(
envID
,
r
.
Environments
)
{
return
true
}
e
,
err
:=
service
.
Get
(
ctx
,
spaceID
,
envID
)
if
err
!=
nil
||
e
==
nil
{
return
false
}
aliases
:=
append
(
e
.
Aliases
,
e
.
ID
)
for
_
,
ce
:=
range
r
.
Environments
{
if
data
.
Contains
(
ce
,
aliases
)
{
return
true
}
}
return
false
}
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