Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore skipSSLValidation flag #735

Merged
merged 1 commit into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import {
IntrospectionQuery,
parse
} from "graphql";
import { Agent, AgentOptions } from "https";
import { Agent } from "http";
import { fetch } from "apollo-env";
import { URL } from "url";

import { RemoteServiceConfig } from "../../config";
import { GraphQLSchemaProvider, SchemaChangeUnsubscribeHandler } from "./base";

Expand All @@ -23,23 +21,11 @@ export class IntrospectionSchemaProvider implements GraphQLSchemaProvider {
async resolveSchema() {
if (this.schema) return this.schema;
const { skipSSLValidation, url, headers } = this.config;
let options: HttpLink.Options = { uri: url, fetch };

if (skipSSLValidation) {
const urlObject = new URL(url);
const host = urlObject.host;
const port = +urlObject.port || 443;

const agentOptions: AgentOptions = {
host: host,
port: port,
rejectUnauthorized: false
};

const agent = new Agent(agentOptions);

options.fetchOptions = { agent: agent };
}
const options: HttpLink.Options = {
uri: url,
fetch,
...(skipSSLValidation && { fetchOptions: { agent: new Agent() } })
};

const { data, errors } = (await toPromise(
linkExecute(createHttpLink(options), {
Expand Down
4 changes: 3 additions & 1 deletion packages/apollo/src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface Flags {
engine?: string;
frontend?: string;
tag?: string;
skipSSLValidation?: boolean;
}

const headersArrayToObject = (
Expand Down Expand Up @@ -133,7 +134,8 @@ export abstract class ProjectCommand extends Command {
service: {
endpoint: {
url: flags.endpoint,
headers: headersArrayToObject(flags.header)
headers: headersArrayToObject(flags.header),
...(flags.skipSSLValidation && { skipSSLValidation: true })
}
}
});
Expand Down
4 changes: 4 additions & 0 deletions packages/apollo/src/commands/service/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default class ServiceDownload extends ProjectCommand {
char: "t",
description: "The published tag to check this service against",
default: "current"
}),
skipSSLValidation: flags.boolean({
char: "k",
description: "Allow connections to an SSL site without certs"
})
};

Expand Down