Skip to content

Instantly share code, notes, and snippets.

@leandrosilva
Last active September 9, 2019 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leandrosilva/22b2b34fda07932ac1dbf8fde8423911 to your computer and use it in GitHub Desktop.
Save leandrosilva/22b2b34fda07932ac1dbf8fde8423911 to your computer and use it in GitHub Desktop.
Two small samples on how to use mod_s3.psm1 and mod_eslog.psm1
#################################
# SENDING LOG TO ELASTIC SEARCH #
#################################
Import-Module ($PSScriptRoot + "\mod_eslog.psm1") -Force
Send-InstallationLog -Version $remoteVersion
"Current version has been installed."
####################
# HELPER FUNCTIONS #
####################
function Send-InstallationLog ($Version) {
$esVersionsIndexUri = Get-ESIndexUri -IndexSuffix "versions"
$body = @"
{
"Version": "${Version}",
"Message": "Hey you there! I am your DUMMY app rocking version ${Version}."
}
"@
Send-ESLog -IndexUri $esVersionsIndexUri -Body $body
}
################################
# GETTING METADATA FROM AWS S3 #
################################
Import-Module ($PSScriptRoot + "\mod_s3.psm1") -Force
$remoteLastModified = (Get-RemoteVersionCatalogMetadata).LastModified
"Remote file: $remoteLastModified."
$localLastModified = (Get-Item $LocalVersionCatalogPath).LastWriteTime
"Local file: $localLastModified."
$remoteWasModified = ($remoteLastModified -gt $localFileMetadata)
"Remote file was modified: $remoteWasModified."
if ($remoteWasModified) {
Read-RemoteVersionCatalog -LocalFilePath $RemoteVersionCatalogPath
$remoteVersionCatalogJson = Get-Content $RemoteVersionCatalogPath | Out-String | ConvertFrom-Json
$remoteVersion = $remoteVersionCatalogJson | ForEach-Object {$_.$DummyCluster} | ForEach-Object {$_.current}
"Remote version: $remoteVersion."
$localVersionCatalogJson = Get-Content $LocalVersionCatalogPath | Out-String | ConvertFrom-Json
$localVersion = $localVersionCatalogJson | ForEach-Object {$_.$DummyCluster} | ForEach-Object {$_.current}
"Local version: $localVersion."
$versionHasChanged = (-not ($localVersion -eq $remoteVersion))
"Current version has changed: $versionHasChanged."
# this and that...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment