feat: add support for AWS Signature auth type (#4142)

Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
Co-authored-by: nivedin <nivedinp@gmail.com>
This commit is contained in:
Anwarul Islam
2024-08-30 14:30:13 +06:00
committed by GitHub
parent 5a2eed60c9
commit 703b71de2c
26 changed files with 1499 additions and 666 deletions

View File

@@ -1,18 +1,25 @@
import { defineVersion } from "verzod"
import { z } from "zod"
import { GQLHeader as GQLHeaderV1 } from "../../graphql/v/1"
import { GQLHeader as GQLHeaderV2 } from "../../graphql/v/6"
import { GQLHeader as V1_GQLHeader } from "../../graphql/v/1"
import { HoppRESTHeaders as V1_HoppRESTHeaders } from "../../rest/v/1"
import { HoppRESTHeaders as V2_HoppRESTHeaders } from "../../rest/v/7"
import { HoppRESTAuth } from "../../rest/v/7"
import { HoppGQLAuth } from "../../graphql/v/6"
import { HoppGQLAuth, GQLHeader as V2_GQLHeader } from "../../graphql/v/6"
import {
HoppRESTAuth,
HoppRESTHeaders as V2_HoppRESTHeaders,
} from "../../rest/v/7"
import { v2_baseCollectionSchema, V2_SCHEMA } from "./2"
const v3_baseCollectionSchema = v2_baseCollectionSchema.extend({
v: z.literal(3),
headers: z.union([V2_HoppRESTHeaders, z.array(GQLHeaderV2)]),
// AWS Signature Authorization type addition
auth: z.union([HoppRESTAuth, HoppGQLAuth]),
// `description` field addition under `headers`
headers: z.union([V2_HoppRESTHeaders, z.array(V2_GQLHeader)]),
})
type Input = z.input<typeof v3_baseCollectionSchema> & {
@@ -32,7 +39,7 @@ export default defineVersion({
initial: false,
schema: V3_SCHEMA,
up(old: z.infer<typeof V2_SCHEMA>) {
const headers = (old.headers as V1_HoppRESTHeaders | GQLHeaderV1[]).map(
const headers = (old.headers as V1_HoppRESTHeaders | V1_GQLHeader[]).map(
(header) => ({
...header,
description: "",

View File

@@ -13,12 +13,11 @@ export {
HoppGQLAuthInherit,
HoppGQLAuthNone,
} from "./v/2"
export { GQLHeader } from "./v/6"
export { HoppGQLAuth, HoppGQLAuthOAuth2 } from "./v/6"
export { HoppGQLAuthAPIKey } from "./v/4"
export { GQLHeader, HoppGQLAuth, HoppGQLAuthOAuth2 } from "./v/6"
export const GQL_REQ_SCHEMA_VERSION = 6
const versionedObject = z.object({

View File

@@ -1,33 +1,21 @@
import { defineVersion } from "verzod"
import { z } from "zod"
import { V5_SCHEMA } from "./5"
import { HoppRESTAuthOAuth2 } from "./../../rest/v/7"
import { HoppRESTAuthAWSSignature } from "./../../rest/v/7"
import {
HoppGQLAuthAPIKey,
HoppGQLAuthBasic,
HoppGQLAuthBearer,
HoppGQLAuthInherit,
HoppGQLAuthNone,
} from "./2"
import { HoppGQLAuthAPIKey } from "./4"
import { HoppGQLAuthOAuth2, V5_SCHEMA } from "./5"
export { HoppRESTAuthOAuth2 as HoppGQLAuthOAuth2 } from "../../rest/v/7"
export const HoppGQLAuth = z
.discriminatedUnion("authType", [
HoppGQLAuthNone,
HoppGQLAuthInherit,
HoppGQLAuthBasic,
HoppGQLAuthBearer,
HoppGQLAuthAPIKey,
HoppRESTAuthOAuth2, // both rest and gql have the same auth type for oauth2
])
.and(
z.object({
authActive: z.boolean(),
})
)
// Both REST & GQL have the same schema definition for AWS Signature Authorization type
export const HoppGQLAuthAWSSignature = HoppRESTAuthAWSSignature
export type HoppGQLAuth = z.infer<typeof HoppGQLAuth>
export type HoppGQLAuthAWSSignature = z.infer<typeof HoppGQLAuthAWSSignature>
export const GQLHeader = z.object({
key: z.string().catch(""),
@@ -38,10 +26,28 @@ export const GQLHeader = z.object({
export type GQLHeader = z.infer<typeof GQLHeader>
export const HoppGQLAuth = z
.discriminatedUnion("authType", [
HoppGQLAuthNone,
HoppGQLAuthInherit,
HoppGQLAuthBasic,
HoppGQLAuthBearer,
HoppGQLAuthOAuth2,
HoppGQLAuthAPIKey,
HoppGQLAuthAWSSignature,
])
.and(
z.object({
authActive: z.boolean(),
})
)
export type HoppGQLAuth = z.infer<typeof HoppGQLAuth>
export const V6_SCHEMA = V5_SCHEMA.extend({
v: z.literal(6),
headers: z.array(GQLHeader).catch([]),
auth: HoppGQLAuth,
headers: z.array(GQLHeader).catch([]),
})
export default defineVersion({

View File

@@ -8,15 +8,14 @@ import { lodashIsEqualEq, mapThenEq, undefinedEq } from "../utils/eq"
import V0_VERSION from "./v/0"
import V1_VERSION from "./v/1"
import V2_VERSION from "./v/2"
import V2_VERSION, { HoppRESTRequestVariables } from "./v/2"
import V3_VERSION from "./v/3"
import V4_VERSION from "./v/4"
import V5_VERSION from "./v/5"
import V6_VERSION, { HoppRESTReqBody } from "./v/6"
import V7_VERSION, { HoppRESTAuth } from "./v/7"
import { HoppRESTHeaders, HoppRESTParams } from "./v/7"
import { HoppRESTRequestVariables } from "./v/2"
import { HoppRESTParams, HoppRESTHeaders } from "./v/7"
export * from "./content-types"
@@ -28,22 +27,24 @@ export {
HoppRESTAuthNone,
HoppRESTReqBodyFormData,
} from "./v/1"
export {
ClientCredentialsGrantTypeParams,
ImplicitOauthFlowParams,
PasswordGrantTypeParams,
} from "./v/3"
export { AuthCodeGrantTypeParams } from "./v/5"
export { HoppRESTAuthOAuth2, HoppRESTAuth } from "./v/7"
export { HoppRESTRequestVariables } from "./v/2"
export { HoppRESTAuthAPIKey } from "./v/4"
export { HoppRESTRequestVariables } from "./v/2"
export { AuthCodeGrantTypeParams } from "./v/5"
export { HoppRESTReqBody } from "./v/6"
export { HoppRESTHeaders } from "./v/7"
export {
HoppRESTAuth,
HoppRESTAuthAWSSignature,
HoppRESTAuthOAuth2,
HoppRESTHeaders,
HoppRESTParams,
} from "./v/7"
const versionedObject = z.object({
// v is a stringified number

View File

@@ -1,6 +1,12 @@
import { defineVersion } from "verzod"
import { z } from "zod"
import { defineVersion } from "verzod"
import {
HoppRESTAuthAPIKey,
HoppRESTAuthBasic,
HoppRESTAuthBearer,
HoppRESTAuthInherit,
HoppRESTAuthNone,
} from "./1"
import { V6_SCHEMA } from "./6"
import { AuthCodeGrantTypeParams as AuthCodeGrantTypeParamsOld } from "./5"
@@ -10,13 +16,6 @@ import {
ImplicitOauthFlowParams,
PasswordGrantTypeParams,
} from "./3"
import {
HoppRESTAuthAPIKey,
HoppRESTAuthBasic,
HoppRESTAuthBearer,
HoppRESTAuthInherit,
HoppRESTAuthNone,
} from "./1"
// Add refreshToken to all grant types except Implicit
export const AuthCodeGrantTypeParams = AuthCodeGrantTypeParamsOld.extend({
@@ -36,23 +35,6 @@ export const HoppRESTAuthOAuth2 = z.object({
export type HoppRESTAuthOAuth2 = z.infer<typeof HoppRESTAuthOAuth2>
export const HoppRESTAuth = z
.discriminatedUnion("authType", [
HoppRESTAuthNone,
HoppRESTAuthInherit,
HoppRESTAuthBasic,
HoppRESTAuthBearer,
HoppRESTAuthOAuth2,
HoppRESTAuthAPIKey,
])
.and(
z.object({
authActive: z.boolean(),
})
)
export type HoppRESTAuth = z.infer<typeof HoppRESTAuth>
export const HoppRESTParams = z.array(
z.object({
key: z.string().catch(""),
@@ -75,6 +57,41 @@ export const HoppRESTHeaders = z.array(
export type HoppRESTHeaders = z.infer<typeof HoppRESTHeaders>
// in this new version, we add a new auth type for AWS Signature
// this auth type is used for AWS Signature V5 authentication
// it requires the user to provide the access key id, secret access key, region, service name, and service token
export const HoppRESTAuthAWSSignature = z.object({
authType: z.literal("aws-signature"),
accessKey: z.string().catch(""),
secretKey: z.string().catch(""),
region: z.string().catch(""),
serviceName: z.string().catch(""),
serviceToken: z.string().optional(),
signature: z.object({}).optional(),
addTo: z.enum(["HEADERS", "QUERY_PARAMS"]).catch("HEADERS"),
})
export type HoppRESTAuthAWSSignature = z.infer<typeof HoppRESTAuthAWSSignature>
export const HoppRESTAuth = z
.discriminatedUnion("authType", [
HoppRESTAuthNone,
HoppRESTAuthInherit,
HoppRESTAuthBasic,
HoppRESTAuthBearer,
HoppRESTAuthOAuth2,
HoppRESTAuthAPIKey,
HoppRESTAuthAWSSignature,
])
.and(
z.object({
authActive: z.boolean(),
})
)
export type HoppRESTAuth = z.infer<typeof HoppRESTAuth>
export const V7_SCHEMA = V6_SCHEMA.extend({
v: z.literal("7"),
params: HoppRESTParams,