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