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

Post-merge review of #3356 #3379

Closed
3 tasks done
eamodio opened this issue Jul 8, 2024 · 5 comments
Closed
3 tasks done

Post-merge review of #3356 #3379

eamodio opened this issue Jul 8, 2024 · 5 comments
Assignees
Labels
Milestone

Comments

@eamodio
Copy link
Member

eamodio commented Jul 8, 2024

Review of #3356

  • Can we consolidate the following to hide that complexity inside the integration.connect() call?

    let connected = await integration.connect();
    if (!connected) {
    if (isSupportedCloudIntegrationId(integration.id)) {
    await this.container.integrations.manageCloudIntegrations(
    { integrationId: integration.id, skipIfConnected: true },
    {
    source: 'remoteProvider',
    detail: {
    action: 'connect',
    integration: integration.id,
    },
    },
    );
    }
    connected = await integration.connect();

    let connected = integration.maybeConnected ?? (await integration.isConnected());
    if (!connected) {
    if (isSupportedCloudIntegrationId(integration.id)) {
    await this.container.integrations.manageCloudIntegrations(
    { integrationId: integration.id },
    {
    source: 'launchpad',
    detail: {
    action: 'connect',
    integration: integration.id,
    },
    },
    );
    }
    connected = await integration.connect();
    }

  • Suggest changing the notion of "secret" to "session"/"stored session"/"auth":

    protected async deleteSecret(key: SecretKeys) {
    await this.container.storage.deleteSecret(key);
    }
    protected async writeSecret(key: SecretKeys, session: AuthenticationSession | StoredSession) {
    await this.container.storage.storeSecret(key, JSON.stringify(session));
    }
    protected async readSecret(key: SecretKeys, ignoreErrors: boolean): Promise<StoredSession | undefined> {
    let storedSession: StoredSession | undefined;
    try {
    const sessionJSON = await this.container.storage.getSecret(key);
    if (sessionJSON) {
    storedSession = JSON.parse(sessionJSON);
    }
    } catch (ex) {
    try {
    await this.deleteSecret(key);
    } catch {}
    if (ignoreErrors) {
    throw ex;
    }
    }
    return storedSession;
    }

  • Restrict the key params to be a subset of SecretKeys to avoid something else getting in there

    protected async deleteSecret(key: SecretKeys) {
    await this.container.storage.deleteSecret(key);
    }
    protected async writeSecret(key: SecretKeys, session: AuthenticationSession | StoredSession) {
    await this.container.storage.storeSecret(key, JSON.stringify(session));
    }
    protected async readSecret(key: SecretKeys, ignoreErrors: boolean): Promise<StoredSession | undefined> {
    let storedSession: StoredSession | undefined;
    try {
    const sessionJSON = await this.container.storage.getSecret(key);
    if (sessionJSON) {
    storedSession = JSON.parse(sessionJSON);
    }
    } catch (ex) {
    try {
    await this.deleteSecret(key);
    } catch {}
    if (ignoreErrors) {
    throw ex;
    }
    }
    return storedSession;
    }

  • Generally avoid Promise.all and use Promose.allSettled when we want to wait for everything -- as Promise.all will throw on the first rejected promise

https://gitkraken.atlassian.net/browse/GLVSC-591

@eamodio eamodio added this to the 15.3 milestone Jul 8, 2024
@sergeibbb
Copy link
Member

sergeibbb commented Jul 9, 2024

@eamodio

Suggest changing the notion of "secret" to "session"/"stored session"/"auth":

I'm taking "auth". I pick anything but "session", because there is a layer of "[actOn]Session" methods that call to "[actOn]Secret" methods (that are kind of a lower level), that's why I took a different word for that.

@sergeibbb
Copy link
Member

@eamodio

Restrict the key params to be a subset of SecretKeys to avoid something else getting in there

Do you mean adding a check on its value at runtime?

@eamodio
Copy link
Member Author

eamodio commented Jul 9, 2024

@eamodio

Restrict the key params to be a subset of SecretKeys to avoid something else getting in there

Do you mean adding a check on its value at runtime?

More to just create a restricted type, e.g.

export type SecretKeys =
	| `gitlens.${AIProviders}.key`
	| `gitlens.plus.auth:${Environment}`
	| IntegrationAuthenticationKeys;

export type IntegrationAuthenticationKeys =
	| `gitlens.integration.auth:${IntegrationId}|${string}`
	| `gitlens.integration.auth.cloud:${IntegrationId}|${string}`;

And then use that new type

@sergeibbb
Copy link
Member

More to just create a restricted type

ok. that's clear

sergeibbb added a commit that referenced this issue Jul 26, 2024
sergeibbb added a commit that referenced this issue Jul 26, 2024
(to "write/read/delete StoredSession") GLVSC-591 #3379
sergeibbb added a commit that referenced this issue Jul 26, 2024
sergeibbb added a commit that referenced this issue Jul 26, 2024
to avoid something else getting in there
GLVSC-591 #3428 #3379
sergeibbb added a commit that referenced this issue Jul 26, 2024
sergeibbb added a commit that referenced this issue Jul 26, 2024
to avoid something else getting in there
GLVSC-591 #3428
Closes #3379
sergeibbb added a commit that referenced this issue Jul 26, 2024
sergeibbb added a commit that referenced this issue Jul 26, 2024
(to "write/read/delete StoredSession") GLVSC-591 #3379
sergeibbb added a commit that referenced this issue Jul 26, 2024
(to "write/read/delete StoredSession") GLVSC-591 #3379
@eamodio eamodio closed this as completed Jul 27, 2024
sergeibbb added a commit that referenced this issue Jul 29, 2024
(to "write/read/delete StoredSession") GLVSC-591 #3379
sergeibbb added a commit that referenced this issue Jul 29, 2024
sergeibbb added a commit that referenced this issue Jul 29, 2024
to avoid something else getting in there
GLVSC-591 #3428
Closes #3379
sergeibbb added a commit that referenced this issue Jul 29, 2024
@axosoft-ramint axosoft-ramint added pending-release Resolved but not yet released to the stable edition verified ✔ Verified and removed pending-release Resolved but not yet released to the stable edition labels Aug 14, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants