def dcos_login(): # Defaults servers for both DCOS 1.10+ CE and EE. servers = os.getenv('MARATHON_SERVERS', 'http://marathon.mesos:8080,https://marathon.mesos:8443').split(',') if SERVICE_SECRET: print('Attempting token auth to Marathon...') client = MarathonClient(servers, auth_token=DCOSServiceAuth(json.loads(SERVICE_SECRET)).token, verify=False) else: print('Attempting unauthenticated access to Marathon...') client = MarathonClient(servers, verify=False) return client
def set_service_account(self, service_secret, verify=False): ''' Set credentials to authenticate with DCOS and Mesos Master :param service_secret: Optional DCOS Service account secret. Supersedes principal / secret. :type service_secret: dict :param verify: validate HTTPS fronted Mesos API using CA root trusts, defaults to False :type verify: bool ''' self.requests_auth = DCOSServiceAuth(service_secret) self.principal = self.requests_auth.principal cert_file = 'dcos-ca.crt' if not verify: response = requests.get('https://leader.mesos/ca/' + cert_file, verify=False) if response.status_code == 200: with open(cert_file, 'w') as cert: cert.write(response.text) self.verify = cert_file
from __future__ import absolute_import from __future__ import unicode_literals import json import requests from django.conf import settings from mesoshttp.acs import DCOSServiceAuth DCOS_AUTH = None DCOS_VERIFY = True if settings.SERVICE_SECRET: # We are in Enterprise mode and using service account DCOS_AUTH = DCOSServiceAuth((json.loads(settings.SERVICE_SECRET))) cert_file = 'dcos-ca.crt' response = requests.get('https://leader.mesos/ca/' + cert_file, verify=False) if response.status_code == 200: with open(cert_file, 'w') as cert: cert.write(response.text) DCOS_VERIFY = cert_file def make_dcos_request(host_address, relative_url, params=None): """Makes a requests that is capable of traversing DCOS EE Strict boundary :param master: The address for the Mesos master :type master: `util.host.HostAddress`