1
1
import {
2
2
cleanUpFileDiagnostics ,
3
3
createDiagnosticCollection ,
4
- ggshieldApiKey ,
5
4
ggshieldAuthStatus ,
6
5
ignoreLastFound ,
7
6
ignoreSecret ,
@@ -21,7 +20,7 @@ import {
21
20
WebviewView ,
22
21
} from "vscode" ;
23
22
import { GGShieldResolver } from "./lib/ggshield-resolver" ;
24
- import { getCurrentFile , isGitInstalled } from "./utils" ;
23
+ import { getCurrentFile , checkGitInstalled } from "./utils" ;
25
24
import { GitGuardianWebviewProvider } from "./ggshield-webview/gitguardian-webview-view" ;
26
25
import {
27
26
createStatusBarItem ,
@@ -67,13 +66,6 @@ function registerOpenViewsCommands(
67
66
) ;
68
67
}
69
68
70
- function registerQuotaViewCommands ( view : GitGuardianQuotaWebviewProvider ) {
71
- commands . registerCommand (
72
- "gitguardian.refreshQuota" ,
73
- async ( ) => await view . refresh ( )
74
- ) ;
75
- }
76
-
77
69
export function activate ( context : ExtensionContext ) {
78
70
// Check if ggshield if available
79
71
commands . executeCommand ( "setContext" , "isAuthenticated" , false ) ;
@@ -122,123 +114,107 @@ export function activate(context: ExtensionContext) {
122
114
123
115
//generic commands to open correct view on status bar click
124
116
registerOpenViewsCommands ( context , outputChannel ) ;
125
- registerQuotaViewCommands ( ggshieldQuotaViewProvider ) ;
117
+ commands . registerCommand (
118
+ "gitguardian.refreshQuota" ,
119
+ ggshieldQuotaViewProvider . refresh
120
+ ) ;
126
121
127
122
context . subscriptions . push (
128
123
languages . registerHoverProvider ( "*" , new GitGuardianSecretHoverProvider ( ) )
129
124
) ;
130
125
131
- ggshieldResolver
132
- . checkGGShieldConfiguration ( )
133
- . then ( ( ) => {
134
- // Check if ggshield is authenticated
135
- ggshieldAuthStatus ( configuration , context ) ;
136
- if ( context . globalState . get ( "isAuthenticated" , false ) ) {
137
- updateStatusBarItem ( StatusBarStatus . ready ) ;
138
- ggshieldViewProvider . refresh ( ) ;
139
- ggshieldRemediationMessageViewProvider . refresh ( ) ;
140
- ggshieldQuotaViewProvider . refresh ( ) ;
141
- } else {
142
- updateStatusBarItem ( StatusBarStatus . unauthenticated ) ;
143
- }
144
- } )
145
- . then ( async ( ) => {
146
- // Check if git is installed
147
- console . log ( "git is installed and configured" ) ;
148
- const gitInstallation = await isGitInstalled ( ) ;
149
- if ( ! gitInstallation ) {
150
- window . showErrorMessage (
151
- `GGShield requires git to work correctly. Please install git.`
126
+ checkGitInstalled ( ) ;
127
+
128
+ ggshieldResolver . checkGGShieldConfiguration ( ) ;
129
+
130
+ // Check if ggshield is authenticated
131
+ ggshieldAuthStatus ( configuration , context ) . then ( ( ) => {
132
+ if ( context . globalState . get ( "isAuthenticated" , false ) ) {
133
+ updateStatusBarItem ( StatusBarStatus . ready ) ;
134
+ ggshieldViewProvider . refresh ( ) ;
135
+ ggshieldRemediationMessageViewProvider . refresh ( ) ;
136
+ ggshieldQuotaViewProvider . refresh ( ) ;
137
+ } else {
138
+ updateStatusBarItem ( StatusBarStatus . unauthenticated ) ;
139
+ }
140
+ } ) ;
141
+
142
+ // Start scanning documents on activation events
143
+ // (i.e. when a new document is opened or when the document is saved)
144
+ createDiagnosticCollection ( context ) ;
145
+ context . subscriptions . push (
146
+ workspace . onDidSaveTextDocument ( ( textDocument ) => {
147
+ // Check if the document is inside the workspace
148
+ const workspaceFolder = workspace . getWorkspaceFolder ( textDocument . uri ) ;
149
+ if (
150
+ context . globalState . get ( "isAuthenticated" , false ) &&
151
+ workspaceFolder
152
+ ) {
153
+ scanFile (
154
+ textDocument . fileName ,
155
+ textDocument . uri ,
156
+ ggshieldResolver . configuration
152
157
) ;
153
158
}
154
- } )
155
- . then ( ( ) => {
156
- // Start scanning documents on activation events
157
- // (i.e. when a new document is opened or when the document is saved)
158
- createDiagnosticCollection ( context ) ;
159
- context . subscriptions . push (
160
- workspace . onDidSaveTextDocument ( ( textDocument ) => {
161
- // Check if the document is inside the workspace
162
- const workspaceFolder = workspace . getWorkspaceFolder (
163
- textDocument . uri
164
- ) ;
165
- if (
166
- context . globalState . get ( "isAuthenticated" , false ) &&
167
- workspaceFolder
168
- ) {
169
- scanFile (
170
- textDocument . fileName ,
171
- textDocument . uri ,
172
- ggshieldResolver . configuration
173
- ) ;
174
- }
175
- } ) ,
176
- workspace . onDidCloseTextDocument ( ( textDocument ) =>
177
- cleanUpFileDiagnostics ( textDocument . uri )
178
- ) ,
179
- commands . registerCommand ( "gitguardian.quota" , ( ) => {
180
- showAPIQuota ( ggshieldResolver . configuration ) ;
181
- } ) ,
182
- commands . registerCommand ( "gitguardian.ignore" , ( ) => {
183
- ignoreLastFound ( ggshieldResolver . configuration ) ;
184
- if ( window . activeTextEditor ) {
185
- cleanUpFileDiagnostics ( window . activeTextEditor ?. document . uri ) ;
186
- }
187
- } ) ,
188
- commands . registerCommand (
189
- "gitguardian.ignoreSecret" ,
190
- ( diagnosticData ) => {
191
- window . showInformationMessage ( "Secret ignored." ) ;
192
- let currentFile = getCurrentFile ( ) ;
193
- let secretName = generateSecretName ( currentFile , diagnosticData ) ;
194
-
195
- ignoreSecret (
196
- ggshieldResolver . configuration ,
197
- diagnosticData . secretSha ,
198
- secretName
199
- ) ;
200
- scanFile (
201
- currentFile ,
202
- Uri . file ( currentFile ) ,
203
- ggshieldResolver . configuration
204
- ) ;
159
+ } ) ,
160
+ workspace . onDidCloseTextDocument ( ( textDocument ) =>
161
+ cleanUpFileDiagnostics ( textDocument . uri )
162
+ ) ,
163
+ commands . registerCommand ( "gitguardian.quota" , ( ) => {
164
+ showAPIQuota ( ggshieldResolver . configuration ) ;
165
+ } ) ,
166
+ commands . registerCommand ( "gitguardian.ignore" , ( ) => {
167
+ ignoreLastFound ( ggshieldResolver . configuration ) ;
168
+ if ( window . activeTextEditor ) {
169
+ cleanUpFileDiagnostics ( window . activeTextEditor ?. document . uri ) ;
170
+ }
171
+ } ) ,
172
+ commands . registerCommand ( "gitguardian.ignoreSecret" , ( diagnosticData ) => {
173
+ window . showInformationMessage ( "Secret ignored." ) ;
174
+ let currentFile = getCurrentFile ( ) ;
175
+ let secretName = generateSecretName ( currentFile , diagnosticData ) ;
176
+
177
+ ignoreSecret (
178
+ ggshieldResolver . configuration ,
179
+ diagnosticData . secretSha ,
180
+ secretName
181
+ ) ;
182
+ scanFile (
183
+ currentFile ,
184
+ Uri . file ( currentFile ) ,
185
+ ggshieldResolver . configuration
186
+ ) ;
187
+ } ) ,
188
+ commands . registerCommand ( "gitguardian.authenticate" , async ( ) => {
189
+ commands . executeCommand ( "gitguardian.openSidebar" ) ;
190
+ await loginGGShield (
191
+ ggshieldResolver . configuration ,
192
+ outputChannel ,
193
+ ggshieldViewProvider . getView ( ) as WebviewView ,
194
+ context
195
+ )
196
+ . then ( ( ) => {
197
+ if ( context . globalState . get ( "isAuthenticated" , false ) ) {
198
+ updateStatusBarItem ( StatusBarStatus . ready ) ;
199
+ } else {
200
+ updateStatusBarItem ( StatusBarStatus . unauthenticated ) ;
205
201
}
206
- ) ,
207
- commands . registerCommand ( "gitguardian.authenticate" , async ( ) => {
208
- commands . executeCommand ( "gitguardian.openSidebar" ) ;
209
- await loginGGShield (
210
- ggshieldResolver . configuration ,
211
- outputChannel ,
212
- ggshieldViewProvider . getView ( ) as WebviewView ,
213
- context
214
- )
215
- . then ( ( ) => {
216
- if ( context . globalState . get ( "isAuthenticated" , false ) ) {
217
- updateStatusBarItem ( StatusBarStatus . ready ) ;
218
- } else {
219
- updateStatusBarItem ( StatusBarStatus . unauthenticated ) ;
220
- }
221
- ggshieldViewProvider . refresh ( ) ;
222
- ggshieldRemediationMessageViewProvider . refresh ( ) ;
223
- ggshieldQuotaViewProvider . refresh ( ) ;
224
- } )
225
- . catch ( ( err ) => {
226
- outputChannel . appendLine ( `Authentication failed: ${ err . message } ` ) ;
227
- } ) ;
228
- } ) ,
229
- commands . registerCommand ( "gitguardian.logout" , async ( ) => {
230
- logoutGGShield ( ggshieldResolver . configuration , context ) ;
231
- updateStatusBarItem ( StatusBarStatus . unauthenticated ) ;
232
202
ggshieldViewProvider . refresh ( ) ;
233
203
ggshieldRemediationMessageViewProvider . refresh ( ) ;
234
204
ggshieldQuotaViewProvider . refresh ( ) ;
235
205
} )
236
- ) ;
206
+ . catch ( ( err ) => {
207
+ outputChannel . appendLine ( `Authentication failed: ${ err . message } ` ) ;
208
+ } ) ;
209
+ } ) ,
210
+ commands . registerCommand ( "gitguardian.logout" , async ( ) => {
211
+ logoutGGShield ( ggshieldResolver . configuration , context ) ;
212
+ updateStatusBarItem ( StatusBarStatus . unauthenticated ) ;
213
+ ggshieldViewProvider . refresh ( ) ;
214
+ ggshieldRemediationMessageViewProvider . refresh ( ) ;
215
+ ggshieldQuotaViewProvider . refresh ( ) ;
237
216
} )
238
- . catch ( ( error ) => {
239
- outputChannel . appendLine ( `Error: ${ error . message } ` ) ;
240
- updateStatusBarItem ( StatusBarStatus . error ) ;
241
- } ) ;
217
+ ) ;
242
218
}
243
219
244
220
export function deactivate ( ) { }
0 commit comments