Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jdewinne committed May 16, 2024
1 parent 3ee872c commit ebd39ab
Showing 1 changed file with 29 additions and 37 deletions.
66 changes: 29 additions & 37 deletions create-customer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,59 @@
import * as core from "@actions/core";
import { VendorPortalApi, createCustomer } from "replicated-lib";
import * as core from '@actions/core';
import { VendorPortalApi, createCustomer } from 'replicated-lib';

import { parse } from "yaml";
import { parse } from 'yaml'

async function run() {
try {
const appSlug = core.getInput("app-slug");
const apiToken = core.getInput("api-token");
const name = core.getInput("customer-name");
const email = core.getInput("customer-email");
const licenseType = core.getInput("license-type");
const channelSlug = core.getInput("channel-slug");
const apiEndpoint = core.getInput("replicated-api-endpoint");
const expiresInDays: number = +(core.getInput("expires-in") || 0);
const entitlements = core.getInput("entitlements");

const appSlug = core.getInput('app-slug');
const apiToken = core.getInput('api-token')
const name = core.getInput('customer-name');
const email = core.getInput('customer-email');
const licenseType = core.getInput('license-type');
const channelSlug = core.getInput('channel-slug');
const apiEndpoint = core.getInput('replicated-api-endpoint')
const expiresInDays: number = +(core.getInput('expires-in') || 0);
const entitlements = core.getInput('entitlements');


// The default for isKotsInstallEnabled is undefined, which means it will not be set
// As such we can not use core.getBooleanInput
let isKotsInstallEnabled: boolean | undefined = undefined;
if (core.getInput("is-kots-install-enabled") !== "") {
isKotsInstallEnabled =
core.getInput("is-kots-install-enabled") === "true";
}

const apiClient = new VendorPortalApi();
apiClient.apiToken = apiToken;

if (apiEndpoint) {
apiClient.endpoint = apiEndpoint;
apiClient.endpoint = apiEndpoint
}

const entitlementsArray = processEntitlements(entitlements);
const customer = await createCustomer(
apiClient,
appSlug,
name,
email,
licenseType,
channelSlug,
expiresInDays,
entitlementsArray,
isKotsInstallEnabled
);
const entitlementsArray = processEntitlements(entitlements)
const customer = await createCustomer(apiClient, appSlug, name, email, licenseType, channelSlug, expiresInDays, entitlementsArray, isKotsInstallEnabled);

core.setOutput('customer-id', customer.customerId);
core.setOutput('license-id', customer.licenseId);
core.setOutput('license-file', customer.license);

core.setOutput("customer-id", customer.customerId);
core.setOutput("license-id", customer.licenseId);
core.setOutput("license-file", customer.license);
} catch (error) {
core.setFailed(error.message);
}
}

function processEntitlements(entitlements: string): [] | undefined {
if (entitlements) {
const entitlementsYAML = parse(entitlements);

const entitlementsYAML = parse(entitlements)
// for each entitlement in entitlementsYAML, convert to json and add to array
const entitlementsArray = entitlementsYAML.map((entitlement: any) => {
return { name: entitlement.name, value: entitlement.value };
});
return entitlementsArray;
return {name: entitlement.name, value: entitlement.value}
})
return entitlementsArray
}
return undefined;
return undefined
}

run();
run()

0 comments on commit ebd39ab

Please sign in to comment.