7
7
*/
8
8
package com .intellij .lang .jsgraphql .ide .introspection ;
9
9
10
- import com .fasterxml .jackson .databind .ObjectMapper ;
11
10
import com .google .gson .Gson ;
12
11
import com .google .gson .JsonSyntaxException ;
13
12
import com .intellij .ide .actions .CreateFileAction ;
62
61
import com .intellij .util .concurrency .annotations .RequiresWriteLock ;
63
62
import com .intellij .util .messages .MessageBusConnection ;
64
63
import org .apache .commons .lang .StringEscapeUtils ;
65
- import org .apache .commons .lang .StringUtils ;
66
64
import org .apache .http .client .methods .CloseableHttpResponse ;
67
65
import org .apache .http .client .methods .HttpPost ;
68
66
import org .apache .http .client .methods .HttpUriRequest ;
80
78
import org .jetbrains .annotations .Nullable ;
81
79
82
80
import java .io .IOException ;
83
-
84
- import java .security .GeneralSecurityException ;
85
- import java .security .KeyManagementException ;
86
- import java .security .KeyStoreException ;
87
- import java .security .NoSuchAlgorithmException ;
88
- import java .util .Collection ;
89
- import java .util .Collections ;
90
- import java .util .List ;
91
- import java .util .Map ;
92
81
import java .nio .file .Path ;
93
82
import java .nio .file .Paths ;
94
83
import java .security .*;
95
84
import java .security .cert .CertificateException ;
85
+ import java .util .Collection ;
86
+ import java .util .Collections ;
87
+ import java .util .List ;
88
+ import java .util .Map ;
96
89
97
90
import static com .intellij .lang .jsgraphql .ide .project .GraphQLUIProjectService .setHeadersFromOptions ;
98
91
@@ -102,8 +95,6 @@ public class GraphQLIntrospectionService implements Disposable {
102
95
private static final String DISABLE_EMPTY_ERRORS_WARNING_KEY = "graphql.empty.errors.warning.disabled" ;
103
96
public static final String GRAPHQL_TRUST_ALL_HOSTS = "graphql.trust.all.hosts" ;
104
97
105
- public static final String SSL_EXTENSION = "sslConfiguration" ;
106
-
107
98
private GraphQLIntrospectionTask latestIntrospection = null ;
108
99
private final Project myProject ;
109
100
@@ -192,30 +183,37 @@ public static HttpPost createRequest(@NotNull GraphQLConfigVariableAwareEndpoint
192
183
return request ;
193
184
}
194
185
195
- public GraphQLConfigSecurity getSecurityConfig (@ NotNull VirtualFile file ) {
186
+ @ Nullable
187
+ public GraphQLConfigSecurity getSecurityConfig (@ Nullable VirtualFile configFile ) {
188
+ if (configFile == null ) {
189
+ return null ;
190
+ }
191
+
192
+ GraphQLConfigData config = GraphQLConfigManager .getService (myProject ).getConfigurationsByPath ()
193
+ .get (configFile .isDirectory () ? configFile : configFile .getParent ());
194
+ if (config == null ) {
195
+ return null ;
196
+ }
196
197
197
- GraphQLConfigData config = GraphQLConfigManager .getService (myProject ).getConfigurationsByPath ().get (file );
198
- Map <String , Object > sslExtension = (Map <String , Object >) config .extensions .get (SSL_EXTENSION );
199
- if (sslExtension != null && ! sslExtension .isEmpty ()) {
198
+ Map <String , Object > sslExtension = (Map <String , Object >) config .extensions .get (GraphQLConfigManager .SSL_EXTENSION );
199
+ if (sslExtension != null && !sslExtension .isEmpty ()) {
200
200
GraphQLConfigSecurity sslConfig = new GraphQLConfigSecurity ();
201
201
Map <String , Object > clientCertificate = (Map <String , Object >) sslExtension .get ("clientCertificate" );
202
- if (clientCertificate != null && ! clientCertificate .isEmpty ()) {
202
+ if (clientCertificate != null && !clientCertificate .isEmpty ()) {
203
203
sslConfig .clientCertificate = new GraphQLConfigCertificate ();
204
- String path = (String ) clientCertificate .get ("path" );
205
- sslConfig .clientCertificate .path = path ;
204
+ sslConfig .clientCertificate .path = (String ) clientCertificate .get ("path" );
206
205
String format = (String ) clientCertificate .get ("format" );
207
- if (format != null && ! format .equals ("PEM" )) {
206
+ if (format != null && !format .equals ("PEM" )) {
208
207
throw new RuntimeException ("Unsupported certificate format, only PEM is currently supported" );
209
208
}
210
209
sslConfig .clientCertificate .format = GraphQLConfigCertificate .Encoding .PEM ;
211
210
}
212
211
Map <String , Object > clientCertificateKey = (Map <String , Object >) sslExtension .get ("clientCertificateKey" );
213
- if (clientCertificateKey != null && ! clientCertificateKey .isEmpty ()) {
212
+ if (clientCertificateKey != null && !clientCertificateKey .isEmpty ()) {
214
213
sslConfig .clientCertificateKey = new GraphQLConfigCertificate ();
215
- String path = (String ) clientCertificateKey .get ("path" );
216
- sslConfig .clientCertificateKey .path = path ;
214
+ sslConfig .clientCertificateKey .path = (String ) clientCertificateKey .get ("path" );
217
215
String format = (String ) clientCertificateKey .get ("format" );
218
- if (format != null && ! format .equals ("PEM" )) {
216
+ if (format != null && !format .equals ("PEM" )) {
219
217
throw new RuntimeException ("Unsupported certificate format, only PEM is currently supported" );
220
218
}
221
219
sslConfig .clientCertificateKey .format = GraphQLConfigCertificate .Encoding .PEM ;
@@ -536,7 +534,7 @@ public IntrospectionQueryTask(@NotNull HttpUriRequest request,
536
534
public void run (@ NotNull ProgressIndicator indicator ) {
537
535
indicator .setIndeterminate (true );
538
536
String responseJson ;
539
- GraphQLConfigSecurity sslConfig = getSecurityConfig (introspectionSourceFile . getParent () );
537
+ GraphQLConfigSecurity sslConfig = getSecurityConfig (introspectionSourceFile );
540
538
try (final CloseableHttpClient httpClient = createHttpClient (sslConfig );
541
539
final CloseableHttpResponse response = httpClient .execute (request )) {
542
540
responseJson = ObjectUtils .coalesce (EntityUtils .toString (response .getEntity ()), "" );
0 commit comments