import { AbstractSession , ImperativeExpect , Logger , RestConstants , SessConstants , ImperativeError } from "@zowe/imperative" ; import { ZosmfRestClient } from "../rest/ZosmfRestClient" ; import { LoginConstants } from "./LoginConstants" ; export class export class Login { static param { AbstractSession } session returns memberof public static async apimlLogin ( session ) { Logger . getAppLogger ( ) . trace ( "Login.login()" ) ; ImperativeExpect . toNotBeNullOrUndefined ( session , "Required session must be defined" ) ; ImperativeExpect . toBeEqual ( session . ISession ?. tokenType , "apimlAuthenticationToken" , "Token type for API ML login must be apimlAuthenticationToken." ) ; const client = new ZosmfRestClient ( session ) ; await client . request ( { request : "POST" , resource : LoginConstants . APIML_V1_RESOURCE } ) ; if ( client . response . statusCode !== RestConstants . HTTP_STATUS_204 ) { throw new ImperativeError ( ( client as any ) . populateError ( { msg : `REST API Failure with HTTP(S) status ${ client . response . statusCode }` , causeErrors : client . dataString , source : SessConstants . HTTP_PROTOCOL } ) ) ; } return session . ISession . tokenValue ; } }