This repository has been archived by the owner on Feb 13, 2024. It is now read-only.
-
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
10 changed files
with
391 additions
and
3 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,72 @@ | ||
import * as vscode from 'vscode'; | ||
import * as path from 'path'; | ||
|
||
import { longRunning, showDuffleResult, refreshCredentialExplorer } from '../utils/host'; | ||
import * as duffle from '../duffle/duffle'; | ||
import { RepoBundle, RepoBundleRef } from '../duffle/duffle.objectmodel'; | ||
import { succeeded, map, Errorable } from '../utils/errorable'; | ||
import * as shell from '../utils/shell'; | ||
import { cantHappen } from '../utils/never'; | ||
import { promptBundle, BundleSelection, fileBundleSelection, repoBundleSelection } from '../utils/bundleselection'; | ||
|
||
export async function generateCredentials(target?: any): Promise<void> { | ||
if (!target) { | ||
return await generateCredentialsPrompted(); | ||
} | ||
if (target.scheme) { | ||
return await generateCredentialsForFile(target as vscode.Uri); | ||
} | ||
if (target.bundle) { | ||
return await generateCredentialsForRepoBundle((target as RepoBundleRef).bundle); | ||
} | ||
await vscode.window.showErrorMessage("Internal error: unexpected command target"); | ||
} | ||
|
||
async function generateCredentialsPrompted(): Promise<void> { | ||
const bundlePick = await promptBundle("Select the bundle to generate credentials for"); | ||
|
||
if (!bundlePick) { | ||
return; | ||
} | ||
|
||
return await generateCredentialsCore(bundlePick); | ||
} | ||
|
||
async function generateCredentialsForFile(file: vscode.Uri): Promise<void> { | ||
if (file.scheme !== 'file') { | ||
vscode.window.showErrorMessage("This command requires a filesystem bundle"); | ||
return; | ||
} | ||
return await generateCredentialsCore(fileBundleSelection(file)); | ||
} | ||
|
||
async function generateCredentialsForRepoBundle(bundle: RepoBundle): Promise<void> { | ||
return await generateCredentialsCore(repoBundleSelection(bundle)); | ||
} | ||
|
||
async function generateCredentialsCore(bundlePick: BundleSelection): Promise<void> { | ||
const generateResult = await generateCredentialsTo(bundlePick, bundlePick.label); | ||
|
||
if (succeeded(generateResult)) { | ||
await refreshCredentialExplorer(); | ||
} | ||
|
||
await showDuffleResult('generate credentials', (bundleId) => bundleId, generateResult); | ||
} | ||
|
||
async function generateCredentialsTo(bundlePick: BundleSelection, credentialSetName: string): Promise<Errorable<string>> { | ||
if (bundlePick.kind === 'folder') { | ||
const folderPath = bundlePick.path; | ||
const bundlePath = path.join(folderPath, "cnab", "bundle.json"); | ||
const generateResult = await longRunning(`Duffle generating credentials for ${bundlePath}`, | ||
() => duffle.generateCredentialsForFile(shell.shell, bundlePath, credentialSetName) | ||
); | ||
return map(generateResult, (_) => bundlePath); | ||
} else if (bundlePick.kind === 'repo') { | ||
const installResult = await longRunning(`Duffle generating credentials for ${bundlePick.bundle}`, | ||
() => duffle.generateCredentialsForBundle(shell.shell, bundlePick.bundle, credentialSetName) | ||
); | ||
return map(installResult, (_) => bundlePick.bundle); | ||
} | ||
return cantHappen(bundlePick); | ||
} |
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,27 @@ | ||
import * as path from 'path'; | ||
|
||
export function credentialSetPath(name: string): string { | ||
return path.join(credentialSetDir(), name + '.yaml'); | ||
} | ||
|
||
function home(): string { | ||
const envHome = process.env['DUFFLE_HOME']; | ||
if (envHome) { | ||
return envHome; | ||
} | ||
|
||
return path.join(osHome(), '.duffle'); | ||
} | ||
|
||
function osHome(): string { | ||
const homeEnvPath = process.env["HOME"]; | ||
if (homeEnvPath) { | ||
return homeEnvPath; | ||
} | ||
|
||
return process.env["USERPROFILE"] || ''; | ||
} | ||
|
||
function credentialSetDir(): string { | ||
return path.join(home(), 'credentials'); | ||
} |
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
Oops, something went wrong.