Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/publish/account.ts
6442 views
1
/*
2
* account.ts
3
*
4
* Copyright (C) 2022 Posit Software, PBC
5
*/
6
7
import { error } from "../deno_ral/log.ts";
8
9
import { prompt } from "cliffy/prompt/mod.ts";
10
import { Confirm } from "cliffy/prompt/confirm.ts";
11
12
import {
13
AccountToken,
14
AccountTokenType,
15
PublishProvider,
16
} from "./provider-types.ts";
17
18
export type AccountPrompt = "always" | "never" | "multiple";
19
20
export async function authorizePrompt(provider: PublishProvider) {
21
const result = await prompt([{
22
indent: "",
23
name: "confirmed",
24
message: "Authorize",
25
default: true,
26
hint:
27
`In order to publish to ${provider.description} you need to authorize your account.\n` +
28
` Please be sure you are logged into the correct ${provider.description} account in your\n` +
29
" default web browser, then press Enter or 'Y' to authorize.",
30
type: Confirm,
31
}]);
32
return !!result.confirmed;
33
}
34
35
export async function reauthorizePrompt(
36
provider: PublishProvider,
37
) {
38
const result = await prompt([{
39
indent: "",
40
name: "confirmed",
41
message: "Re-authorize account",
42
default: true,
43
hint:
44
`The authorization saved for ${provider.description} is no longer valid.\n` +
45
` Please be sure you are logged into the correct ${provider.description} account in your\n` +
46
" default web browser, then press Enter to re-authorize.",
47
type: Confirm,
48
}]);
49
return !!result.confirmed;
50
}
51
52
export async function handleUnauthorized(
53
provider: PublishProvider,
54
account: AccountToken,
55
) {
56
if (account.type === AccountTokenType.Environment) {
57
error(
58
`Unable to authenticate with the provided ${account.name}. Please be sure this token is valid.`,
59
);
60
return false;
61
} else if (account.type === AccountTokenType.Authorized) {
62
return await reauthorizePrompt(
63
provider,
64
);
65
}
66
}
67
68