import { ICommandArguments , ICommandOptionDefinition , IProfile , Logger , SessConstants , Session , ISession } from "@zowe/imperative" ; export export class ZosmfSession { public static ZOSMF_CONNECTION_OPTION_GROUP = "Zosmf Connection Options" ; /**
     * Option used in profile creation and commands for hostname for z/OSMF
     */ public static ZOSMF_OPTION_HOST : ICommandOptionDefinition = { name : "host" , aliases : [ "H" ] , description : "The z/OSMF server host name." , type : "string" , required : false , group : ZosmfSession . ZOSMF_CONNECTION_OPTION_GROUP } ; public static ZOSMF_OPTION_HOST_PROFILE : ICommandOptionDefinition = { ... ZosmfSession . ZOSMF_OPTION_HOST , required : false } ; /**
     * Option used in profile creation and commands for port for z/OSMF
     */ public static ZOSMF_OPTION_PORT : ICommandOptionDefinition = { name : "port" , aliases : [ "P" ] , description : "The z/OSMF server port." , type : "number" , defaultValue : 443 , group : ZosmfSession . ZOSMF_CONNECTION_OPTION_GROUP } ; /**
     * Option used in profile creation and commands for username / ID  for z/OSMF
     */ public static ZOSMF_OPTION_USER : ICommandOptionDefinition = { name : "user" , aliases : [ "u" ] , description : "Mainframe (z/OSMF) user name, which can be the same as your TSO login." , type : "string" , required : false , group : ZosmfSession . ZOSMF_CONNECTION_OPTION_GROUP } ; public static ZOSMF_OPTION_USER_PROFILE : ICommandOptionDefinition = { ... ZosmfSession . ZOSMF_OPTION_USER , required : false } ; /**
     * Option used in profile creation and commands for password/passphrase for z/OSMF
     */ public static ZOSMF_OPTION_PASSWORD : ICommandOptionDefinition = { name : "password" , aliases : [ "pass" , "pw" ] , description : "Mainframe (z/OSMF) password, which can be the same as your TSO password." , type : "string" , required : false , group : ZosmfSession . ZOSMF_CONNECTION_OPTION_GROUP } ; public static ZOSMF_OPTION_PASSWORD_PROFILE : ICommandOptionDefinition = { ... ZosmfSession . ZOSMF_OPTION_PASSWORD , required : false } ; /**
     * Option used in profile creation and commands for rejectUnauthorized setting for connecting to z/OSMF
     */ public static ZOSMF_OPTION_REJECT_UNAUTHORIZED : ICommandOptionDefinition = { name : "reject-unauthorized" , aliases : [ "ru" ] , description : "Reject self-signed certificates." , type : "boolean" , defaultValue : true , group : ZosmfSession . ZOSMF_CONNECTION_OPTION_GROUP } ; /**
     * Option used in profile creation and commands for base path setting for connecting to z/OSMF
     */ public static ZOSMF_OPTION_BASE_PATH : ICommandOptionDefinition = { name : "base-path" , aliases : [ "bp" ] , description : "The base path for your API mediation layer instance." + " Specify this option to prepend the base path to all z/OSMF resources when making REST requests." + " Do not specify this option if you are not using an API mediation layer." , type : "string" , group : ZosmfSession . ZOSMF_CONNECTION_OPTION_GROUP } ; /**
     * Option used to specify HTTP or HTTPS Protocol
     */ public static ZOSMF_OPTION_PROTOCOL : ICommandOptionDefinition = { name : "protocol" , description : "The protocol used (HTTP or HTTPS)" , type : "string" , defaultValue : "https" , group : ZosmfSession . ZOSMF_CONNECTION_OPTION_GROUP , allowableValues : { values : [ "http" , "https" ] , caseSensitive : false } } ; /**
     * Option used to specify the path to the certificate file for authentication
     */ public static ZOSMF_OPTION_CERT_FILE : ICommandOptionDefinition = { name : "cert-file" , description : "The file path to a certificate file to use for authentication" , type : "existingLocalFile" , group : ZosmfSession . ZOSMF_CONNECTION_OPTION_GROUP } ; /**
     * Option used to specify the path to the certificate file for authentication
     */ public static ZOSMF_OPTION_CERT_KEY_FILE : ICommandOptionDefinition = { name : "cert-key-file" , description : "The file path to a certificate key file to use for authentication" , type : "existingLocalFile" , group : ZosmfSession . ZOSMF_CONNECTION_OPTION_GROUP } ; /**
     * Option used to specify the path to the certificate file for authentication
     */ /**
     * Options related to connecting to z/OSMF
     * These options can be filled in if the user creates a profile
     */ public static ZOSMF_CONNECTION_OPTIONS : ICommandOptionDefinition [ ] = [ ZosmfSession . ZOSMF_OPTION_HOST , ZosmfSession . ZOSMF_OPTION_PORT , ZosmfSession . ZOSMF_OPTION_USER , ZosmfSession . ZOSMF_OPTION_PASSWORD , ZosmfSession . ZOSMF_OPTION_REJECT_UNAUTHORIZED , ZosmfSession . ZOSMF_OPTION_BASE_PATH , ZosmfSession . ZOSMF_OPTION_PROTOCOL , ZosmfSession . ZOSMF_OPTION_CERT_FILE , ZosmfSession . ZOSMF_OPTION_CERT_KEY_FILE ] ; param { IProfile } args returns { ISession } public static createSessCfgFromArgs ( args ) { return { rejectUnauthorized : args . rejectUnauthorized , basePath : args . basePath , protocol : args . protocol ? args . protocol . toLowerCase ( ) : 'https' } ; } deprecated static param { IProfile } profile returns { Session } public static createBasicZosmfSession ( profile ) { this . log . debug ( "Creating a z/OSMF session from the profile named %s" , profile . name ) ; return new Session ( { type : SessConstants . AUTH_TYPE_BASIC , hostname : profile . host , port : profile . port , user : profile . user , password : profile . password , rejectUnauthorized : profile . rejectUnauthorized , basePath : profile . basePath , protocol : profile . protocol ? profile . protocol . toLowerCase ( ) : 'https' } ) ; } static deprecated param { IProfile } args returns { Session } public static createBasicZosmfSessionFromArguments ( args ) { this . log . debug ( "Creating a z/OSMF session from arguments" ) ; const sessionConfig = { hostname : args . host , port : args . port , rejectUnauthorized : args . rejectUnauthorized , basePath : args . basePath } ; sessionConfig . type = SessConstants . AUTH_TYPE_BASIC ; sessionConfig . user = args . user ; sessionConfig . password = args . password ; if ( sessionConfig . user && sessionConfig . password ) { this . log . debug ( "Using basic authentication" ) ; } else if ( args . tokenType && args . tokenValue ) { this . log . debug ( "Using token authentication" ) ; sessionConfig . type = SessConstants . AUTH_TYPE_TOKEN ; sessionConfig . tokenType = args . tokenType ; sessionConfig . tokenValue = args . tokenValue ; } else if ( args . certFile && args . certKeyFile ) { this . log . debug ( "Using PEM Certificate authentication" ) ; sessionConfig . type = SessConstants . AUTH_TYPE_CERT_PEM ; sessionConfig . cert = args . certFile ; sessionConfig . certKey = args . certKeyFile ; } return new Session ( sessionConfig ) ; } private static get log ( ) : Logger { return Logger . getAppLogger ( ) ; } }