Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/customers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ describe("Create Customer", () => {
await mockServer.forPost("/customer").once().thenReply(201, JSON.stringify(customerResponse));
await mockServer.forGet("/app/1234abcd/customer/5678efgh/license-download").once().thenReply(403);

const customer: Customer = await createCustomer(apiClient, "app-1", "testing", "testing@replicated.com", "test", "", 0);
const customer: Customer = await createCustomer(apiClient, {
appSlug: "app-1",
name: "testing",
email: "testing@replicated.com",
licenseType: "test"
});
expect(customer.name).toEqual("testing");
expect(customer.customerId).toEqual("5678efgh");
expect(customer.licenseId).toEqual("1234abcd");
Expand Down
77 changes: 69 additions & 8 deletions src/customers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ interface entitlementValue {
value: string;
}

export interface CreateCustomerOptions {
appSlug: string;
name: string;
licenseType: string;
email?: string;
channelSlug?: string;
expiresIn?: number;
entitlementValues?: entitlementValue[];
customId?: string;
isKotsInstallEnabled?: boolean;
isDevModeEnabled?: boolean;
isAirgapEnabled?: boolean;
isGitopsSupported?: boolean;
isSnapshotSupported?: boolean;
isHelmInstallEnabled?: boolean;
isKurlInstallEnabled?: boolean;
isEmbeddedClusterDownloadEnabled?: boolean;
isEmbeddedClusterMultinodeEnabled?: boolean;
isGeoaxisSupported?: boolean;
isIdentityServiceSupported?: boolean;
isInstallerSupportEnabled?: boolean;
isSupportBundleUploadEnabled?: boolean;
}

export class KubernetesDistribution {
k8sDistribution: string;
k8sVersion: string;
Expand All @@ -32,8 +56,9 @@ export class KubernetesDistribution {
isAirgap: boolean;
}

export async function createCustomer(vendorPortalApi: VendorPortalApi, appSlug: string, name: string, email: string, licenseType: string, channelSlug: string, expiresIn: number, entitlementValues?: entitlementValue[], isKotsInstallEnabled?: boolean, isDevModeEnabled?: boolean): Promise<Customer> {
export async function createCustomer(vendorPortalApi: VendorPortalApi, options: CreateCustomerOptions): Promise<Customer> {
try {
const { appSlug, name, licenseType, email, channelSlug, expiresIn, entitlementValues } = options;
const app = await getApplicationDetails(vendorPortalApi, appSlug);

console.log("Creating customer on appId " + app.id);
Expand All @@ -42,30 +67,66 @@ export async function createCustomer(vendorPortalApi: VendorPortalApi, appSlug:

// 1. create the customer
const createCustomerUri = `${vendorPortalApi.endpoint}/customer`;
let createCustomerReqBody = {
let createCustomerReqBody: Record<string, any> = {
name: name,
email: email,
type: licenseType,
app_id: app.id
};
if (isKotsInstallEnabled !== undefined) {
createCustomerReqBody["is_kots_install_enabled"] = isKotsInstallEnabled;
}
if (channelSlug) {
const channel = await getChannelDetails(vendorPortalApi, appSlug, { slug: channelSlug });
createCustomerReqBody["channel_id"] = channel.id;
}
// expiresIn is in days, if it's 0 or less, ignore it - non-expiring license
if (expiresIn > 0) {
if (expiresIn !== undefined && expiresIn > 0) {
const now = new Date();
const expiresAt = fromZonedTime(add(now, { days: expiresIn }), "UTC");
createCustomerReqBody["expires_at"] = expiresAt.toISOString();
}
if (entitlementValues) {
createCustomerReqBody["entitlementValues"] = entitlementValues;
}
if (isDevModeEnabled !== undefined) {
createCustomerReqBody["is_dev_mode_enabled"] = isDevModeEnabled;
if (options.customId !== undefined) {
createCustomerReqBody["custom_id"] = options.customId;
}
if (options.isKotsInstallEnabled !== undefined) {
createCustomerReqBody["is_kots_install_enabled"] = options.isKotsInstallEnabled;
}
if (options.isDevModeEnabled !== undefined) {
createCustomerReqBody["is_dev_mode_enabled"] = options.isDevModeEnabled;
}
if (options.isAirgapEnabled !== undefined) {
createCustomerReqBody["is_airgap_enabled"] = options.isAirgapEnabled;
}
if (options.isGitopsSupported !== undefined) {
createCustomerReqBody["is_gitops_supported"] = options.isGitopsSupported;
}
if (options.isSnapshotSupported !== undefined) {
createCustomerReqBody["is_snapshot_supported"] = options.isSnapshotSupported;
}
if (options.isHelmInstallEnabled !== undefined) {
createCustomerReqBody["is_helm_install_enabled"] = options.isHelmInstallEnabled;
}
if (options.isKurlInstallEnabled !== undefined) {
createCustomerReqBody["is_kurl_install_enabled"] = options.isKurlInstallEnabled;
}
if (options.isEmbeddedClusterDownloadEnabled !== undefined) {
createCustomerReqBody["is_embedded_cluster_download_enabled"] = options.isEmbeddedClusterDownloadEnabled;
}
if (options.isEmbeddedClusterMultinodeEnabled !== undefined) {
createCustomerReqBody["is_embedded_cluster_multinode_enabled"] = options.isEmbeddedClusterMultinodeEnabled;
}
if (options.isGeoaxisSupported !== undefined) {
createCustomerReqBody["is_geoaxis_supported"] = options.isGeoaxisSupported;
}
if (options.isIdentityServiceSupported !== undefined) {
createCustomerReqBody["is_identity_service_supported"] = options.isIdentityServiceSupported;
}
if (options.isInstallerSupportEnabled !== undefined) {
createCustomerReqBody["is_installer_support_enabled"] = options.isInstallerSupportEnabled;
}
if (options.isSupportBundleUploadEnabled !== undefined) {
createCustomerReqBody["is_support_bundle_upload_enabled"] = options.isSupportBundleUploadEnabled;
}

const createCustomerRes = await http.post(createCustomerUri, JSON.stringify(createCustomerReqBody));
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export { VendorPortalApi } from "./configuration";
export { getApplicationDetails } from "./applications";
export { Channel, createChannel, getChannelDetails, archiveChannel, pollForAirgapReleaseStatus, getDownloadUrlAirgapBuildRelease } from "./channels";
export { ClusterVersion, createCluster, createClusterWithLicense, pollForStatus, getKubeconfig, removeCluster, upgradeCluster, getClusterVersions, createAddonObjectStore, pollForAddonStatus, exposeClusterPort } from "./clusters";
export { KubernetesDistribution, CustomerSummary, archiveCustomer, createCustomer, getUsedKubernetesDistributions, listCustomersByName, listCustomersByEmail } from "./customers";
export { KubernetesDistribution, CustomerSummary, CreateCustomerOptions, archiveCustomer, createCustomer, getUsedKubernetesDistributions, listCustomersByName, listCustomersByEmail } from "./customers";
export { Release, CompatibilityResult, createRelease, createReleaseFromChart, promoteRelease, reportCompatibilityResult } from "./releases";