Skip to content

Commit 31cc015

Browse files
committed
Rebase onto the upstream branch
1 parent abdd7e3 commit 31cc015

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

src/main/com/intellij/lang/jsgraphql/ide/editor/GraphQLIntrospectionSSLBuilder.java renamed to src/main/com/intellij/lang/jsgraphql/ide/introspection/GraphQLIntrospectionSSLBuilder.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.intellij.lang.jsgraphql.ide.editor;
1+
package com.intellij.lang.jsgraphql.ide.introspection;
22

33
import com.intellij.lang.jsgraphql.ide.project.graphqlconfig.model.GraphQLConfigCertificate;
44
import org.jetbrains.annotations.NotNull;
@@ -8,7 +8,6 @@
88
import java.io.InputStream;
99
import java.io.UnsupportedEncodingException;
1010
import java.nio.charset.Charset;
11-
import java.nio.charset.StandardCharsets;
1211
import java.nio.file.Files;
1312
import java.nio.file.Path;
1413
import java.security.*;
@@ -22,7 +21,8 @@
2221

2322
public class GraphQLIntrospectionSSLBuilder {
2423
@NotNull
25-
public static KeyStore makeKeyStore(final Path certPath, final Path keyPath, final GraphQLConfigCertificate.Encoding format) throws UnsupportedEncodingException {
24+
public static KeyStore makeKeyStore(final Path certPath, final Path keyPath, final GraphQLConfigCertificate.Encoding format)
25+
throws UnsupportedEncodingException {
2626
CertificateFactory certificateFactory;
2727
try {
2828
certificateFactory = CertificateFactory.getInstance("X509");
@@ -33,7 +33,7 @@ public static KeyStore makeKeyStore(final Path certPath, final Path keyPath, fin
3333
java.security.cert.Certificate[] certChain;
3434
try (InputStream inputStream = Files.newInputStream(certPath)) {
3535
Collection<? extends Certificate> certCollection = certificateFactory.generateCertificates(inputStream);
36-
certChain = certCollection.toArray(new java.security.cert.Certificate[certCollection.size()]);
36+
certChain = certCollection.toArray(new Certificate[0]);
3737
} catch (CertificateException | IOException e) {
3838
throw new RuntimeException(e);
3939
}
@@ -59,7 +59,7 @@ public static KeyStore makeKeyStore(final Path certPath, final Path keyPath, fin
5959
@Nullable
6060
private static PrivateKey generatePEMPrivateKey(final Path keyPath) throws IOException {
6161

62-
String key = new String(Files.readAllBytes(keyPath), Charset.defaultCharset());
62+
String key = Files.readString(keyPath, Charset.defaultCharset());
6363
String privateKeyPEM = key
6464
.replace("-----BEGIN PRIVATE KEY-----", "")
6565
.replaceAll(System.lineSeparator(), "")

src/main/com/intellij/lang/jsgraphql/ide/introspection/GraphQLIntrospectionService.java

+24-26
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
package com.intellij.lang.jsgraphql.ide.introspection;
99

10-
import com.fasterxml.jackson.databind.ObjectMapper;
1110
import com.google.gson.Gson;
1211
import com.google.gson.JsonSyntaxException;
1312
import com.intellij.ide.actions.CreateFileAction;
@@ -62,7 +61,6 @@
6261
import com.intellij.util.concurrency.annotations.RequiresWriteLock;
6362
import com.intellij.util.messages.MessageBusConnection;
6463
import org.apache.commons.lang.StringEscapeUtils;
65-
import org.apache.commons.lang.StringUtils;
6664
import org.apache.http.client.methods.CloseableHttpResponse;
6765
import org.apache.http.client.methods.HttpPost;
6866
import org.apache.http.client.methods.HttpUriRequest;
@@ -80,19 +78,14 @@
8078
import org.jetbrains.annotations.Nullable;
8179

8280
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;
9281
import java.nio.file.Path;
9382
import java.nio.file.Paths;
9483
import java.security.*;
9584
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;
9689

9790
import static com.intellij.lang.jsgraphql.ide.project.GraphQLUIProjectService.setHeadersFromOptions;
9891

@@ -102,8 +95,6 @@ public class GraphQLIntrospectionService implements Disposable {
10295
private static final String DISABLE_EMPTY_ERRORS_WARNING_KEY = "graphql.empty.errors.warning.disabled";
10396
public static final String GRAPHQL_TRUST_ALL_HOSTS = "graphql.trust.all.hosts";
10497

105-
public static final String SSL_EXTENSION = "sslConfiguration";
106-
10798
private GraphQLIntrospectionTask latestIntrospection = null;
10899
private final Project myProject;
109100

@@ -192,30 +183,37 @@ public static HttpPost createRequest(@NotNull GraphQLConfigVariableAwareEndpoint
192183
return request;
193184
}
194185

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+
}
196197

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()) {
200200
GraphQLConfigSecurity sslConfig = new GraphQLConfigSecurity();
201201
Map<String, Object> clientCertificate = (Map<String, Object>) sslExtension.get("clientCertificate");
202-
if (clientCertificate != null && ! clientCertificate.isEmpty()) {
202+
if (clientCertificate != null && !clientCertificate.isEmpty()) {
203203
sslConfig.clientCertificate = new GraphQLConfigCertificate();
204-
String path = (String) clientCertificate.get("path");
205-
sslConfig.clientCertificate.path = path;
204+
sslConfig.clientCertificate.path = (String) clientCertificate.get("path");
206205
String format = (String) clientCertificate.get("format");
207-
if (format != null && ! format.equals("PEM")) {
206+
if (format != null && !format.equals("PEM")) {
208207
throw new RuntimeException("Unsupported certificate format, only PEM is currently supported");
209208
}
210209
sslConfig.clientCertificate.format = GraphQLConfigCertificate.Encoding.PEM;
211210
}
212211
Map<String, Object> clientCertificateKey = (Map<String, Object>) sslExtension.get("clientCertificateKey");
213-
if (clientCertificateKey != null && ! clientCertificateKey.isEmpty()) {
212+
if (clientCertificateKey != null && !clientCertificateKey.isEmpty()) {
214213
sslConfig.clientCertificateKey = new GraphQLConfigCertificate();
215-
String path = (String) clientCertificateKey.get("path");
216-
sslConfig.clientCertificateKey.path = path;
214+
sslConfig.clientCertificateKey.path = (String) clientCertificateKey.get("path");
217215
String format = (String) clientCertificateKey.get("format");
218-
if (format != null && ! format.equals("PEM")) {
216+
if (format != null && !format.equals("PEM")) {
219217
throw new RuntimeException("Unsupported certificate format, only PEM is currently supported");
220218
}
221219
sslConfig.clientCertificateKey.format = GraphQLConfigCertificate.Encoding.PEM;
@@ -536,7 +534,7 @@ public IntrospectionQueryTask(@NotNull HttpUriRequest request,
536534
public void run(@NotNull ProgressIndicator indicator) {
537535
indicator.setIndeterminate(true);
538536
String responseJson;
539-
GraphQLConfigSecurity sslConfig = getSecurityConfig(introspectionSourceFile.getParent());
537+
GraphQLConfigSecurity sslConfig = getSecurityConfig(introspectionSourceFile);
540538
try (final CloseableHttpClient httpClient = createHttpClient(sslConfig);
541539
final CloseableHttpResponse response = httpClient.execute(request)) {
542540
responseJson = ObjectUtils.coalesce(EntityUtils.toString(response.getEntity()), "");

src/main/com/intellij/lang/jsgraphql/ide/project/GraphQLUIProjectService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public void run(@NotNull ProgressIndicator indicator) {
359359
private void runQuery(Editor editor, VirtualFile virtualFile, GraphQLQueryContext context, String url, HttpPost request) {
360360
GraphQLIntrospectionService introspectionService = GraphQLIntrospectionService.getInstance(myProject);
361361
try {
362-
VirtualFile configFile = GraphQLConfigManager.getService(myProject).getClosestConfigFile(virtualFile).getParent();
362+
VirtualFile configFile = GraphQLConfigManager.getService(myProject).getClosestConfigFile(virtualFile);
363363
GraphQLConfigSecurity sslConfig = introspectionService.getSecurityConfig(configFile);
364364
try (final CloseableHttpClient httpClient = introspectionService.createHttpClient(sslConfig)) {
365365
editor.putUserData(GRAPH_QL_EDITOR_QUERYING, true);

0 commit comments

Comments
 (0)