Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mas: disable sign-in check for macOS 12+ #6520

Merged
29 changes: 23 additions & 6 deletions plugins/modules/mas.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
- 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+
justinpjose marked this conversation as resolved.
Show resolved Hide resolved
- User need to sign in via the Mac App Store GUI beforehand for anyone using macOS 12.0+ due to https://github.com/mas-cli/mas/issues/417
justinpjose marked this conversation as resolved.
Show resolved Hide resolved
'''

EXAMPLES = '''
Expand Down Expand Up @@ -106,6 +108,9 @@

from ansible_collections.community.general.plugins.module_utils.version import LooseVersion

import platform
WORKING_MAC_VERSION_MAS_ACCOUNT = '11.0'
justinpjose marked this conversation as resolved.
Show resolved Hide resolved


class Mas(object):

Expand All @@ -115,6 +120,7 @@ def __init__(self, module):
# Initialize data properties
self.mas_path = self.module.get_bin_path('mas')
self._checked_signin = False
self._mac_version = platform.mac_ver()[0]
justinpjose marked this conversation as resolved.
Show resolved Hide resolved
self._installed = None # Populated only if needed
self._outdated = None # Populated only if needed
self.count_install = 0
Expand Down Expand Up @@ -156,14 +162,16 @@ def check_mas_tool(self):

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')
return
if is_version_greater(self._mac_version, 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

Expand Down Expand Up @@ -299,3 +307,12 @@ def main():

if __name__ == '__main__':
main()


def is_version_greater(version, reference_version):
version_parts = [int(part) for part in version.split('.')]
reference_parts = [int(part) for part in reference_version.split('.')]
if version_parts > reference_parts:
return True
else:
return False
justinpjose marked this conversation as resolved.
Show resolved Hide resolved
Loading