dt-app
Version:
The Dynatrace App Toolkit is a tool you can use from your command line to create, develop, and deploy apps on your Dynatrace environment.
62 lines (61 loc) • 3.38 kB
TypeScript
import type { AutomationTokenInformation, SSOTokenInformation } from '../interfaces';
import { AuthWorkflow } from '../interfaces';
import type { OAuthScope } from '../utils/config/cli-options';
export declare const SSO_CLIENT_ID = "dt0s08.dt-app-local";
export declare const enum TokenValidity {
VALID = "valid",
REFRESH_REQUIRED = "refresh-required",
INVALID = "invalid"
}
export declare const enum TokenType {
APP_TOKEN = "app",
TOOLKIT_TOKEN = "toolkit"
}
export type TokenInformation<T extends AuthWorkflow> = T extends AuthWorkflow.AUTOMATION ? AutomationTokenInformation : SSOTokenInformation;
export type TokenFileContent = {
toolkit_token?: AutomationTokenInformation | SSOTokenInformation;
app_token?: AutomationTokenInformation | SSOTokenInformation;
};
export type GetBearerTokenTypes<T extends TokenType> = {
tokenType: T;
cwd: string;
environmentUrl: string;
tokenFilePath?: string;
/** Open the auth url in the default browser */
openAuthUrl?: boolean;
customClientId?: string;
/** Should only be used when publishing the app */
ssoPublishUrl?: string;
};
export declare const defaultGetBearerOptions: (cwd: string) => {
openAuthUrl: boolean;
tokenFilePath: string;
};
/** Wrapper function that will validate and return token without returning token validity */
export declare function getBearerToken(options: GetBearerTokenTypes<TokenType>, appScopes?: OAuthScope[]): Promise<string>;
/**
* This function handles the whole authentication process. Depending on the tokenType passed you either get the full powered TOOLKIT_TOKEN or the APP_TOKEN, which only has the scopes specified for the app.
* Priority of which token is used: DT_APP_PLATFORM_TOKEN --> cached token (if still valid) --> refresh token --> sso process.
* If DT_APP_CLIENT_ID and DT_APP_CLIENT_SECRET are set it is executing the automation process instead of the sso process.
*/
export declare function getAutomationOrAccessToken(bearerTokenContext: TokenContext, tokenValidity: TokenValidity): Promise<string>;
/** Function that will process refresh of the access token save it to the file and return the token */
export declare function refreshToken(bearerTokenContext: TokenContext): Promise<string>;
export interface TokenContext {
currentAuthWorkflow: AuthWorkflow;
tokenFilePath: string;
environmentUrl: string;
oauthUrl: string;
oauthClientId: string;
appScopes?: OAuthScope[];
tokenType: TokenType;
currentTokenFileContent: TokenFileContent;
tokenInformation: AutomationTokenInformation | SSOTokenInformation | undefined;
openAuthUrl: boolean;
}
/** Function that returns all needed data for calling the getToken and validateToken functions */
export declare function createTokenContext(options: GetBearerTokenTypes<TokenType>, appScopes?: OAuthScope[]): Promise<TokenContext>;
/** Gets the token via the refresh_token process and adapts the tokenJson accordingly */
export declare function processRefreshOauth2Token(tokenJson: TokenFileContent, tokenType: TokenType, environmentUrl: string, oauthUrl: string, clientId: string): Promise<[TokenFileContent, string]>;
/** Adds all the scopes at the beginning of the array if they are not already part of the array. */
export declare function enrichAppScopes(scopes: OAuthScope[], scopesToAdd: OAuthScope[]): OAuthScope[];