From 131bf72d720e8eb466e64623c8afe8edc5a7d9c1 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 29 May 2023 21:08:53 +0200 Subject: [PATCH] [PR #6520/4373f2f3 backport][stable-7] mas: disable sign-in check for macOS 12+ (#6592) mas: disable sign-in check for macOS 12+ (#6520) * disable sign-in check for macOS 12+ * move is_version_greater func outside class Mas * fix formatting * remove trailing whitespace * make use of LooseVersion to compare versions * update requirement description Co-authored-by: Felix Fontein * update requirement description link Co-authored-by: Felix Fontein * update constant of macOS version Co-authored-by: Felix Fontein * use updated constant Co-authored-by: Felix Fontein * update getting macOS version Co-authored-by: Felix Fontein * add changelog fragment --------- Co-authored-by: Felix Fontein (cherry picked from commit 4373f2f33b8e89fa87613aeb60d07b0a07c972c8) Co-authored-by: Justine Jose <59870720+justinpjose@users.noreply.github.com> --- .../fragments/6520-mas-disable-signin.yaml | 3 +++ plugins/modules/mas.py | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/6520-mas-disable-signin.yaml diff --git a/changelogs/fragments/6520-mas-disable-signin.yaml b/changelogs/fragments/6520-mas-disable-signin.yaml new file mode 100644 index 0000000000..0cd6caa626 --- /dev/null +++ b/changelogs/fragments/6520-mas-disable-signin.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - "mas - disable sign-in check for macOS 12+ as ``mas account`` is non-functional (https://github.com/ansible-collections/community.general/pull/6520)." diff --git a/plugins/modules/mas.py b/plugins/modules/mas.py index 5b8958beb0..532f6a2dc1 100644 --- a/plugins/modules/mas.py +++ b/plugins/modules/mas.py @@ -53,6 +53,8 @@ requirements: - macOS 10.11+ - "mas-cli (U(https://github.com/mas-cli/mas)) 1.5.0+ available as C(mas) in the bin path" - The Apple ID to use already needs to be signed in to the Mac App Store (check with C(mas account)). + - The feature of "checking if user is signed in" is disabled for anyone using macOS 12.0+. + - Users need to sign in via the Mac App Store GUI beforehand for anyone using macOS 12.0+ due to U(https://github.com/mas-cli/mas/issues/417). ''' EXAMPLES = ''' @@ -106,6 +108,9 @@ import os from ansible_collections.community.general.plugins.module_utils.version import LooseVersion +import platform +NOT_WORKING_MAC_VERSION_MAS_ACCOUNT = '12.0' + class Mas(object): @@ -115,6 +120,7 @@ class Mas(object): # Initialize data properties self.mas_path = self.module.get_bin_path('mas') self._checked_signin = False + self._mac_version = platform.mac_ver()[0] or '0.0' self._installed = None # Populated only if needed self._outdated = None # Populated only if needed self.count_install = 0 @@ -156,14 +162,16 @@ class Mas(object): def check_signin(self): ''' Verifies that the user is signed in to the Mac App Store ''' - # Only check this once per execution if self._checked_signin: return - - rc, out, err = self.run(['account']) - if out.split("\n", 1)[0].rstrip() == 'Not signed in': - self.module.fail_json(msg='You must be signed in to the Mac App Store') + if LooseVersion(self._mac_version) >= LooseVersion(NOT_WORKING_MAC_VERSION_MAS_ACCOUNT): + # Checking if user is signed-in is disabled due to https://github.com/mas-cli/mas/issues/417 + self.module.log('WARNING: You must be signed in via the Mac App Store GUI beforehand else error will occur') + else: + rc, out, err = self.run(['account']) + if out.split("\n", 1)[0].rstrip() == 'Not signed in': + self.module.fail_json(msg='You must be signed in to the Mac App Store') self._checked_signin = True