@@ -18,6 +18,7 @@ package rbac
18
18
19
19
import (
20
20
"fmt"
21
+ "github.com/devtron-labs/devtron/api/helm-app/service/bean"
21
22
"github.com/devtron-labs/devtron/internal/sql/repository/app"
22
23
repository2 "github.com/devtron-labs/devtron/pkg/appStore/installedApp/repository"
23
24
"github.com/devtron-labs/devtron/pkg/cluster/repository"
@@ -78,8 +79,7 @@ func (impl EnforcerUtilHelmImpl) GetHelmObjectByTeamIdAndClusterId(teamId int, c
78
79
79
80
func (impl EnforcerUtilHelmImpl ) GetHelmObjectByClusterIdNamespaceAndAppName (clusterId int , namespace string , appName string ) (string , string ) {
80
81
81
- installedApp , installedAppErr := impl .InstalledAppRepository .GetInstalledApplicationByClusterIdAndNamespaceAndAppName (clusterId , namespace , appName )
82
-
82
+ installedApp , installedAppErr := impl .getInstalledApp (clusterId , namespace , appName )
83
83
if installedAppErr != nil && installedAppErr != pg .ErrNoRows {
84
84
impl .logger .Errorw ("error on fetching data for rbac object from installed app repository" , "err" , installedAppErr )
85
85
return "" , ""
@@ -93,19 +93,18 @@ func (impl EnforcerUtilHelmImpl) GetHelmObjectByClusterIdNamespaceAndAppName(clu
93
93
94
94
if installedApp == nil || installedAppErr == pg .ErrNoRows {
95
95
// for cli apps which are not yet linked
96
-
97
- app , err := impl .appRepository .FindAppAndProjectByAppName (appName )
96
+ app , err := impl .getAppObject (clusterId , namespace , appName )
98
97
if err != nil && err != pg .ErrNoRows {
99
98
impl .logger .Errorw ("error in fetching app details" , "err" , err )
100
99
return "" , ""
101
100
}
102
101
103
102
if app .TeamId == 0 {
104
103
// case if project is not assigned to cli app
105
- return fmt .Sprintf ("%s/%s__%s/%s" , team .UNASSIGNED_PROJECT , cluster .ClusterName , namespace , appName ), ""
104
+ return fmt .Sprintf ("%s/%s__%s/%s" , team .UNASSIGNED_PROJECT , cluster .ClusterName , namespace , appName ), fmt . Sprintf ( "%s/%s/%s" , team . UNASSIGNED_PROJECT , namespace , appName )
106
105
} else {
107
106
// case if project is assigned
108
- return fmt .Sprintf ("%s/%s__%s/%s" , app .Team .Name , cluster .ClusterName , namespace , appName ), ""
107
+ return fmt .Sprintf ("%s/%s__%s/%s" , app .Team .Name , cluster .ClusterName , namespace , appName ), fmt . Sprintf ( "%s/%s/%s" , app . Team . Name , namespace , appName )
109
108
}
110
109
111
110
}
@@ -118,7 +117,7 @@ func (impl EnforcerUtilHelmImpl) GetHelmObjectByClusterIdNamespaceAndAppName(clu
118
117
} else {
119
118
if installedApp .EnvironmentId == 0 {
120
119
// for apps in EA mode, initally env can be 0.
121
- return fmt .Sprintf ("%s/%s__%s/%s" , installedApp .App .Team .Name , cluster .ClusterName , namespace , appName ), ""
120
+ return fmt .Sprintf ("%s/%s__%s/%s" , installedApp .App .Team .Name , cluster .ClusterName , namespace , appName ), fmt . Sprintf ( "%s/%s/%s" , installedApp . App . Team . Name , namespace , appName )
122
121
}
123
122
// for apps which are assigned to a project and have env ID
124
123
rbacOne := fmt .Sprintf ("%s/%s/%s" , installedApp .App .Team .Name , installedApp .Environment .EnvironmentIdentifier , appName )
@@ -131,6 +130,37 @@ func (impl EnforcerUtilHelmImpl) GetHelmObjectByClusterIdNamespaceAndAppName(clu
131
130
132
131
}
133
132
133
+ func (impl EnforcerUtilHelmImpl ) getAppObject (clusterId int , namespace string , appName string ) (* app.App , error ) {
134
+ appIdentifier := & bean.AppIdentifier {
135
+ ClusterId : clusterId ,
136
+ Namespace : namespace ,
137
+ ReleaseName : appName ,
138
+ }
139
+ appNameIdentifier := appIdentifier .GetUniqueAppNameIdentifier ()
140
+ appObj , err := impl .appRepository .FindAppAndProjectByAppName (appNameIdentifier )
141
+ if appObj == nil || err == pg .ErrNoRows {
142
+ impl .logger .Warnw ("appObj not found, going to find app using display name " , "appIdentifier" , appNameIdentifier , "appName" , appName )
143
+ appObj , err = impl .appRepository .FindAppAndProjectByAppName (appName )
144
+ }
145
+ return appObj , err
146
+ }
147
+
148
+ func (impl EnforcerUtilHelmImpl ) getInstalledApp (clusterId int , namespace string , appName string ) (* repository2.InstalledApps , error ) {
149
+ appIdentifier := & bean.AppIdentifier {
150
+ ClusterId : clusterId ,
151
+ Namespace : namespace ,
152
+ ReleaseName : appName ,
153
+ }
154
+ appNameIdentifier := appIdentifier .GetUniqueAppNameIdentifier ()
155
+ //installedApp, installedAppErr := impl.InstalledAppRepository.GetInstalledApplicationByClusterIdAndNamespaceAndAppName(clusterId, namespace, appNameIdentifier)
156
+ //if installedApp == nil || installedAppErr == pg.ErrNoRows {
157
+ // impl.logger.Warnw("installed app not found, going to find app using display name ", "appIdentifier", appNameIdentifier, "appName", appName)
158
+ // installedApp, installedAppErr = impl.InstalledAppRepository.GetInstalledApplicationByClusterIdAndNamespaceAndAppName(clusterId, namespace, appName)
159
+ //}
160
+ return impl .InstalledAppRepository .GetInstalledApplicationByClusterIdAndNamespaceAndAppIdentifier (clusterId , namespace , appNameIdentifier , appName )
161
+ //return installedApp, installedAppErr
162
+ }
163
+
134
164
func (impl EnforcerUtilHelmImpl ) GetAppRBACNameByInstalledAppId (installedAppVersionId int ) (string , string ) {
135
165
136
166
InstalledApp , err := impl .InstalledAppRepository .GetInstalledApp (installedAppVersionId )
0 commit comments