Skip to content

Commit

Permalink
feat: add service info cli (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
thantos authored Jan 3, 2023
1 parent 82d5d37 commit f613910
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/@eventual/aws-cdk/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export class Service extends Construct implements IGrantable {
parameterName: `/eventual/services/${this.serviceName}`,
stringValue: JSON.stringify({
apiEndpoint: this.api.gateway.apiEndpoint,
eventBusArn: this.events.bus.eventBusArn,
functions: {
orchestrator: this.workflows.orchestrator.functionName,
activityWorker: this.activities.worker.functionName,
Expand Down
2 changes: 2 additions & 0 deletions packages/@eventual/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { sendSignal } from "./commands/send-signal.js";
import { execution } from "./commands/execution.js";
import { publishEvents } from "./commands/publish-events.js";
import { configure } from "./commands/configure.js";
import { serviceInfo } from "./commands/service-info.js";

const argv = hideBin(process.argv);
const cli = yargs(argv).scriptName("eventual").strict();
Expand All @@ -24,6 +25,7 @@ const cli = yargs(argv).scriptName("eventual").strict();
publishEvents,
replay,
sendSignal,
serviceInfo,
services,
start,
timeline,
Expand Down
30 changes: 30 additions & 0 deletions packages/@eventual/cli/src/commands/service-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Argv } from "yargs";
import { serviceAction, setServiceOptions } from "../service-action.js";

export const serviceInfo = (yargs: Argv) =>
yargs.command(
"info",
"Get data about your service",
(yargs) => setServiceOptions(yargs, true),
serviceAction(
async (spinner, _service, _, serviceData) => {
spinner.start("Getting executions");
spinner.stop();
process.stdout.write(
[
`API Gateway: ${serviceData.apiEndpoint}`,
`Event Bus Arn: ${serviceData.eventBusArn}`,
].join("\n")
);
process.stdout.write("\n");
},
async (_service, _, serviceData) => {
process.stdout.write(
JSON.stringify({
apiEndpoint: serviceData.apiEndpoint,
eventBusArn: serviceData.eventBusArn,
}) + "\n"
);
}
)
);
26 changes: 19 additions & 7 deletions packages/@eventual/cli/src/service-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import { assumeCliRole } from "./role.js";
import {
getServiceData,
resolveRegion,
ServiceData,
tryResolveDefaultService,
} from "./service-data.js";

export type ServiceAction<T> = (
spinner: Ora,
serviceClient: EventualServiceClient,
args: Arguments<T & { service: string }>
args: Arguments<T & { service: string }>,
serviceData: ServiceData
) => Promise<void>;

export type ServiceJsonAction<T> = (
serviceClient: EventualServiceClient,
args: Arguments<T & { service: string }>
args: Arguments<T & { service: string }>,
serviceData: ServiceData
) => Promise<void>;

/**
Expand Down Expand Up @@ -52,12 +55,21 @@ export const serviceAction =
if (!jsonAction) {
throw new Error("Operation does not support --json.");
}
return jsonAction(serviceClient, { ...args, service: serviceName });
return jsonAction(
serviceClient,
{ ...args, service: serviceName },
serviceData
);
}
return await action(spinner, serviceClient, {
...args,
service: serviceName,
});
return await action(
spinner,
serviceClient,
{
...args,
service: serviceName,
},
serviceData
);
} catch (e: any) {
if (args.debug) {
styledConsole.error(util.inspect(e));
Expand Down
1 change: 1 addition & 0 deletions packages/@eventual/cli/src/service-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { styledConsole } from "./styled-console.js";
*/
export interface ServiceData {
apiEndpoint: string;
eventBusArn: string;
functions: {
orchestrator: string;
activityWorker: string;
Expand Down

0 comments on commit f613910

Please sign in to comment.