import * as fs from "fs" ; import * as readYaml from "js-yaml" ; import { ImperativeError } from "@zowe/imperative" ; import { IPropertiesInput , IProvisionOptionals } from "./" ; export class export class ProvisioningService { param { string } propertiesText returns { IPropertiesInput [ ] } see { IPropertiesInput } memberof public static parseProperties ( propertiesText ) { if ( propertiesText === "" ) { return [ ] ; } return propertiesText . split ( "," ) . map ( ( property ) => { const tempArray = property . split ( "=" ) ; if ( tempArray . length === 2 && tempArray [ 0 ] . length > 0 ) { return { name : tempArray [ 0 ] . trim ( ) , value : tempArray [ 1 ] . trim ( ) } ; } else { throw new ImperativeError ( { msg : `Incorrect properties format: ${ propertiesText }` } ) ; } } ) ; } param { string } path returns { IPropertiesInput [ ] } see { IPropertiesInput } memberof public static readPropertiesFromYamlFile ( path ) { const props = readYaml . safeLoad ( fs . readFileSync ( path , "utf8" ) ) ; const propsArrayObj = [ ] ; if ( typeof props !== "object" ) { return [ ] ; } for ( const key in props ) { if ( Object . prototype . hasOwnProperty . call ( props , key ) ) { propsArrayObj . push ( { name : key , value : ( props as any ) [ key ] } ) ; } } return propsArrayObj ; } param { string } properties param { string } propertiesFile param { string } domainName param { string } tenantName param { string } userDataId param { string } userData param { string } accountInfo param { string [ ] } systemNickNames returns { IProvisionOptionals } see { IProvisionOptionals } memberof public static checkForPassedOptionalParms ( properties ? , propertiesFile ? , domainName ? , tenantName ? , userDataId ? , userData ? , accountInfo ? , systemNickNames ? ) { const optionalItems = { "input-variables" : null , "domain-name" : null , "tenant-name" : null , "user-data-id" : null , "account-info" : null , "user-data" : null , "systems-nicknames" : null } ; if ( properties ) { optionalItems [ "input-variables" ] = ProvisioningService . parseProperties ( properties ) ; } if ( propertiesFile ) { optionalItems [ "input-variables" ] = ProvisioningService . readPropertiesFromYamlFile ( propertiesFile ) ; } if ( domainName ) { optionalItems [ "domain-name" ] = domainName ; } if ( tenantName ) { optionalItems [ "tenant-name" ] = tenantName ; } if ( accountInfo ) { optionalItems [ "account-info" ] = accountInfo ; } if ( userDataId ) { optionalItems [ "user-data-id" ] = userDataId ; } if ( userData ) { optionalItems [ "user-data" ] = userData ; } if ( systemNickNames ) { optionalItems [ "systems-nicknames" ] = systemNickNames ; } return optionalItems ; } }