diff --git a/release/conf/polaris-server.yaml b/release/conf/polaris-server.yaml index 2d1558136..eab609cd8 100644 --- a/release/conf/polaris-server.yaml +++ b/release/conf/polaris-server.yaml @@ -452,7 +452,7 @@ store: option: path: ./polaris.bolt loadFile: ./conf/bolt-data.yaml - ## Database storage plugin + # Database storage plugin # name: defaultStore # option: # master: diff --git a/store/mysql/role.go b/store/mysql/role.go index dfe353626..dc6430f7d 100644 --- a/store/mysql/role.go +++ b/store/mysql/role.go @@ -70,7 +70,7 @@ func (s *roleStore) savePrincipals(tx *BaseTx, role *authcommon.Role) error { return err } - insertTpl := "INSERT INTO auth_role_principal(role_id, principal_id, principal_role, extend_info) VALUES (?, ?, ?)" + insertTpl := "INSERT INTO auth_role_principal(role_id, principal_id, principal_role, IFNULL(extend_info, '')) VALUES (?, ?, ?)" for i := range role.Users { args := []interface{}{role.ID, role.Users[i].PrincipalID, authcommon.PrincipalUser, utils.MustJson(role.Users[i].Extend)} @@ -267,7 +267,8 @@ func (s *roleStore) GetMoreRoles(firstUpdate bool, mtime time.Time) ([]*authcomm } func (s *roleStore) fetchRolePrincipals(tx *BaseTx, role *authcommon.Role) error { - rows, err := tx.Query("SELECT role_id, principal_id, principal_role, extend_info FROM auth_role_principal WHERE rold_id = ?", role.ID) + rows, err := tx.Query("SELECT role_id, principal_id, principal_role, IFNULL(extend_info, '') FROM "+ + " auth_role_principal WHERE rold_id = ?", role.ID) if err != nil { log.Error("[store][role] fetch role principals", zap.String("name", role.Name), zap.Error(err)) return store.Error(err) diff --git a/store/mysql/scripts/polaris_server.sql b/store/mysql/scripts/polaris_server.sql index 4d4afb714..f7a470a58 100644 --- a/store/mysql/scripts/polaris_server.sql +++ b/store/mysql/scripts/polaris_server.sql @@ -1009,6 +1009,7 @@ INSERT INTO `owner`, `comment`, `default`, + `source`, `revision`, `flag`, `ctime`, @@ -1022,6 +1023,7 @@ VALUES '65e4789a6d5b49669adf1e9e8387549c', 'default admin', 1, + 'Polaris', 'fbca9bfa04ae4ead86e1ecf5811e32a9', 0, sysdate(), @@ -1146,6 +1148,7 @@ INSERT INTO `owner`, `comment`, `default`, + `source`, `revision`, `flag`, `ctime`, @@ -1159,6 +1162,7 @@ VALUES '65e4789a6d5b49669adf1e9e8387549c', 'global resources read onyly', 1, + 'Polaris', 'fbca9bfa04ae4ead86e1ecf5811e32a9', 0, sysdate(), @@ -1261,15 +1265,15 @@ VALUES INSERT INTO auth_strategy_function (`strategy_id`, `function`) VALUES ( - 'fbca9bfa04ae4ead86e1ecf5811e32a9', + 'bfa04ae1e32a94fbca9ead86e1ecf581', 'Describe*' ), ( - 'fbca9bfa04ae4ead86e1ecf5811e32a9', + 'bfa04ae1e32a94fbca9ead86e1ecf581', 'List*' ), ( - 'fbca9bfa04ae4ead86e1ecf5811e32a9', + 'bfa04ae1e32a94fbca9ead86e1ecf581', 'Get*' ); @@ -1283,6 +1287,7 @@ INSERT INTO `owner`, `comment`, `default`, + `source`, `revision`, `flag`, `ctime`, @@ -1296,6 +1301,7 @@ VALUES '65e4789a6d5b49669adf1e9e8387549c', 'global resources read and write', 1, + 'Polaris', 'fbca9bfa04ae4ead86e1ecf5811e32a9', 0, sysdate(), diff --git a/store/mysql/strategy.go b/store/mysql/strategy.go index 23c8e096d..c55d69624 100644 --- a/store/mysql/strategy.go +++ b/store/mysql/strategy.go @@ -277,7 +277,7 @@ func (s *strategyStore) addPolicyPrincipals(tx *BaseTx, id string, principals [] return nil } - savePrincipalSql := "INSERT IGNORE INTO auth_principal(strategy_id, principal_id, principal_role, extend_info) VALUES " + savePrincipalSql := "INSERT IGNORE INTO auth_principal(strategy_id, principal_id, principal_role, IFNULL(extend_info, '')) VALUES " values := make([]string, 0) args := make([]interface{}, 0) @@ -613,7 +613,7 @@ func (s *strategyStore) GetStrategyResources(principalId string, func (s *strategyStore) getStrategyPrincipals(queryHander QueryHandler, id string) ([]authcommon.Principal, error) { - rows, err := queryHander("SELECT principal_id, principal_role, extend_info FROM auth_principal WHERE strategy_id = ?", id) + rows, err := queryHander("SELECT principal_id, principal_role, IFNULL(extend_info, '') FROM auth_principal WHERE strategy_id = ?", id) if err != nil { switch err { case sql.ErrNoRows: @@ -670,7 +670,7 @@ func (s *strategyStore) getStrategyConditions(queryHander QueryHandler, id strin func (s *strategyStore) getStrategyFunctions(queryHander QueryHandler, id string) ([]string, error) { - rows, err := queryHander("SELECT `function` FROM auth_strategy_label WHERE strategy_id = ?", id) + rows, err := queryHander("SELECT `function` FROM auth_strategy_function WHERE strategy_id = ?", id) if err != nil { switch err { case sql.ErrNoRows: