chore: generate
This commit is contained in:
parent
3f174531b9
commit
a6e3afe048
3 changed files with 26 additions and 17 deletions
|
|
@ -35,7 +35,11 @@ let pendingOAuth: PendingOAuth | undefined
|
||||||
let oauthServerPort: number | undefined
|
let oauthServerPort: number | undefined
|
||||||
|
|
||||||
function normalizeAccount(input: string) {
|
function normalizeAccount(input: string) {
|
||||||
return input.trim().replace(/^https?:\/\//, "").replace(/\.snowflakecomputing\.com\/?$/, "").replace(/\/+$/, "")
|
return input
|
||||||
|
.trim()
|
||||||
|
.replace(/^https?:\/\//, "")
|
||||||
|
.replace(/\.snowflakecomputing\.com\/?$/, "")
|
||||||
|
.replace(/\/+$/, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateRandomString(length: number) {
|
function generateRandomString(length: number) {
|
||||||
|
|
@ -456,7 +460,9 @@ export async function SnowflakeCortexAuthPlugin(_input: PluginInput): Promise<Ho
|
||||||
}
|
}
|
||||||
|
|
||||||
const expiresSoon =
|
const expiresSoon =
|
||||||
!currentOauth.expires || !currentOauth.access || currentOauth.expires - Date.now() <= ACCESS_TOKEN_REFRESH_SKEW_MS
|
!currentOauth.expires ||
|
||||||
|
!currentOauth.access ||
|
||||||
|
currentOauth.expires - Date.now() <= ACCESS_TOKEN_REFRESH_SKEW_MS
|
||||||
|
|
||||||
if (expiresSoon) await refresh()
|
if (expiresSoon) await refresh()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -884,7 +884,8 @@ function custom(dep: CustomDep): Record<string, CustomLoader> {
|
||||||
// OAuth refresh + snowflake transformations in one place.
|
// OAuth refresh + snowflake transformations in one place.
|
||||||
// For env/config/API-key tokens, the provider fetch applies snowflake
|
// For env/config/API-key tokens, the provider fetch applies snowflake
|
||||||
// transformations directly.
|
// transformations directly.
|
||||||
const useOAuthHandler = oauthToken !== undefined && envToken === undefined && apiKeyToken === undefined && configToken === undefined
|
const useOAuthHandler =
|
||||||
|
oauthToken !== undefined && envToken === undefined && apiKeyToken === undefined && configToken === undefined
|
||||||
if (!useOAuthHandler) {
|
if (!useOAuthHandler) {
|
||||||
options.fetch = async (url: RequestInfo | URL, init?: RequestInit) => {
|
options.fetch = async (url: RequestInfo | URL, init?: RequestInit) => {
|
||||||
if (init?.body && typeof init.body === "string") {
|
if (init?.body && typeof init.body === "string") {
|
||||||
|
|
|
||||||
|
|
@ -106,13 +106,14 @@ describe("plugin.snowflake-cortex", () => {
|
||||||
try {
|
try {
|
||||||
const hooks = await SnowflakeCortexAuthPlugin(input)
|
const hooks = await SnowflakeCortexAuthPlugin(input)
|
||||||
const options = await hooks.auth!.loader!(
|
const options = await hooks.auth!.loader!(
|
||||||
async () => ({
|
async () =>
|
||||||
type: "oauth",
|
({
|
||||||
access: "access-expired",
|
type: "oauth",
|
||||||
refresh: "refresh-old",
|
access: "access-expired",
|
||||||
expires: 0,
|
refresh: "refresh-old",
|
||||||
accountId: "myorg-myaccount",
|
expires: 0,
|
||||||
}) as any,
|
accountId: "myorg-myaccount",
|
||||||
|
}) as any,
|
||||||
{} as any,
|
{} as any,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -139,13 +140,14 @@ describe("plugin.snowflake-cortex", () => {
|
||||||
const { input, getAuth, setCalls } = makeInput()
|
const { input, getAuth, setCalls } = makeInput()
|
||||||
const hooks = await SnowflakeCortexAuthPlugin(input)
|
const hooks = await SnowflakeCortexAuthPlugin(input)
|
||||||
const options = await hooks.auth!.loader!(
|
const options = await hooks.auth!.loader!(
|
||||||
async () => ({
|
async () =>
|
||||||
type: "oauth",
|
({
|
||||||
access: "access-stale",
|
type: "oauth",
|
||||||
refresh: "refresh-old",
|
access: "access-stale",
|
||||||
expires: Date.now() + 60 * 60 * 1000,
|
refresh: "refresh-old",
|
||||||
accountId: "myorg-myaccount",
|
expires: Date.now() + 60 * 60 * 1000,
|
||||||
}) as any,
|
accountId: "myorg-myaccount",
|
||||||
|
}) as any,
|
||||||
{} as any,
|
{} as any,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue