示例#1
0
    def test_get_token(self):
        # get a jwt
        auth = Auth()
        self.assertIsNotNone(auth.token)

        # validate the jwt
        url = "https://descarteslabs.auth0.com" + "/tokeninfo"
        params = {"id_token": auth.token}
        headers = {"content-type": "application/json"}
        r = requests.post(url, data=json.dumps(params), headers=headers)
        self.assertEqual(200, r.status_code)
示例#2
0
    def __init__(self, url=None, token=None, auth=Auth(), maxsize=10, ttl=600):
        """The parent Service class implements authentication and exponential
        backoff/retry. Override the url parameter to use a different instance
        of the backing service.
        """
        if url is None:
            url = os.environ.get(
                "DESCARTESLABS_PLACES_URL",
                "https://platform.descarteslabs.com/waldo/v2")

        Service.__init__(self, url, token, auth)
        self.cache = TTLCache(maxsize, ttl)
    def __init__(self, url=None, token=None, auth=Auth()):
        """The parent Service class implements authentication and exponential
        backoff/retry. Override the url parameter to use a different instance
        of the backing service.
        """
        warnings.simplefilter('always', DeprecationWarning)
        if url is None:
            url = os.environ.get(
                "DESCARTESLABS_RASTER_URL",
                "https://platform.descarteslabs.com/raster/v1")

        Service.__init__(self, url, token, auth)
示例#4
0
def auth_handler(args):
    auth = Auth()

    if args.command == 'login':

        print(
            'Follow this link to login https://iam.descarteslabs.com/auth/login?refresh_token=true&destination=/auth/refresh_token'
        )  # NOQA

        s = input('...then come back here and paste the generated token: ')
        if isinstance(s, six.text_type):
            s = s.encode('utf-8')

        if s:

            token_info = json.loads(base64url_decode(s).decode('utf-8'))

            path = os.path.join(os.path.expanduser("~"), '.descarteslabs')

            if not os.path.exists(path):
                os.makedirs(path)

            os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)

            file = os.path.join(os.path.expanduser("~"), '.descarteslabs',
                                'token_info.json')

            with open(file, 'w+') as fp:
                json.dump(token_info, fp)

            os.chmod(file, stat.S_IRUSR | stat.S_IWUSR)

            # Get a fresh Auth token
            auth = dl.Auth()
            dl.metadata.auth = auth
            keys = dl.metadata.keys()

            name = auth.payload['name']
            groups = ', '.join(auth.payload['groups'])

            if len(keys):

                print('Welcome, %s!' % name)

            else:

                print(
                    'Welcome, %s! Your %s role(s) do not permit access to any imagery at this time.'
                    % (name, groups))
                print(
                    'Contact [email protected] if you believe you received this message in error or have any questions.'
                )  # NOQA

    if args.command == 'token':
        print(auth.token)

    if args.command == 'name':
        auth.token
        print(auth.payload['name'])

    if args.command == 'groups':
        auth.token
        print(json.dumps(auth.payload['groups']))

    if args.command == 'payload':
        auth.token
        print(auth.payload)

    if args.command == 'env':
        auth.token
        print('%s=%s' % ('CLIENT_ID', auth.client_id))
        print('%s=%s' % ('CLIENT_SECRET', auth.client_secret))

    if args.command == 'version':
        print(dl.__version__)
示例#5
0
 def test_get_namespace(self):
     auth = Auth.from_environment_or_token_json()
     self.assertIsNotNone(auth.namespace)