Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apigee-templater-cli

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apigee-templater-cli - npm Package Compare versions

Comparing version 0.4.18 to 0.4.19

17

dist/cli.d.ts

@@ -0,1 +1,16 @@

/**
* Copyright 2022 Google LLC
*
* 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 'dotenv/config';

@@ -73,2 +88,3 @@ import { ApigeeTemplateService } from 'apigee-templater-module';

deploy: boolean;
deployServiceAccount: string;
environment: string;

@@ -79,2 +95,3 @@ filter: string;

targetUrl: string;
targetBigQueryTable: string;
verbose: boolean;

@@ -81,0 +98,0 @@ keyPath: string;

274

dist/cli.js
"use strict";
/**
* Copyright 2022 Google LLC
*
* 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.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -61,2 +76,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

'--deploy': Boolean,
'--deployServiceAccount': String,
'--environment': String,

@@ -67,2 +83,3 @@ '--filter': String,

'--targetUrl': String,
'--targetBigQueryTable': String,
'--verbose': Boolean,

@@ -74,2 +91,3 @@ '--keyPath': String,

'-d': '--deploy',
'-s': '--deployServiceAccount',
'-e': '--environment',

@@ -80,2 +98,3 @@ '-l': '--filter',

'-t': '--targetUrl',
'-q': '--targetBigQueryTable',
'-v': '--verbose',

@@ -85,15 +104,17 @@ '-k': '--keyPath',

}, {
argv: rawArgs.slice(2),
argv: rawArgs.slice(2)
});
return {
file: args['--file'] || "",
input: args['--input'] || "",
file: args['--file'] || '',
input: args['--input'] || '',
deploy: args['--deploy'] || false,
environment: args['--environment'] || "",
filter: args['--filter'] || "",
name: args['--name'] || "",
basePath: args['--basePath'] || "",
targetUrl: args['--targetUrl'] || "",
deployServiceAccount: args['--deployServiceAccount'] || '',
environment: args['--environment'] || '',
filter: args['--filter'] || '',
name: args['--name'] || '',
basePath: args['--basePath'] || '',
targetUrl: args['--targetUrl'] || '',
targetBigQueryTable: args['--targetBigQueryTable'] || '',
verbose: args['--verbose'] || false,
keyPath: args['--keyPath'] || "",
keyPath: args['--keyPath'] || '',
help: args['--help'] || false

@@ -116,3 +137,3 @@ };

transformer: (input) => {
return input.replace(/ /g, "-");
return input.replace(/ /g, '-');
}

@@ -135,3 +156,3 @@ });

name: 'targetUrl',
message: 'Which backend target should be called?',
message: 'Which backend target URL should be called?',
transformer: (input) => {

@@ -149,15 +170,5 @@ return `https://${input}`;

}
if (!options.keyPath) {
if (!options.environment) {
questions.push({
type: 'input',
name: 'keyPath',
message: 'No GOOGLE_APPLICATION_CREDENTIALS found, please enter a path to a GCP project JSON key:',
when: (answers) => {
return answers.deploy;
}
});
}
if (!options.environment) {
questions.push({
type: 'list',
name: 'environment',

@@ -167,12 +178,2 @@ message: 'Which Apigee X environment to you want to deploy to?',

return answers.deploy;
},
choices: (answers) => {
if (answers.keyPath)
process.env.GOOGLE_APPLICATION_CREDENTIALS = answers.keyPath;
this.apigeeService.getEnvironments().then((result) => {
return result;
}).catch(() => {
console.error(`${chalk_1.default.redBright("! Error:")} Invalid GCP service account key file passed, please pass a service account with Apigee deployment roles attached.`);
return [];
});
}

@@ -182,6 +183,8 @@ });

const answers = await inquirer_1.default.prompt(questions);
if (answers.basePath && !answers.basePath.startsWith("/"))
answers.basePath = "/" + answers.basePath;
if (answers.targetUrl && !answers.targetUrl.startsWith("https://"))
answers.targetUrl = "https://" + answers.targetUrl;
if (answers.basePath && !answers.basePath.startsWith('/')) {
answers.basePath = '/' + answers.basePath;
}
if (answers.targetUrl && !answers.targetUrl.startsWith('https://')) {
answers.targetUrl = 'https://' + answers.targetUrl;
}
return {

@@ -194,3 +197,3 @@ ...options,

environment: options.environment || answers.environment,
keyPath: options.keyPath || answers.keyPath,
keyPath: options.keyPath || answers.keyPath
};

@@ -202,10 +205,10 @@ }

printHelp() {
console.log("");
console.log(`${chalk_1.default.bold(chalk_1.default.blueBright("Simple examples:"))}`);
console.log(`apigee-template ${chalk_1.default.grey("# Start interactive mode to enter the parameters.")}`);
console.log(`apigee-template -n TestProxy -b /httpbin -t https://httpbin.org ${chalk_1.default.grey("# Create a proxy called TestProxy under the base path /test to https://httpbin.org > will produce a TestProxy.zip bundle.")}`);
console.log('');
console.log(`${chalk_1.default.bold(chalk_1.default.blueBright('Simple examples:'))}`);
console.log(`apigee-template ${chalk_1.default.grey('# Start interactive mode to enter the parameters.')}`);
console.log(`apigee-template -n TestProxy -b /httpbin -t https://httpbin.org ${chalk_1.default.grey('# Create a proxy called TestProxy under the base path /test to https://httpbin.org > will produce a TestProxy.zip bundle.')}`);
console.log(`apigee-template -n TestProxy -b /httpbin -t https://httpbin.org -d -e test1 ${chalk_1.default.grey("# Create a proxy called TestProxy and deploy to the Apigee X environment 'test1'.")}`);
console.log(`apigee-template -f ./PetStore.yaml -d -e test1 ${chalk_1.default.grey("# Create a proxy based on the PetStore.yaml file and deploy to environment 'test1'")}`);
console.log("");
console.log(`${chalk_1.default.bold(chalk_1.default.blueBright("All parameters:"))}`);
console.log('');
console.log(`${chalk_1.default.bold(chalk_1.default.blueBright('All parameters:'))}`);
for (const line of helpCommands) {

@@ -227,4 +230,4 @@ console.log(`${chalk_1.default.bold(chalk_1.default.green(line.name))}: ${chalk_1.default.grey(line.description)} `);

if (options.verbose)
this.logVerbose(JSON.stringify(options), "options:");
console.log(`${chalk_1.default.green(">")} ${chalk_1.default.bold(chalk_1.default.greenBright("Welcome to apigee-template"))}, use -h for more command line options. `);
this.logVerbose(JSON.stringify(options), 'options:');
console.log(`${chalk_1.default.green('>')} ${chalk_1.default.bold(chalk_1.default.greenBright('Welcome to apigee-template'))}, use -h for more command line options. `);
if (options.help) {

@@ -235,3 +238,3 @@ this.printHelp();

if (fs_1.default.existsSync(options.file)) {
options.input = fs_1.default.readFileSync(options.file, "utf-8");
options.input = fs_1.default.readFileSync(options.file, 'utf-8');
}

@@ -241,2 +244,5 @@ if (!options.input && !options.file) {

options.keyPath = process.env.GOOGLE_APPLICATION_CREDENTIALS;
// If a BigQuery table was passed in, set it to targetUrl as well to prevent prompts (we have our target)
if (options.targetBigQueryTable)
options.targetUrl = options.targetBigQueryTable;
try {

@@ -246,53 +252,83 @@ options = await this.promptForMissingOptions(options);

catch (error) {
console.error(`${chalk_1.default.redBright("! Error:")} Invalid GCP service account key file passed, please pass a service account with Apigee deployment roles attached.`);
console.log("hello");
console.error(`${chalk_1.default.redBright('! Error:')} Error during prompt for inputs, that's all we know.`);
if (options.verbose)
this.logVerbose(JSON.stringify(error), 'prompt error:');
}
const newInput = new apigee_templater_module_1.ApigeeTemplateInput({
name: options.name,
proxyEndpoints: [
{
name: "default",
basePath: options.basePath,
targetName: "default",
targetUrl: options.targetUrl
}
]
});
let newInput;
if (options.targetBigQueryTable)
newInput = new apigee_templater_module_1.ApigeeTemplateInput({
name: options.name,
profile: "bigquery",
endpoints: [
{
name: 'default',
basePath: options.basePath,
target: {
name: 'default',
table: options.targetBigQueryTable
}
}
]
});
else
newInput = new apigee_templater_module_1.ApigeeTemplateInput({
name: options.name,
profile: "default",
endpoints: [
{
name: 'default',
basePath: options.basePath,
target: {
name: 'default',
url: options.targetUrl
}
}
]
});
options.input = JSON.stringify(newInput);
}
const _proxyDir = ".";
const _proxyDir = '.';
if (options.filter) {
// users can add their own preprocessing filter scripts here
eval(fs_1.default.readFileSync(options.filter, "utf-8"));
// eslint-disable-next-line
eval(fs_1.default.readFileSync(options.filter, 'utf-8'));
}
if (options.verbose)
this.logVerbose(options.input, "template:");
this.logVerbose(options.input, 'template:');
this.apigeeGenerator.generateProxyFromString(options.input, _proxyDir).then((result) => {
if (result && result.template)
console.log(`${chalk_1.default.green(">")} Proxy ${chalk_1.default.bold(chalk_1.default.blue(result.template.name))} generated to ${chalk_1.default.magentaBright(chalk_1.default.bold(result.localPath))} in ${chalk_1.default.bold(chalk_1.default.green(Math.round(result.duration) + " milliseconds"))}.`);
if (result && result.template) {
console.log(`${chalk_1.default.green('>')} Proxy ${chalk_1.default.bold(chalk_1.default.blue(result.template.name))} generated to ${chalk_1.default.magentaBright(chalk_1.default.bold(result.localPath))} in ${chalk_1.default.bold(chalk_1.default.green(Math.round(result.duration) + ' milliseconds'))}.`);
}
if (options.deploy && !options.environment) {
console.error(`${chalk_1.default.redBright("! Error:")} No environment found to deploy to, please pass the -e parameter with an Apigee X environment.`);
console.error(`${chalk_1.default.redBright('! Error:')} No environment found to deploy to, please pass the -e parameter with an Apigee X environment.`);
}
else if (options.deploy && !process.env.GOOGLE_APPLICATION_CREDENTIALS) {
console.error(`${chalk_1.default.redBright("! Error:")} No GCP credentials found, please set the GOOGLE_APPLICATION_CREDENTIALS environment variable or use the -k parameter, see https://cloud.google.com/docs/authentication/getting-started for more information.`);
}
else if (options.deploy) {
const startTime = perf_hooks_1.performance.now();
if (result && result.template) {
this.apigeeService.updateProxy(result.template.name, _proxyDir + "/" + result.template.name + ".zip").then((updateResult) => {
this.apigeeService.updateProxy(result.template.name, _proxyDir + '/' + result.template.name + '.zip').then((updateResult) => {
if (updateResult && updateResult.revision) {
if (result && result.template)
this.apigeeService.deployProxyRevision(options.environment, result.template.name, updateResult.revision).then(() => {
if (result && result.template) {
this.apigeeService.deployProxyRevision(options.environment, result.template.name, updateResult.revision, options.deployServiceAccount).then(() => {
const endTime = perf_hooks_1.performance.now();
const duration = endTime - startTime;
if (result && result.template)
console.log(`${chalk_1.default.green(">")} Proxy ${chalk_1.default.bold(chalk_1.default.blue(result.template.name + " version " + updateResult.revision))} deployed to environment ${chalk_1.default.bold(chalk_1.default.magentaBright(options.environment))} in ${chalk_1.default.bold(chalk_1.default.green(Math.round(duration) + " milliseconds"))}.`);
}).catch(() => {
console.error(`${chalk_1.default.redBright("! Error:")} Error deploying proxy revision.`);
if (options.verbose)
this.logVerbose(JSON.stringify(result), 'deploy result:');
if (result && result.template) {
console.log(`${chalk_1.default.green('>')} Proxy ${chalk_1.default.bold(chalk_1.default.blue(result.template.name + ' version ' + updateResult.revision))} deployed to environment ${chalk_1.default.bold(chalk_1.default.magentaBright(options.environment))} in ${chalk_1.default.bold(chalk_1.default.green(Math.round(duration) + ' milliseconds'))}.`);
}
}).catch((error) => {
console.error(`${chalk_1.default.redBright('! Error:')} Error deploying proxy revision.`);
if (options.verbose)
this.logVerbose(JSON.stringify(error), 'deploy error:');
});
}
}
}).catch((error) => {
if (error && error.response && error.response.status && error.response.status == 400)
console.error(`${chalk_1.default.redBright("! Error:")} Error in proxy bundle definition, try importing manually for more detailed error information.`);
else
console.error(`${chalk_1.default.redBright("! Error:")} Error deploying proxy revision.`);
if (error && error.response && error.response.status && error.response.status === 400) {
console.error(`${chalk_1.default.redBright('! Error:')} Error in proxy bundle definition, try importing manually for more detailed error information.`);
}
else {
console.error(`${chalk_1.default.redBright('! Error:')} Error deploying proxy revision.`);
}
});

@@ -302,3 +338,3 @@ }

}).catch(() => {
console.error(`${chalk_1.default.redBright("! Error:")} Error templating proxy, invalid inputs given.`);
console.error(`${chalk_1.default.redBright('! Error:')} Error templating proxy, invalid inputs given.`);
process.exit();

@@ -316,4 +352,4 @@ });

if (label)
console.log(`${chalk_1.default.grey("> " + label)}`);
console.log(`${chalk_1.default.grey("> " + input)}`);
console.log(`${chalk_1.default.grey('> ' + label)}`);
console.log(`${chalk_1.default.grey('> ' + input)}`);
}

@@ -335,3 +371,3 @@ }

writable: true,
value: ""
value: ''
});

@@ -342,3 +378,3 @@ Object.defineProperty(this, "input", {

writable: true,
value: ""
value: ''
});

@@ -351,2 +387,8 @@ Object.defineProperty(this, "deploy", {

});
Object.defineProperty(this, "deployServiceAccount", {
enumerable: true,
configurable: true,
writable: true,
value: ''
});
Object.defineProperty(this, "environment", {

@@ -356,3 +398,3 @@ enumerable: true,

writable: true,
value: ""
value: ''
});

@@ -363,3 +405,3 @@ Object.defineProperty(this, "filter", {

writable: true,
value: ""
value: ''
});

@@ -370,3 +412,3 @@ Object.defineProperty(this, "name", {

writable: true,
value: ""
value: ''
});

@@ -377,3 +419,3 @@ Object.defineProperty(this, "basePath", {

writable: true,
value: ""
value: ''
});

@@ -384,4 +426,10 @@ Object.defineProperty(this, "targetUrl", {

writable: true,
value: ""
value: ''
});
Object.defineProperty(this, "targetBigQueryTable", {
enumerable: true,
configurable: true,
writable: true,
value: ''
});
Object.defineProperty(this, "verbose", {

@@ -397,3 +445,3 @@ enumerable: true,

writable: true,
value: ""
value: ''
});

@@ -416,41 +464,49 @@ Object.defineProperty(this, "help", {

{
name: "--file, -f",
description: "Path to a JSON or OpenAPIv3 YAML file with a proxy definition."
name: '--file, -f',
description: 'Path to a JSON or OpenAPIv3 YAML file with a proxy definition.'
},
{
name: "--input, -i",
description: "Same as --file, but with the input directly as a string in this parameter."
name: '--input, -i',
description: 'Same as --file, but with the input directly as a string in this parameter.'
},
{
name: "--deploy, -d",
description: "Boolean true or false if the generated proxy should also be deployed to an Apigee X environment."
name: '--deploy, -d',
description: 'Boolean true or false if the generated proxy should also be deployed to an Apigee X environment.'
},
{
name: "--environment, -e",
description: "If --deploy is true, the environment to deploy the proxy to."
name: '--deployServiceAccount, -s',
description: 'The Google Cloud service account email address to deploy with (used to authenticate or authorize target calls).'
},
{
name: "--filter, -l",
description: "Path to an optional javascript file that will be evaluated before any processing is done, can be used to add conversion plugins or inject other logic into the conversion."
name: '--environment, -e',
description: 'If --deploy is true, the environment to deploy the proxy to.'
},
{
name: "--name, -n",
description: "If no --file or --input parameters are specified, this can set the proxy name directly for a simple proxy."
name: '--filter, -l',
description: 'Path to an optional javascript file that will be evaluated before any processing is done, can be used to add conversion plugins or inject other logic into the conversion.'
},
{
name: "--basePath, -b",
description: "If no --file or --input parameters are specified, this can set the basePath directly."
name: '--name, -n',
description: 'If no --file or --input parameters are specified, this can set the proxy name directly for a simple proxy.'
},
{
name: "--targetUrl, t",
description: "If no --file or --input parameters are specified, this can set the target URL directly."
name: '--basePath, -b',
description: 'If no --file or --input parameters are specified, this can set the basePath directly.'
},
{
name: "--verbose, -v",
description: "If extra logging information should be printed during the conversion and deployment."
name: '--targetUrl, t',
description: 'If no --file or --input parameters are specified, this can set the target URL directly.'
},
{
name: "--keyPath, -k",
description: "If no GOOGLE_APPLICATION_CREDENTIALS are set to authorize the proxy deployment, this can point to a GCP service account JSON key file to use for authorization."
name: '--targetBigQueryTable, q',
description: 'If no --file or --input parameters are specified, this can set a target BigQuery table directly.'
},
{
name: '--verbose, -v',
description: 'If extra logging information should be printed during the conversion and deployment.'
},
{
name: '--keyPath, -k',
description: 'If no GOOGLE_APPLICATION_CREDENTIALS are set to authorize the proxy deployment, this can point to a GCP service account JSON key file to use for authorization.'
}
];
{
"name": "apigee-templater-cli",
"version": "0.4.18",
"version": "0.4.19",
"description": "A CLI to easily template and deploy Apigee proxies.",

@@ -28,4 +28,4 @@ "homepage": "https://github.com/tyayers/apigee-templater",

"dependencies": {
"apigee-templater-module": "^0.5.3",
"apigee-x-module": "^0.7.0",
"apigee-templater-module": "^0.6.0",
"apigee-x-module": "^0.7.2",
"arg": "^5.0.1",

@@ -43,2 +43,2 @@ "chalk": "^4.1.2",

}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc