@@ -946,39 +946,46 @@ func (impl UserAuthRepositoryImpl) GetRolesForWorkflow(workflow, entityName stri
946
946
func (impl UserAuthRepositoryImpl ) GetRoleForClusterEntity (cluster , namespace , group , kind , resource , action string ) (RoleModel , error ) {
947
947
var model RoleModel
948
948
query := "SELECT * FROM roles WHERE entity = ? "
949
+ var queryParams []string
949
950
var err error
950
951
951
952
if len (cluster ) > 0 {
952
- query += " and cluster='" + cluster + "' "
953
+ query += " and cluster = ? "
954
+ queryParams = append (queryParams , cluster )
953
955
} else {
954
956
query += " and cluster IS NULL "
955
957
}
956
958
if len (namespace ) > 0 {
957
- query += " and namespace='" + namespace + "' "
959
+ query += " and namespace = ? "
960
+ queryParams = append (queryParams , namespace )
958
961
} else {
959
962
query += " and namespace IS NULL "
960
963
}
961
964
if len (group ) > 0 {
962
- query += " and \" group\" ='" + group + "' "
965
+ query += " and \" group\" = ? "
966
+ queryParams = append (queryParams , group )
963
967
} else {
964
968
query += " and \" group\" IS NULL "
965
969
}
966
970
if len (kind ) > 0 {
967
- query += " and kind='" + kind + "' "
971
+ query += " and kind = ? "
972
+ queryParams = append (queryParams , kind )
968
973
} else {
969
974
query += " and kind IS NULL "
970
975
}
971
976
if len (resource ) > 0 {
972
- query += " and resource='" + resource + "' "
977
+ query += " and resource = ? "
978
+ queryParams = append (queryParams , resource )
973
979
} else {
974
980
query += " and resource IS NULL "
975
981
}
976
982
if len (action ) > 0 {
977
- query += " and action='" + action + "' ;"
983
+ query += " and action = ? ;"
984
+ queryParams = append (queryParams , action )
978
985
} else {
979
986
query += " and action IS NULL ;"
980
987
}
981
- _ , err = impl .dbConnection .Query (& model , query , bean .CLUSTER_ENTITIY )
988
+ _ , err = impl .dbConnection .Query (& model , query , bean .CLUSTER_ENTITIY , queryParams )
982
989
if err != nil {
983
990
impl .Logger .Errorw ("error in getting roles for clusterEntity" , "err" , err ,
984
991
bean2 .CLUSTER , cluster , "namespace" , namespace , "kind" , kind , "group" , group , "resource" , resource )
@@ -990,24 +997,28 @@ func (impl UserAuthRepositoryImpl) GetRoleForClusterEntity(cluster, namespace, g
990
997
func (impl UserAuthRepositoryImpl ) GetRoleForJobsEntity (entity , team , app , env , act string , workflow string ) (RoleModel , error ) {
991
998
var model RoleModel
992
999
var err error
1000
+ var queryParams []string
993
1001
if len (team ) > 0 && len (act ) > 0 {
994
1002
query := "SELECT role.* FROM roles role WHERE role.team = ? AND role.action=? AND role.entity=? "
995
1003
if len (env ) == 0 {
996
1004
query = query + " AND role.environment is NULL"
997
1005
} else {
998
- query += "AND role.environment='" + env + "'"
1006
+ query += "AND role.environment = ? "
1007
+ queryParams = append (queryParams , env )
999
1008
}
1000
1009
if len (app ) == 0 {
1001
1010
query = query + " AND role.entity_name is NULL"
1002
1011
} else {
1003
- query += " AND role.entity_name='" + app + "'"
1012
+ query += " AND role.entity_name = ? "
1013
+ queryParams = append (queryParams , app )
1004
1014
}
1005
1015
if len (workflow ) == 0 {
1006
1016
query = query + " AND role.workflow is NULL;"
1007
1017
} else {
1008
- query += " AND role.workflow='" + workflow + "';"
1018
+ query += " AND role.workflow = ? ;"
1019
+ queryParams = append (queryParams , workflow )
1009
1020
}
1010
- _ , err = impl .dbConnection .Query (& model , query , team , act , entity )
1021
+ _ , err = impl .dbConnection .Query (& model , query , team , act , entity , queryParams )
1011
1022
} else {
1012
1023
return model , nil
1013
1024
}
@@ -1021,21 +1032,25 @@ func (impl UserAuthRepositoryImpl) GetRoleForChartGroupEntity(entity, app, act,
1021
1032
var model RoleModel
1022
1033
var err error
1023
1034
if len (app ) > 0 && act == "update" {
1035
+ var queryParams []string
1024
1036
query := "SELECT role.* FROM roles role WHERE role.entity = ? AND role.entity_name=? AND role.action=?"
1025
1037
if len (accessType ) == 0 {
1026
1038
query = query + " and role.access_type is NULL"
1027
1039
} else {
1028
- query += " and role.access_type='" + accessType + "'"
1040
+ query += " and role.access_type = ? "
1041
+ queryParams = append (queryParams , accessType )
1029
1042
}
1030
- _ , err = impl .dbConnection .Query (& model , query , entity , app , act )
1043
+ _ , err = impl .dbConnection .Query (& model , query , entity , app , act , queryParams )
1031
1044
} else if app == "" {
1045
+ var queryParams []string
1032
1046
query := "SELECT role.* FROM roles role WHERE role.entity = ? AND role.action=?"
1033
1047
if len (accessType ) == 0 {
1034
1048
query = query + " and role.access_type is NULL"
1035
1049
} else {
1036
- query += " and role.access_type='" + accessType + "'"
1050
+ query += " and role.access_type = ? "
1051
+ queryParams = append (queryParams , accessType )
1037
1052
}
1038
- _ , err = impl .dbConnection .Query (& model , query , entity , act )
1053
+ _ , err = impl .dbConnection .Query (& model , query , entity , act , queryParams )
1039
1054
}
1040
1055
if err != nil {
1041
1056
impl .Logger .Errorw ("error in getting role for chart group entity" , "err" , err , "entity" , entity , "app" , app , "act" , act , "accessType" , accessType )
@@ -1047,52 +1062,62 @@ func (impl UserAuthRepositoryImpl) GetRoleForOtherEntity(team, app, env, act, ac
1047
1062
var model RoleModel
1048
1063
var err error
1049
1064
if len (team ) > 0 && len (app ) > 0 && len (env ) > 0 && len (act ) > 0 {
1065
+ var queryParams []string
1050
1066
query := "SELECT role.* FROM roles role WHERE role.team = ? AND role.entity_name=? AND role.environment=? AND role.action=?"
1051
1067
if oldValues {
1052
1068
query = query + " and role.access_type is NULL"
1053
1069
} else {
1054
- query += " and role.access_type='" + accessType + "'"
1070
+ query += " and role.access_type = ? "
1071
+ queryParams = append (queryParams , accessType )
1055
1072
}
1056
1073
1057
- _ , err = impl .dbConnection .Query (& model , query , team , app , env , act )
1074
+ _ , err = impl .dbConnection .Query (& model , query , team , app , env , act , queryParams )
1058
1075
} else if len (team ) > 0 && app == "" && len (env ) > 0 && len (act ) > 0 {
1059
-
1076
+ var queryParams [] string
1060
1077
query := "SELECT role.* FROM roles role WHERE role.team=? AND coalesce(role.entity_name,'')=? AND role.environment=? AND role.action=?"
1061
1078
if oldValues {
1062
1079
query = query + " and role.access_type is NULL"
1063
1080
} else {
1064
- query += " and role.access_type='" + accessType + "'"
1081
+ query += " and role.access_type = ? "
1082
+ queryParams = append (queryParams , accessType )
1065
1083
}
1066
- _ , err = impl .dbConnection .Query (& model , query , team , EMPTY_PLACEHOLDER_FOR_QUERY , env , act )
1084
+ _ , err = impl .dbConnection .Query (& model , query , team , EMPTY_PLACEHOLDER_FOR_QUERY , env , act , queryParams )
1067
1085
} else if len (team ) > 0 && len (app ) > 0 && env == "" && len (act ) > 0 {
1086
+ var queryParams []string
1068
1087
//this is applicable for all environment of a team
1069
1088
query := "SELECT role.* FROM roles role WHERE role.team = ? AND role.entity_name=? AND coalesce(role.environment,'')=? AND role.action=?"
1070
1089
if oldValues {
1071
1090
query = query + " and role.access_type is NULL"
1072
1091
} else {
1073
- query += " and role.access_type='" + accessType + "'"
1092
+ query += " and role.access_type = ? "
1093
+ queryParams = append (queryParams , accessType )
1074
1094
}
1075
1095
1076
- _ , err = impl .dbConnection .Query (& model , query , team , app , EMPTY_PLACEHOLDER_FOR_QUERY , act )
1096
+ _ , err = impl .dbConnection .Query (& model , query , team , app , EMPTY_PLACEHOLDER_FOR_QUERY , act , queryParams )
1077
1097
} else if len (team ) > 0 && app == "" && env == "" && len (act ) > 0 {
1098
+ var queryParams []string
1078
1099
//this is applicable for all environment of a team
1079
1100
query := "SELECT role.* FROM roles role WHERE role.team = ? AND coalesce(role.entity_name,'')=? AND coalesce(role.environment,'')=? AND role.action=?"
1080
1101
if oldValues {
1081
1102
query = query + " and role.access_type is NULL"
1082
1103
} else {
1083
- query += " and role.access_type='" + accessType + "'"
1104
+ query += " and role.access_type = ? "
1105
+ queryParams = append (queryParams , accessType )
1084
1106
}
1085
1107
1086
- _ , err = impl .dbConnection .Query (& model , query , team , EMPTY_PLACEHOLDER_FOR_QUERY , EMPTY_PLACEHOLDER_FOR_QUERY , act )
1108
+ _ , err = impl .dbConnection .Query (& model , query , team , EMPTY_PLACEHOLDER_FOR_QUERY , EMPTY_PLACEHOLDER_FOR_QUERY , act , queryParams )
1087
1109
} else if team == "" && app == "" && env == "" && len (act ) > 0 {
1110
+ var queryParams []string
1088
1111
//this is applicable for super admin, all env, all team, all app
1089
1112
query := "SELECT role.* FROM roles role WHERE coalesce(role.team,'') = ? AND coalesce(role.entity_name,'')=? AND coalesce(role.environment,'')=? AND role.action=?"
1090
1113
if len (accessType ) == 0 {
1091
1114
query = query + " and role.access_type is NULL"
1092
1115
} else {
1093
- query += " and role.access_type='" + accessType + "'"
1116
+ query += " and role.access_type = ? "
1117
+ queryParams = append (queryParams , accessType )
1118
+
1094
1119
}
1095
- _ , err = impl .dbConnection .Query (& model , query , EMPTY_PLACEHOLDER_FOR_QUERY , EMPTY_PLACEHOLDER_FOR_QUERY , EMPTY_PLACEHOLDER_FOR_QUERY , act )
1120
+ _ , err = impl .dbConnection .Query (& model , query , EMPTY_PLACEHOLDER_FOR_QUERY , EMPTY_PLACEHOLDER_FOR_QUERY , EMPTY_PLACEHOLDER_FOR_QUERY , act , queryParams )
1096
1121
} else if team == "" && app == "" && env == "" && act == "" {
1097
1122
return model , nil
1098
1123
} else {
0 commit comments