1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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 <felix@fontein.de>

* update requirement description link

Co-authored-by: Felix Fontein <felix@fontein.de>

* update constant of macOS version

Co-authored-by: Felix Fontein <felix@fontein.de>

* use updated constant

Co-authored-by: Felix Fontein <felix@fontein.de>

* update getting macOS version

Co-authored-by: Felix Fontein <felix@fontein.de>

* add changelog fragment

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Justine Jose 2023-05-29 17:53:20 +01:00 committed by GitHub
parent bd6cec2105
commit 4373f2f33b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View file

@ -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)."

View file

@ -53,6 +53,8 @@ requirements:
- macOS 10.11+ - macOS 10.11+
- "mas-cli (U(https://github.com/mas-cli/mas)) 1.5.0+ available as C(mas) in the bin path" - "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 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 = ''' EXAMPLES = '''
@ -106,6 +108,9 @@ import os
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
import platform
NOT_WORKING_MAC_VERSION_MAS_ACCOUNT = '12.0'
class Mas(object): class Mas(object):
@ -115,6 +120,7 @@ class Mas(object):
# Initialize data properties # Initialize data properties
self.mas_path = self.module.get_bin_path('mas') self.mas_path = self.module.get_bin_path('mas')
self._checked_signin = False self._checked_signin = False
self._mac_version = platform.mac_ver()[0] or '0.0'
self._installed = None # Populated only if needed self._installed = None # Populated only if needed
self._outdated = None # Populated only if needed self._outdated = None # Populated only if needed
self.count_install = 0 self.count_install = 0
@ -156,14 +162,16 @@ class Mas(object):
def check_signin(self): def check_signin(self):
''' Verifies that the user is signed in to the Mac App Store ''' ''' Verifies that the user is signed in to the Mac App Store '''
# Only check this once per execution # Only check this once per execution
if self._checked_signin: if self._checked_signin:
return return
if LooseVersion(self._mac_version) >= LooseVersion(NOT_WORKING_MAC_VERSION_MAS_ACCOUNT):
rc, out, err = self.run(['account']) # Checking if user is signed-in is disabled due to https://github.com/mas-cli/mas/issues/417
if out.split("\n", 1)[0].rstrip() == 'Not signed in': self.module.log('WARNING: You must be signed in via the Mac App Store GUI beforehand else error will occur')
self.module.fail_json(msg='You must be signed in to the Mac App Store') 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 self._checked_signin = True