Skip to content
Open
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
62 changes: 62 additions & 0 deletions KeeperSdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export {
AuditReportErrorCode,
ActionReportErrorCode,
PasswordReportErrorCode,
PamErrorCode,
KEEPER_PUBLIC_HOSTS,
isBoolean,
isString,
Expand Down Expand Up @@ -652,6 +653,67 @@ export type {
NsfResolvedShareRecipient,
} from './nestedShareFolders'

export {
PamManager,
GatewayManager,
listGateways,
formatGatewaysTable,
renderGatewaysAsciiTable,
formatGatewaysJson,
formatGatewaysOutput,
createGateway,
formatCreateGatewayOutput,
editGateway,
formatEditGatewayOutput,
GatewayListFormat,
GatewayStatus,
GatewayConfigInitFormat,
KSM_APP_RECORD_VERSION,
APP_NOT_ACCESSIBLE_LABEL,
KSM_CLIENT_ID_MESSAGE,
DEFAULT_GATEWAY_TOKEN_EXPIRES_IN_MIN,
MAX_GATEWAY_TOKEN_EXPIRES_IN_MIN,
EMPTY_GATEWAYS_MESSAGE,
GATEWAY_LIST_DEFAULT_HEADERS,
GATEWAY_LIST_VERBOSE_HEADERS,
getKeeperRouterBaseUrl,
webSafeUidFromBytes,
toFiniteNumber,
formatTimestampMs,
parseGatewayVersionString,
getKsmApplicationDisplayInfo,
resolveKsmApplication,
getKeeperRegionAbbreviation,
formatGatewayOneTimeToken,
findEnterpriseGatewayByUidOrName,
groupOnlineGatewaysByControllerUid,
isKeeperRouterConnectionError,
} from './pam'
export type {
ListGatewaysOptions,
GatewayCounts,
GatewayOsMetadata,
GatewayVersionParts,
GatewayPoolInstance,
GatewayListRow,
GatewayConnectivityStatus,
ListGatewaysResult,
FormattedGatewaysTable,
FormatGatewaysTableOptions,
RenderGatewaysAsciiTableOptions,
GatewayListFormatInput,
GatewayConfigInitFormatInput,
KsmApplicationDisplayInfo,
ResolvedKsmApplication,
CreateGatewayInput,
CreateGatewayResult,
EditGatewayInput,
EditGatewayResult,
GatewayJsonPoolInstance,
GatewayJsonEntry,
GatewaysJsonPayload,
} from './pam'

export type {
DRecord,
DRecordMetadata,
Expand Down
73 changes: 73 additions & 0 deletions KeeperSdk/src/pam/PamManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import type { Auth } from '@keeper-security/keeperapi'
import type { InMemoryStorage } from '../storage/InMemoryStorage'
import { GatewayManager } from './gateway/GatewayManager'
import type {
CreateGatewayInput,
CreateGatewayResult,
EditGatewayInput,
EditGatewayResult,
FormatGatewaysTableOptions,
FormattedGatewaysTable,
ListGatewaysOptions,
ListGatewaysResult,
RenderGatewaysAsciiTableOptions,
} from './gateway/gatewayTypes'

export type AuthProvider = () => Auth

export class PamManager {
private readonly gatewayManager: GatewayManager

constructor(storage: InMemoryStorage, authProvider: AuthProvider) {
this.gatewayManager = new GatewayManager(storage, authProvider)
}

public getGatewayManager(): GatewayManager {
return this.gatewayManager
}

public async listGateways(options: ListGatewaysOptions = {}): Promise<ListGatewaysResult> {
return this.gatewayManager.listGateways(options)
}

public async createGateway(input: CreateGatewayInput & { returnValue: true }): Promise<string>
public async createGateway(input: CreateGatewayInput & { returnValue?: false }): Promise<CreateGatewayResult>
public async createGateway(input: CreateGatewayInput): Promise<CreateGatewayResult | string>
public async createGateway(input: CreateGatewayInput): Promise<CreateGatewayResult | string> {
return this.gatewayManager.createGateway(input)
}

public formatCreateGatewayOutput(result: CreateGatewayResult): string {
return this.gatewayManager.formatCreateGatewayOutput(result)
}

public async editGateway(input: EditGatewayInput): Promise<EditGatewayResult> {
return this.gatewayManager.editGateway(input)
}

public formatEditGatewayOutput(result: EditGatewayResult): string {
return this.gatewayManager.formatEditGatewayOutput(result)
}

public formatGatewaysTable(
result: ListGatewaysResult,
options: FormatGatewaysTableOptions = {}
): FormattedGatewaysTable {
return this.gatewayManager.formatGatewaysTable(result, options)
}

public renderGatewaysAsciiTable(
table: FormattedGatewaysTable,
options: RenderGatewaysAsciiTableOptions = {}
): string {
return this.gatewayManager.renderGatewaysAsciiTable(table, options)
}

public formatGatewaysJson(result: ListGatewaysResult, options: ListGatewaysOptions = {}): string {
return this.gatewayManager.formatGatewaysJson(result, options)
}

public formatGatewaysOutput(result: ListGatewaysResult, options: ListGatewaysOptions = {}): string {
return this.gatewayManager.formatGatewaysOutput(result, options)
}
}
88 changes: 88 additions & 0 deletions KeeperSdk/src/pam/gateway/GatewayManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import type { Auth } from '@keeper-security/keeperapi'
import type { InMemoryStorage } from '../../storage/InMemoryStorage'
import { KeeperSdkError, ResultCodes } from '../../utils'
import { createGateway, formatCreateGatewayOutput } from './createGateway'
import { editGateway, formatEditGatewayOutput } from './editGateway'
import {
formatGatewaysJson,
formatGatewaysOutput,
formatGatewaysTable,
listGateways,
renderGatewaysAsciiTable,
} from './listGateways'
import type {
CreateGatewayInput,
CreateGatewayResult,
EditGatewayInput,
EditGatewayResult,
FormatGatewaysTableOptions,
FormattedGatewaysTable,
ListGatewaysOptions,
ListGatewaysResult,
RenderGatewaysAsciiTableOptions,
} from './gatewayTypes'

export type AuthProvider = () => Auth

export class GatewayManager {
private readonly storage: InMemoryStorage
private readonly authProvider: AuthProvider

constructor(storage: InMemoryStorage, authProvider: AuthProvider) {
this.storage = storage
this.authProvider = authProvider
}

private requireAuth(): Auth {
const auth = this.authProvider()
if (!auth?.sessionToken) {
throw new KeeperSdkError('Not logged in. Call login() first.', ResultCodes.NOT_LOGGED_IN)
}
return auth
}

public async listGateways(options: ListGatewaysOptions = {}): Promise<ListGatewaysResult> {
return listGateways(this.requireAuth(), this.storage, options)
}

public async createGateway(input: CreateGatewayInput & { returnValue: true }): Promise<string>
public async createGateway(input: CreateGatewayInput & { returnValue?: false }): Promise<CreateGatewayResult>
public async createGateway(input: CreateGatewayInput): Promise<CreateGatewayResult | string>
public async createGateway(input: CreateGatewayInput): Promise<CreateGatewayResult | string> {
return createGateway(this.requireAuth(), this.storage, input)
}

public formatCreateGatewayOutput(result: CreateGatewayResult): string {
return formatCreateGatewayOutput(result)
}

public async editGateway(input: EditGatewayInput): Promise<EditGatewayResult> {
return editGateway(this.requireAuth(), input)
}

public formatEditGatewayOutput(result: EditGatewayResult): string {
return formatEditGatewayOutput(result)
}

public formatGatewaysTable(
result: ListGatewaysResult,
options: FormatGatewaysTableOptions = {}
): FormattedGatewaysTable {
return formatGatewaysTable(result, options)
}

public renderGatewaysAsciiTable(
table: FormattedGatewaysTable,
options: RenderGatewaysAsciiTableOptions = {}
): string {
return renderGatewaysAsciiTable(table, options)
}

public formatGatewaysJson(result: ListGatewaysResult, options: ListGatewaysOptions = {}): string {
return formatGatewaysJson(result, options)
}

public formatGatewaysOutput(result: ListGatewaysResult, options: ListGatewaysOptions = {}): string {
return formatGatewaysOutput(result, options)
}
}
Loading
Loading