Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions src/actions/downloadCodeSite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { HostParameterEntry, IHostAbstractions } from "../host/IHostAbstractions";
import { InputValidator } from "../host/InputValidator";
import { authenticateEnvironment, clearAuthentication } from "../pac/auth/authenticate";
import createPacRunner from "../pac/createPacRunner";
import { RunnerParameters } from "../Parameters";
import { AuthCredentials } from "../pac/auth/authParameters";

export interface DownloadCodeSiteParameters {
credentials: AuthCredentials;
environmentUrl: string;
path: HostParameterEntry;
websiteId: HostParameterEntry;
overwrite: HostParameterEntry;
}

export async function downloadCodeSite(parameters: DownloadCodeSiteParameters, runnerParameters: RunnerParameters, host: IHostAbstractions): Promise<void> {
const logger = runnerParameters.logger;
const pac = createPacRunner(runnerParameters);

try {
const authenticateResult = await authenticateEnvironment(pac, parameters.credentials, parameters.environmentUrl, logger);
logger.log("The Authentication Result: " + authenticateResult);

const pacArgs = ["pages", "download-code-site"]
const validator = new InputValidator(host);

validator.pushInput(pacArgs, "--path", parameters.path);
validator.pushInput(pacArgs, "--webSiteId", parameters.websiteId);
validator.pushInput(pacArgs, "--overwrite", parameters.overwrite);

logger.log("Calling pac cli inputs: " + pacArgs.join(" "));
const pacResult = await pac(...pacArgs);
logger.log("DownloadCodeSite Action Result: " + pacResult);
} catch (error) {
logger.error(`failed: ${error instanceof Error ? error.message : error}`);
throw error;
} finally {
const clearAuthResult = await clearAuthentication(pac);
logger.log("The Clear Authentication Result: " + clearAuthResult);
}
}
2 changes: 2 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from "./whoAmI";
export * from "./importSolution";
export * from "./upgradeSolution";
export * from "./deleteEnvironment";
export * from "./downloadCodeSite";
export * from "./backupEnvironment";
export * from "./checkSolution";
export * from "./publishSolution";
Expand All @@ -17,6 +18,7 @@ export * from "./packSolution";
export * from "./unpackSolution";
export * from "./resetEnvironment";
export * from "./copyEnvironment";
export * from "./uploadCodeSite";
export * from "./uploadPaportal";
export * from "./downloadPaportal";
export * from "./cloneSolution";
Expand Down
41 changes: 41 additions & 0 deletions src/actions/uploadCodeSite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { HostParameterEntry, IHostAbstractions } from "../host/IHostAbstractions";
import { InputValidator } from "../host/InputValidator";
import { authenticateEnvironment, clearAuthentication } from "../pac/auth/authenticate";
import createPacRunner from "../pac/createPacRunner";
import { RunnerParameters } from "../Parameters";
import { AuthCredentials } from "../pac/auth/authParameters";

export interface UploadCodeSiteParameters {
credentials: AuthCredentials;
environmentUrl: string;
rootPath: HostParameterEntry;
compiledPath: HostParameterEntry;
siteName: HostParameterEntry;
}

export async function uploadCodeSite(parameters: UploadCodeSiteParameters, runnerParameters: RunnerParameters, host: IHostAbstractions): Promise<void> {
const logger = runnerParameters.logger;
const pac = createPacRunner(runnerParameters);

try {
const authenticateResult = await authenticateEnvironment(pac, parameters.credentials, parameters.environmentUrl, logger);
logger.log("The Authentication Result: " + authenticateResult);

const pacArgs = ["pages", "upload-code-site"]
const validator = new InputValidator(host);

validator.pushInput(pacArgs, "--rootPath", parameters.rootPath);
validator.pushInput(pacArgs, "--compiledPath", parameters.compiledPath);
validator.pushInput(pacArgs, "--siteName", parameters.siteName);

logger.log("Calling pac cli inputs: " + pacArgs.join(" "));
const pacResult = await pac(...pacArgs);
logger.log("UploadCodeSite Action Result: " + pacResult);
} catch (error) {
logger.error(`failed: ${error instanceof Error ? error.message : error}`);
throw error;
} finally {
const clearAuthResult = await clearAuthentication(pac);
logger.log("The Clear Authentication Result: " + clearAuthResult);
}
}
Loading