-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Terminal access for trigger roles (#1128)
* wip * wip - added method for updating terminal access policy for old users * added default policy update method, fixed ci trigger bug, added api for terminal access update * wip * fixed sql query * fixed sql script * fixed sql script - default auth role * updated auth for trigger ci api * wip - ci trigger bug fix * reverted ci trigger changes * wip * wip - rbac for terminal access removed * fixed policy json error * wip - added rbac back for update terminal access and ci trigger apis * ci trigger fix + update policy api fix * wip * fixed casbin policy update input * fix sql query for getting roles * wip * wip * wip * added own KeyMatch func * updated keyMatch func * formatted code * fixed condition * review changes * updated conf file for rbac matcher func update * updated key match func * updated trigger policy for terminal object * review changes * added rbac in terminal api for charts
- Loading branch information
1 parent
7a4e7ee
commit f799aa4
Showing
18 changed files
with
1,119 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package repository | ||
|
||
import ( | ||
"github.com/devtron-labs/devtron/pkg/sql" | ||
"github.com/go-pg/pg" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type RoleType string | ||
|
||
const ( | ||
MANAGER_TYPE RoleType = "manager" | ||
ADMIN_TYPE RoleType = "admin" | ||
TRIGGER_TYPE RoleType = "trigger" | ||
VIEW_TYPE RoleType = "view" | ||
ENTITY_ALL_TYPE RoleType = "entityAll" | ||
ENTITY_VIEW_TYPE RoleType = "entityView" | ||
ENTITY_SPECIFIC_TYPE RoleType = "entitySpecific" | ||
ENTITY_SPECIFIC_ADMIN_TYPE RoleType = "entitySpecificAdmin" | ||
ENTITY_SPECIFIC_VIEW_TYPE RoleType = "entitySpecificView" | ||
ROLE_SPECIFIC_TYPE RoleType = "roleSpecific" | ||
) | ||
|
||
type DefaultAuthPolicyRepository interface { | ||
CreatePolicy(policy *DefaultAuthPolicy) (*DefaultAuthPolicy, error) | ||
UpdatePolicyByRoleType(policy string, roleType RoleType) (*DefaultAuthPolicy, error) | ||
GetPolicyByRoleType(roleType RoleType) (policy string, err error) | ||
} | ||
|
||
type DefaultAuthPolicy struct { | ||
TableName struct{} `sql:"default_auth_policy" pg:",discard_unknown_columns"` | ||
Id int `sql:"id,pk"` | ||
RoleType string `sql:"role_type,notnull"` | ||
Policy string `sql:"policy,notnull"` | ||
sql.AuditLog | ||
} | ||
|
||
type DefaultAuthPolicyRepositoryImpl struct { | ||
dbConnection *pg.DB | ||
logger *zap.SugaredLogger | ||
} | ||
|
||
func NewDefaultAuthPolicyRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger) *DefaultAuthPolicyRepositoryImpl { | ||
return &DefaultAuthPolicyRepositoryImpl{dbConnection: dbConnection, logger: logger} | ||
} | ||
|
||
func (impl DefaultAuthPolicyRepositoryImpl) CreatePolicy(policy *DefaultAuthPolicy) (*DefaultAuthPolicy, error) { | ||
err := impl.dbConnection.Insert(policy) | ||
if err != nil { | ||
impl.logger.Error("error in creating auth policy", "err", err) | ||
return policy, err | ||
} | ||
return policy, nil | ||
} | ||
|
||
func (impl DefaultAuthPolicyRepositoryImpl) UpdatePolicyByRoleType(policy string, roleType RoleType) (*DefaultAuthPolicy, error) { | ||
var model DefaultAuthPolicy | ||
_, err := impl.dbConnection.Model(&model).Set("policy = ?", policy). | ||
Where("role_type = ?", roleType).Update() | ||
if err != nil { | ||
impl.logger.Error("error in updating auth policy", "err", err) | ||
return &model, err | ||
} | ||
return &model, nil | ||
} | ||
|
||
func (impl DefaultAuthPolicyRepositoryImpl) GetPolicyByRoleType(roleType RoleType) (policy string, err error) { | ||
var model DefaultAuthPolicy | ||
err = impl.dbConnection.Model(&model).Where("role_type = ?", roleType).Select() | ||
if err != nil { | ||
impl.logger.Error("error in getting policy by roleType", "err", err, "roleType", roleType) | ||
return "", err | ||
} | ||
return model.Policy, nil | ||
} |
Oops, something went wrong.