2024-10-15 15:17:05 +00:00
module . exports = {
friendlyName : 'Get software' ,
description : 'Builds and returns an array of deployed software installers on the Fleet instance and undeployed software stored in the dashboard\'s datastore.' ,
exits : {
success : {
outputType : [ { } ] ,
}
} ,
fn : async function ( ) {
let teamsResponseData = await sails . helpers . http . get . with ( {
url : '/api/v1/fleet/teams' ,
baseUrl : sails . config . custom . fleetBaseUrl ,
headers : {
Authorization : ` Bearer ${ sails . config . custom . fleetApiToken } `
}
} )
. timeout ( 120000 )
. retry ( [ 'requestFailed' , { name : 'TimeoutError' } ] ) ;
let allTeams = teamsResponseData . teams ;
let teams = [ ] ;
for ( let team of allTeams ) {
teams . push ( {
fleetApid : team . id ,
teamName : team . name ,
} ) ;
}
// Add the "team" for hosts with no team
teams . push ( {
fleetApid : 0 ,
teamName : 'No team' ,
} ) ;
let allSoftware = [ ] ;
let allSoftwareWithPackages = [ ] ;
let teamsinformationForSoftware = [ ] ;
let teamApids = _ . pluck ( teams , 'fleetApid' ) ;
// Get all of the software packages on the Fleet instance.
for ( let teamApid of teamApids ) {
let configurationProfilesResponseData = await sails . helpers . http . get . with ( {
2025-01-30 17:25:33 +00:00
url : ` /api/latest/fleet/software/titles?team_id= ${ teamApid } &exclude_fleet_maintained_apps=true ` ,
2024-10-15 15:17:05 +00:00
baseUrl : sails . config . custom . fleetBaseUrl ,
headers : {
Authorization : ` Bearer ${ sails . config . custom . fleetApiToken } `
}
} )
. timeout ( 120000 )
. retry ( [ 'requestFailed' , { name : 'TimeoutError' } ] ) ;
let softwareForThisTeam = configurationProfilesResponseData . software _titles ;
let softwareWithSoftwarePackages = _ . filter ( softwareForThisTeam , ( software ) => {
return ! _ . isEmpty ( software . software _package ) ;
} ) ;
for ( let softwareWithInstaller of softwareWithSoftwarePackages ) {
let softwareWithInstallerResponse = await sails . helpers . http . get . with ( {
2025-01-30 17:25:33 +00:00
url : ` /api/latest/fleet/software/titles/ ${ softwareWithInstaller . id } ?team_id= ${ teamApid } &available_for_install=true&exclude_fleet_maintained_apps=true ` ,
2024-10-15 15:17:05 +00:00
baseUrl : sails . config . custom . fleetBaseUrl ,
headers : {
Authorization : ` Bearer ${ sails . config . custom . fleetApiToken } `
}
} )
. timeout ( 120000 )
. retry ( [ 'requestFailed' , { name : 'TimeoutError' } ] ) ;
let packageInformation = softwareWithInstallerResponse . software _title . software _package ;
let packageInfo = {
fleetApid : softwareWithInstaller . id ,
name : packageInformation . name ,
createdAt : new Date ( packageInformation . uploaded _at ) . getTime ( ) ,
platform : _ . endsWith ( packageInformation . name , 'deb' ) ? 'Linux' : _ . endsWith ( packageInformation . name , 'pkg' ) ? 'macOS' : 'Windows' ,
preInstallQuery : packageInformation . pre _install _query ,
installScript : packageInformation . install _script ,
postInstallScript : packageInformation . post _install _script ,
uninstallScript : packageInformation . uninstall _script ,
teams : [ ] ,
} ;
let teamInfo = {
softwareFleetApid : softwareWithInstaller . id ,
fleetApid : teamApid ,
teamName : _ . find ( teams , { fleetApid : teamApid } ) . teamName ,
} ;
teamsinformationForSoftware . push ( teamInfo ) ;
allSoftware . push ( packageInfo ) ;
allSoftwareWithPackages . push ( packageInfo ) ;
}
}
for ( let software of allSoftwareWithPackages ) {
software . teams = _ . where ( teamsinformationForSoftware , { 'softwareFleetApid' : software . fleetApid } ) ;
allSoftware . push ( software ) ;
}
allSoftware = _ . uniq ( allSoftware , 'fleetApid' ) ;
let undeployedSoftware = await UndeployedSoftware . find ( ) ;
allSoftware = allSoftware . concat ( undeployedSoftware ) ;
return allSoftware ;
}
} ;