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

Wr/unset alias config #874

Merged
merged 29 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a06ce1f
fix: unset aliases and configs when org is deleted
WillieRuemmele Jun 26, 2023
b28ef5b
chore: flatMap change
WillieRuemmele Jun 26, 2023
992e8e5
Merge branch 'main' into wr/unsetAliasConfig
WillieRuemmele Jun 26, 2023
0436795
chore: bump jsforce
WillieRuemmele Jun 26, 2023
56b3ea1
chore: move it so that it works when deleting sandboxes as well
WillieRuemmele Jun 26, 2023
d907350
test: perf attempt
mshanemc Jun 27, 2023
e91f910
test: only perf tests for now
mshanemc Jun 27, 2023
a45fdd8
test: filename
mshanemc Jun 27, 2023
428d3b0
test: npm not yarn
mshanemc Jun 27, 2023
b04ec41
test: install deps
mshanemc Jun 27, 2023
d3a051a
test: logger specific tests
mshanemc Jun 27, 2023
ccb69d0
test: with cache
mshanemc Jun 28, 2023
8708626
test: no autopush
mshanemc Jun 28, 2023
5f9a3c2
test: new output file path
mshanemc Jun 28, 2023
edf6ad5
test: perf on windows
mshanemc Jun 28, 2023
e7258d6
style: remove example comments
mshanemc Jun 28, 2023
d706cee
test: os and name
mshanemc Jun 28, 2023
59d2994
test: revert os and name
mshanemc Jun 28, 2023
2587fdd
docs: readme and Benchmark names
mshanemc Jun 28, 2023
d62da01
test: restore all tests
mshanemc Jun 28, 2023
af4e071
test: use warn level to capture real (non-noop) traffic
mshanemc Jun 28, 2023
af8eb5d
chore: qa changes
WillieRuemmele Jun 28, 2023
b3960eb
chore: write only when needed
WillieRuemmele Jun 28, 2023
5c3abfb
test: fix UT
WillieRuemmele Jun 28, 2023
b3a3d11
test: fix UT
WillieRuemmele Jun 28, 2023
985bd0b
Merge branch 'sm/perf-metrics' into wr/unsetAliasConfig
mshanemc Jun 29, 2023
a548663
test: build before perf
mshanemc Jun 29, 2023
be3aee2
test: longer timeout for window lts-1
mshanemc Jun 29, 2023
8ebb20a
test: don't need cache
mshanemc Jun 29, 2023
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"faye": "^1.4.0",
"form-data": "^4.0.0",
"js2xmlparser": "^4.0.1",
"jsforce": "^2.0.0-beta.25",
"jsforce": "^2.0.0-beta.27",
"jsonwebtoken": "9.0.0",
"jszip": "3.10.1",
"proper-lockfile": "^4.1.2",
Expand Down Expand Up @@ -171,4 +171,4 @@
]
}
}
}
}
14 changes: 10 additions & 4 deletions src/config/configAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggregator.Op

// Initialized in loadProperties
private allowedProperties!: ConfigPropertyMeta[];
private localConfig?: Config;
private globalConfig: Config;
private readonly localConfig?: Config;
private readonly globalConfig: Config;
private envVars: Dictionary<string> = {};

/**
Expand Down Expand Up @@ -334,6 +334,13 @@ export class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggregator.Op
return this.config;
}

public async unsetByValue(key: string): Promise<void> {
this.localConfig?.getKeysByValue(key).map((k) => this.localConfig?.unset(k));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern about this is that parallel org deletes (think org list --clean) could possibly muck up the config files because of the well-known concurrency bug.

it would be nice if we only did write() if we knew that config had been modified.

config.unset return true if it does unset the thing, so you could do something like

const globalIsModified = this.globalConfig?.getKeysByValue(key).map((k) => this.globalConfig?.unset(k)).some(Boolean)

this.globalConfig?.getKeysByValue(key).map((k) => this.globalConfig?.unset(k));
await this.localConfig?.write();
await this.globalConfig?.write();
}

/**
* Get the config properties that are environment variables.
*/
Expand Down Expand Up @@ -412,8 +419,7 @@ export class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggregator.Op
configs.push(this.envVars);

const json: JsonMap = {};
const reduced = configs.filter(isJsonMap).reduce((acc: JsonMap, el: AnyJson) => merge(acc, el), json);
return reduced;
return configs.filter(isJsonMap).reduce((acc: JsonMap, el: AnyJson) => merge(acc, el), json);
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/org/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,16 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
* Will delete 'this' instance remotely and any files locally
*/
public async delete(): Promise<void> {
const username = ensureString(this.getUsername());

// unset any aliases referencing this org
const stateAgg = await StateAggregator.getInstance();
const existingAliases = stateAgg.aliases.getAll(username);
await stateAgg.aliases.unsetValuesAndSave(existingAliases);

// unset any configs referencing this org
[...existingAliases, username].flatMap((name) => this.configAggregator.unsetByValue(name));

if (await this.isSandbox()) {
await this.deleteSandbox();
} else {
Expand Down Expand Up @@ -1132,6 +1142,7 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
try {
const devHubConn = devHub.getConnection();
const username = this.getUsername();

const activeScratchOrgRecordId = (
await devHubConn.singleRecordQuery<{ Id: string }>(
`SELECT Id FROM ActiveScratchOrg WHERE SignupUsername='${username}'`
Expand Down
33 changes: 33 additions & 0 deletions test/unit/org/orgTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,39 @@ describe('Org Tests', () => {
}
});

it('should unset the alias and any configs', async () => {
const dev = await createOrgViaAuthInfo(testData.username);

const orgTestData = new MockTestOrgData();
const org = await createOrgViaAuthInfo(orgTestData.username, orgTestData);
const username = ensureString(org.getUsername());
$$.setConfigStubContents('Config', { contents: { [OrgConfigProperties.TARGET_ORG]: username } });
expect($$.getConfigStubContents('Config')).to.deep.equal({ 'target-org': username });
const stateAggregator = await StateAggregator.getInstance();

await stateAggregator.aliases.setAndSave('deleteThisAlias', username);
expect(stateAggregator.aliases.getUsername('deleteThisAlias')).to.equal(username);

const devHubQuery = stubMethod($$.SANDBOX, Connection.prototype, 'singleRecordQuery').resolves({
Id: orgTestData.orgId,
});
const devHubDelete = stubMethod($$.SANDBOX, Org.prototype, 'destroyScratchOrg').resolves();
$$.SANDBOX.stub(org, 'getDevHubOrg').resolves(dev);

await org.delete();

expect($$.getConfigStubContents('Config')).to.deep.equal({});

expect(stateAggregator.aliases.get(username)).to.be.null;
expect(devHubQuery.calledOnce).to.be.true;
expect(devHubQuery.firstCall.args[0]).to.equal(
`SELECT Id FROM ActiveScratchOrg WHERE SignupUsername='${orgTestData.username}'`
);

expect(devHubDelete.calledOnce).to.be.true;
expect(devHubDelete.firstCall.args[1]).to.equal(orgTestData.orgId);
});

it('should handle SingleRecordQueryErrors.NoRecords errors', async () => {
const dev = await createOrgViaAuthInfo();

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2976,10 +2976,10 @@ jsesc@^2.5.1:
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4"
integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==

jsforce@^2.0.0-beta.25:
version "2.0.0-beta.25"
resolved "https://registry.yarnpkg.com/jsforce/-/jsforce-2.0.0-beta.25.tgz#120a3999babf96ae18ab8f1232003d56588a9ca5"
integrity sha512-ZtzwJErI4SSJYWrGAw0mHEHPZRB4Idz0RiXHakCtEgEjEWt6JIDR4sNbWRHUzWHdEO4O61z2YSBvdOuag1hkWg==
jsforce@^2.0.0-beta.27:
version "2.0.0-beta.27"
resolved "https://registry.yarnpkg.com/jsforce/-/jsforce-2.0.0-beta.27.tgz#ba822b18b77bea4529491060a9b07bc1009735ac"
integrity sha512-d9dDWWeHwayRKPo8FJBAIUyk8sNXGSHwdUjR6al3yK0YKci27Jc1XfNaQTxEAuymHQJVaCb1gxTKqmA4uznFdQ==
dependencies:
"@babel/runtime" "^7.12.5"
"@babel/runtime-corejs3" "^7.12.5"
Expand Down