@@ -67,47 +67,57 @@ public DatabricksService(IOptions<DatabricksConfig> databricksConfig,IOptions<Le
6767 /// <inheritdoc/>
6868 public async Task < bool > IsUserReporter ( int userId )
6969 {
70+ bool isReporter = false ;
7071 string cacheKey = $ "{ userId } :{ CacheKey } ";
71- var userReportPermission = await this . cachingService . GetAsync < bool > ( cacheKey ) ;
72- if ( userReportPermission . ResponseEnum == CacheReadResponseEnum . Found )
72+ try
7373 {
74- return userReportPermission . Item ;
75- }
76-
74+ var userReportPermission = await this . cachingService . GetAsync < bool > ( cacheKey ) ;
75+ if ( userReportPermission . ResponseEnum == CacheReadResponseEnum . Found )
76+ {
77+ return userReportPermission . Item ;
78+ }
7779
78- DatabricksApiHttpClient databricksInstance = new DatabricksApiHttpClient ( this . databricksConfig ) ;
7980
80- var sqlText = $ "CALL { this . databricksConfig . Value . UserPermissionEndpoint } ({ userId } );";
81- const string requestUrl = "/api/2.0/sql/statements" ;
81+ DatabricksApiHttpClient databricksInstance = new DatabricksApiHttpClient ( this . databricksConfig ) ;
8282
83- var requestPayload = new
84- {
85- warehouse_id = this . databricksConfig . Value . WarehouseId ,
86- statement = sqlText ,
87- wait_timeout = "30s" ,
88- on_wait_timeout = "CANCEL"
89- } ;
83+ var sqlText = $ "CALL { this . databricksConfig . Value . UserPermissionEndpoint } ({ userId } );";
84+ const string requestUrl = "/api/2.0/sql/statements" ;
9085
91- var jsonBody = JsonConvert . SerializeObject ( requestPayload ) ;
92- using var content = new StringContent ( jsonBody , Encoding . UTF8 , "application/json" ) ;
86+ var requestPayload = new
87+ {
88+ warehouse_id = this . databricksConfig . Value . WarehouseId ,
89+ statement = sqlText ,
90+ wait_timeout = "30s" ,
91+ on_wait_timeout = "CANCEL"
92+ } ;
9393
94- var response = await databricksInstance . GetClient ( ) . PostAsync ( requestUrl , content ) ;
94+ var jsonBody = JsonConvert . SerializeObject ( requestPayload ) ;
95+ using var content = new StringContent ( jsonBody , Encoding . UTF8 , "application/json" ) ;
9596
96- var databricksResponse = await databricksInstance . GetClient ( ) . PostAsync ( requestUrl , content ) ;
97- if ( databricksResponse . StatusCode is not HttpStatusCode . OK )
98- {
99- //log failure
100- return false ;
101- }
102- var responseResult = await databricksResponse . Content . ReadAsStringAsync ( ) ;
97+ var response = await databricksInstance . GetClient ( ) . PostAsync ( requestUrl , content ) ;
10398
104- responseResult = responseResult . Trim ( ) ;
105- var root = JsonDocument . Parse ( responseResult ) . RootElement ;
106- string data = root . GetProperty ( "result" ) . GetProperty ( "data_array" ) [ 0 ] [ 0 ] . GetString ( ) ;
107- bool isReporter = data == "1" ;
99+ var databricksResponse = await databricksInstance . GetClient ( ) . PostAsync ( requestUrl , content ) ;
100+ if ( databricksResponse . StatusCode is not HttpStatusCode . OK )
101+ {
102+ //log failure
103+ return false ;
104+ }
105+ var responseResult = await databricksResponse . Content . ReadAsStringAsync ( ) ;
106+
107+ responseResult = responseResult . Trim ( ) ;
108+ var root = JsonDocument . Parse ( responseResult ) . RootElement ;
109+ string data = root . GetProperty ( "result" ) . GetProperty ( "data_array" ) [ 0 ] [ 0 ] . GetString ( ) ;
110+ isReporter = data == "1" ;
111+
112+ await this . cachingService . SetAsync ( cacheKey , isReporter ) ;
113+ return isReporter ;
108114
109- await this . cachingService . SetAsync ( cacheKey , isReporter ) ;
110- return isReporter ;
115+ }
116+ catch
117+ {
118+ await this . cachingService . SetAsync ( cacheKey , isReporter ) ;
119+ return isReporter ;
120+ }
111121 }
112122
113123 /// <inheritdoc/>
0 commit comments