-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import { AuthInfo, ConfigAggregator, ConfigInfo, fs } from '@salesforce/core'; | ||
import { processWrapper } from './processWrapper'; | ||
|
||
/** | ||
* | ||
* @param hubAlias the alias of the devhub you'd like to use OR the resulting alias of the devhub that'll be authorized if using authUrl/jwt. Defaults to 'nutHub' | ||
* @param setDefault set the authorized hub to be the default. Defaults to false | ||
*/ | ||
export const hubAuth = async (hubAlias = 'nutHub', setAsDefault?: boolean): Promise<ConfigInfo | undefined> => { | ||
// do we have a configured hub already? If so, we're good | ||
const aggregator = await ConfigAggregator.create(); | ||
const configInfo = aggregator.getInfo('defaultdevhubusername'); | ||
if (configInfo) { | ||
return configInfo; | ||
} | ||
|
||
// if not, look around the environment | ||
// case 1: authUrl | ||
if (processWrapper.AUTH_URL) { | ||
// auth the hub, set as default with hubAlias | ||
const oauth2Options = AuthInfo.parseSfdxAuthUrl(processWrapper.AUTH_URL); | ||
const authInfo = await AuthInfo.create({ oauth2Options }); | ||
await authInfo.save(); | ||
// will set to the default. | ||
await authInfo.setAlias(hubAlias); | ||
// export the config | ||
if (setAsDefault) { | ||
await authInfo.setAsDefault({ | ||
defaultDevhubUsername: true, | ||
}); | ||
} | ||
return aggregator.getInfo('defaultdevhubusername'); | ||
} | ||
|
||
// case 2: jwt credentials | ||
if (processWrapper.JWT_CLIENT_ID && processWrapper.JWT_KEY && processWrapper.JWT_USERNAME) { | ||
const tmpKeyPath = 'tmpKeyPath'; | ||
await fs.writeFile(tmpKeyPath, processWrapper.JWT_KEY); | ||
|
||
// TODO: actually auth | ||
await fs.remove(tmpKeyPath); | ||
throw new Error('jwt not implemented yet'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { SfdcUrl } from '@salesforce/core'; | ||
|
||
export const processWrapper = { | ||
AUTH_URL: process.env.SFDX_AUTH_URL, | ||
JWT_KEY: process.env.JWT_KEY, | ||
JWT_USERNAME: process.env.JWT_USERNAME, | ||
JWT_CLIENT_ID: process.env.JWT_CLIENT_ID, | ||
JWT_INSTANCE: process.env.JWT_INSTANCE ?? SfdcUrl.PRODUCTION, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
describe('hubAuth', () => { | ||
it('works with existing defaultdevhub if provided'); | ||
it('auths from authurl in env'); | ||
it('auths from authurl and sets as default'); | ||
it('auths from jwt in env'); | ||
it('auths from jwt with custom hubAlias'); | ||
}); |