-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |