diff --git a/examples/apikeysource/Pulumi.yaml b/examples/apikeysource/Pulumi.yaml new file mode 100644 index 0000000..968c332 --- /dev/null +++ b/examples/apikeysource/Pulumi.yaml @@ -0,0 +1,3 @@ +name: apigateway-apikeysource +runtime: nodejs +description: Testing the `akikeysource for `API`. diff --git a/examples/apikeysource/data.ts b/examples/apikeysource/data.ts new file mode 100644 index 0000000..b772bdb --- /dev/null +++ b/examples/apikeysource/data.ts @@ -0,0 +1,15 @@ +// Copyright 2023, Pulumi Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export const apikeysource = "HEADER"; \ No newline at end of file diff --git a/examples/apikeysource/index.ts b/examples/apikeysource/index.ts new file mode 100644 index 0000000..f648e60 --- /dev/null +++ b/examples/apikeysource/index.ts @@ -0,0 +1,48 @@ +// Copyright 2023, Pulumi Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import * as pulumi from "@pulumi/pulumi"; +import * as aws from "@pulumi/aws"; +import * as apigateway from "@pulumi/aws-apigateway"; +import * as data from "./data"; + +const f = new aws.lambda.CallbackFunction("f", { + callback: async (ev, ctx) => { + console.log(JSON.stringify(ev)); + return { + statusCode: 200, + body: "goodbye", + }; + }, +}); + +const api = new apigateway.RestAPI("authorizer-api", { + apiKeySource: data.apikeysource, + routes: [{ + path: "/", + method: "GET", + eventHandler: f, + }], +}, { version: "" }); + + +// TODO[pulumi/pulumi-aws-apigateway#111]: The `api` output is (incorrectly) a string not an object +// so we cannot read it's output. Workaround this by looking up the API by name. +var apiRead: any = {}; +if (!pulumi.runtime.isDryRun()) { + apiRead = aws.apigateway.getRestApiOutput({ + name: api.url.apply(_ => "authorizer-api"), + }); +} +export const apiKeySource = apiRead.apiKeySource; \ No newline at end of file diff --git a/examples/apikeysource/package.json b/examples/apikeysource/package.json new file mode 100644 index 0000000..44e59d7 --- /dev/null +++ b/examples/apikeysource/package.json @@ -0,0 +1,16 @@ +{ + "name": "api", + "version": "0.0.1", + "license": "Apache-2.0", + "scripts": { + "build": "tsc" + }, + "dependencies": { + "@pulumi/aws": "^6.0.0", + "@pulumi/aws-apigateway": "1.1.0-alpha.3", + "@pulumi/pulumi": "^3.3.1" + }, + "devDependencies": { + "@types/node": "^8.0.0" + } +} diff --git a/examples/apikeysource/step2/data.ts b/examples/apikeysource/step2/data.ts new file mode 100644 index 0000000..c29e617 --- /dev/null +++ b/examples/apikeysource/step2/data.ts @@ -0,0 +1,15 @@ +// Copyright 2023, Pulumi Corporation. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export const apikeysource = "AUTHORIZER"; \ No newline at end of file diff --git a/examples/apikeysource/tsconfig.json b/examples/apikeysource/tsconfig.json new file mode 100644 index 0000000..ab65afa --- /dev/null +++ b/examples/apikeysource/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "strict": true, + "outDir": "bin", + "target": "es2016", + "module": "commonjs", + "moduleResolution": "node", + "sourceMap": true, + "experimentalDecorators": true, + "pretty": true, + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.ts" + ] +} diff --git a/examples/examples_nodejs_test.go b/examples/examples_nodejs_test.go index aebf3a3..599c10b 100644 --- a/examples/examples_nodejs_test.go +++ b/examples/examples_nodejs_test.go @@ -1,13 +1,14 @@ // Copyright 2016-2020, Pulumi Corporation. All rights reserved. -//go:build nodejs || all -// +build nodejs all package examples import ( - "github.com/pulumi/pulumi/pkg/v3/testing/integration" + "path" "path/filepath" "testing" + + "github.com/pulumi/pulumi/pkg/v3/testing/integration" + "github.com/stretchr/testify/assert" ) func TestSimpleTs(t *testing.T) { @@ -20,6 +21,25 @@ func TestSimpleTs(t *testing.T) { integration.ProgramTest(t, &test) } +func TestAccApiKeySource(t *testing.T) { + test := getBaseOptions(t). + With(integration.ProgramTestOptions{ + Dir: path.Join(getCwd(t), "./apikeysource"), + EditDirs: []integration.EditDir{ + { + Dir: "./apikeysource/step2", + Additive: true, + ExtraRuntimeValidation: func(t *testing.T, stack integration.RuntimeValidationStackInfo) { + apiKeySource := stack.Outputs["apiKeySource"].(string) + assert.Equal(t, "AUTHORIZER", apiKeySource) + }, + }, + }, + }) + + integration.ProgramTest(t, &test) +} + func getJSBaseOptions(t *testing.T) integration.ProgramTestOptions { base := getBaseOptions(t) baseJS := base.With(integration.ProgramTestOptions{ diff --git a/examples/examples_test.go b/examples/examples_test.go index bd63a72..a23a7b5 100644 --- a/examples/examples_test.go +++ b/examples/examples_test.go @@ -22,7 +22,10 @@ func getBaseOptions(t *testing.T) integration.ProgramTestOptions { awsRegion := getRegion(t) return integration.ProgramTestOptions{ SkipRefresh: true, - Quick: true, + Quick: true, + Dependencies: []string{ + "@pulumi/aws-apigateway", + }, Config: map[string]string{ "aws:region": awsRegion, }, diff --git a/provider/cmd/pulumi-resource-aws-apigateway/apigateway/api.ts b/provider/cmd/pulumi-resource-aws-apigateway/apigateway/api.ts index 55ae5f3..84bdd8b 100644 --- a/provider/cmd/pulumi-resource-aws-apigateway/apigateway/api.ts +++ b/provider/cmd/pulumi-resource-aws-apigateway/apigateway/api.ts @@ -660,6 +660,9 @@ export function createAPI( name: ifUndefined(restApiArgs.name, title), binaryMediaTypes: ifUndefined(args.binaryMediaTypes, ["*/*"]), body: swaggerString, + // We pass this in directly, because setting it in the Swagger doesn't cause + // it to take affect, it must be passed directly to the RestAPI constructor as well. + apiKeySource: args.apiKeySource, }, { parent } );