Skip to content

Commit

Permalink
Merge pull request #7 from newcastleuniversity/3_implement_prod_channel
Browse files Browse the repository at this point in the history
Calculate real release from distro codename in Apt source management; fixes #3
  • Loading branch information
threepistons authored Jan 20, 2023
2 parents 8a3f1cb + 42aee81 commit ebf6a27
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,6 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: action-pdk-validate
# You may pin to the exact commit or the version.
# uses: puppets-epic-show-theatre/action-pdk-validate@31b5407676af16b690b2b8c54c0767af72fcc34f
uses: puppets-epic-show-theatre/action-pdk-validate@v1
with:
# A string indicating the Puppet version to validate against, such as "5.4.2" or "5.5".
puppet-version: 7.21.0
# A string indicating the PE version to validate against, such as "2017.3.5" or "2018.1".
pe-version: # optional

- name: action-pdk-test-unit
# You may pin to the exact commit or the version.
# uses: puppets-epic-show-theatre/action-pdk-test-unit@193987acba9977d1825fefbcbaf8d02d6af78106
uses: puppets-epic-show-theatre/action-pdk-test-unit@v1
with:
# A string indicating the Puppet version to validate against, such as "5.4.2" or "5.5".
puppet-version: 7.21.0
# A string indicating the PE version to validate against, such as "2017.3.5" or "2018.1".
pe-version: # optional

- name: action-pdk-validate
# You may pin to the exact commit or the version.
# uses: puppets-epic-show-theatre/action-pdk-validate@31b5407676af16b690b2b8c54c0767af72fcc34f
Expand Down
10 changes: 5 additions & 5 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
# Automatic parameter lookup never works for me so I used lookup(), which also lets me do these very obvious defaults-with-overrides.
Stdlib::Filesource $onboarding_json_file,
# If default_distro isn't in the module Hiera, compilation should fail
Optional[String] $distro = lookup('microsoft_defender_atp_agent::default_distro'),
Optional[String] $version = $::facts['os']['release']['major'],
Optional[Enum['prod','insiders-fast','insiders-slow']] $channel = lookup('microsoft_defender_atp_agent::default_channel'), # prod
Optional[Boolean] $manage_sources = lookup('microsoft_defender_atp_agent::default_manage_sources'), # true
Optional[String] $keyserver = lookup('microsoft_defender_atp_agent::default_keyserver') # hkps://keyserver.ubuntu.com:443
Optional[String] $distro = lookup('microsoft_defender_atp_agent::default_distro'),
Optional[String] $version = $::facts['os']['release']['major'],
Optional[Enum['prod','insiders-fast','insiders-slow','nightly','testing']] $channel = lookup('microsoft_defender_atp_agent::default_channel'), # prod
Optional[Boolean] $manage_sources = lookup('microsoft_defender_atp_agent::default_manage_sources'), # true
Optional[String] $keyserver = lookup('microsoft_defender_atp_agent::default_keyserver') # hkps://keyserver.ubuntu.com:443
) {
# I run a lot of armhf Pis and this endpoint agent won't work on them because the
Expand Down
11 changes: 10 additions & 1 deletion manifests/sources.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@

/(debian|ubuntu)/: {

case $microsoft_defender_atp_agent::channel {
'prod': {
$real_channel = $::facts['os']['distro']['codename']
}
default: {
$real_channel = $microsoft_defender_atp_agent::channel
}
}

include apt

apt::source { 'microsoftpackages' :
location => "https://packages.microsoft.com/${microsoft_defender_atp_agent::distro}/${microsoft_defender_atp_agent::version}/prod",
release => $microsoft_defender_atp_agent::channel,
release => $real_channel,
repos => 'main',
key => {
'id' => 'BC528686B50D79E339D3721CEB3E94ADBE1229CF',
Expand Down
23 changes: 19 additions & 4 deletions spec/classes/sources_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
supported_os: [
{
'operatingsystem' => 'Ubuntu',
'operatingsystemrelease' => ['18.04', '20.04'],
'operatingsystemrelease' => ['18.04', '20.04', '22.04'],
},
],
}
Expand All @@ -40,7 +40,6 @@
it {
is_expected.to contain_apt__source('microsoftpackages').with(
'location' => %r{ubuntu},
'release' => 'prod',
'key' => {
'server' => 'hkps://keyserver.ubuntu.com:443',
'id' => 'BC528686B50D79E339D3721CEB3E94ADBE1229CF',
Expand All @@ -50,12 +49,29 @@
end
end

context 'Ubuntu 22.02 tests' do
ubuntu22 = {
supported_os: [
{
'operatingsystem' => 'Ubuntu',
'operatingsystemrelease' => ['22.04'],
},
],
}

on_supported_os(ubuntu22).each do |_os, os_facts|
let(:facts) { os_facts }

it { is_expected.to contain_apt__source('microsoftpackages').with('release' => 'jammy') }
end
end

context 'Debian tests' do
debian = {
supported_os: [
{
'operatingsystem' => 'Debian',
'operatingsystemrelease' => ['9', '10'],
'operatingsystemrelease' => ['9', '10', '11'],
},
],
}
Expand All @@ -66,7 +82,6 @@
it {
is_expected.to contain_apt__source('microsoftpackages').with(
'location' => %r{debian},
'release' => 'prod',
'key' => {
'server' => 'hkps://keyserver.ubuntu.com:443',
'id' => 'BC528686B50D79E339D3721CEB3E94ADBE1229CF',
Expand Down

0 comments on commit ebf6a27

Please # to comment.