Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6cedb62

Browse files
committedJul 6, 2020
fix(integrations): fix API key ref handling
1 parent 8ff3b5f commit 6cedb62

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed
 

‎src/server/api/external-system.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ export const resolvers = {
2828
"syncedAt"
2929
]),
3030
type: (system: ExternalSystem) => system.type.toUpperCase(),
31-
apiKey: async (system: ExternalSystem) => system.api_key_ref,
31+
apiKey: async (system: ExternalSystem) => {
32+
// Backwards compatibility for API keys added before organization ID was prepended
33+
const components = system.api_key_ref.split("|");
34+
return components.length === 1 ? components[0] : components[1];
35+
},
3236
lists: async (system: ExternalSystem, { after, first }: RelayPageArgs) => {
3337
const query = r.reader("external_list").where({ system_id: system.id });
3438
return formatPage(query, { after, first, primaryColumn: "created_at" });

‎src/server/api/schema.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -3167,7 +3167,14 @@ const rootMutations = {
31673167

31683168
if (!externalSystem.apiKey.includes("*")) {
31693169
const truncatedKey = externalSystem.apiKey.slice(0, 5) + "********";
3170-
const apiKeyRef = graphileSecretRef(organizationId, truncatedKey);
3170+
const apiKeyRef = graphileSecretRef(
3171+
savedSystem.organization_id,
3172+
truncatedKey
3173+
);
3174+
await r
3175+
.knex("graphile_secrets.secrets")
3176+
.where({ ref: savedSystem.api_key_ref })
3177+
.del();
31713178
await getWorker().then(worker =>
31723179
worker.setSecret(apiKeyRef, externalSystem.apiKey)
31733180
);

0 commit comments

Comments
 (0)