Exemplo n.º 1
0
 def test_resolving_keys(self):
     # test resolving keys using dot-notation
     client = config.get_settings_at_path("some.arbitrary.path")
     self.assertEqual(client['foo'], "bar")
     
     with self.assertRaises(KeyError):
         config.get_settings_at_path("foo.bar")
    def test_resolving_keys(self):
        # test resolving keys using dot-notation
        client = config.get_settings_at_path("some.arbitrary.path")
        self.assertTrue(isinstance(client, dict))
        self.assertEqual(client['foo'], "bar")

        with self.assertRaises(JanrainConfigError):
            config.get_settings_at_path("foo.bar")
Exemplo n.º 3
0
    def parse_args(self, args=None, namespace=None):
        args = super().parse_args(args, namespace)
        # Parse the YAML configuration here so that init_api() does not need to
        # read the config each time it's called which would not be thread safe.
        if args.config_key:
            credentials = config.get_settings_at_path(args.config_key)
        elif args.default_client:
            credentials = config.default_client()

        if args.config_key or args.default_client:
            args.client_id = credentials['client_id']
            args.client_secret = credentials['client_secret']
            args.apid_uri = credentials['apid_uri']

        logger.debug(args.apid_uri)
        self._parsed_args = args
        return self._parsed_args
Exemplo n.º 4
0
    def parse_args(self, args=None, namespace=None):
        args = super(ApiArgumentParser, self).parse_args(args, namespace)
        # Parse the YAML configuration here so that init_api() does not need to
        # read the config each time it's called which would not be thread safe.
        if args.config_key:
            credentials = config.get_settings_at_path(args.config_key)
        elif args.default_client:
            credentials = config.default_client()

        if args.config_key or args.default_client:
            args.client_id = credentials['client_id']
            args.client_secret = credentials['client_secret']
            args.apid_uri = credentials['apid_uri']

        logger.debug(args.apid_uri)
        self._parsed_args = args
        return self._parsed_args
Exemplo n.º 5
0
 def init_api(self, api_class=None):
     """
     Initialize a janrain.capture.Api() instance for the credentials that
     were specified on the command line or environment variables. This 
     method will use the first credentials it finds, looking in the 
     following order:
     
     1. A client_id and client_secret specified on the command line
     2. A configuration key specified on the command line
     3. The default client as specified with a flag on the command line
     4. The CAPTURE_CLIENT_ID and CAPTURE_CLIENT_SECRET environment vars 
     
     Returns:
         A janrain.capture.Api instance
     
     """
     if not self._parsed_args:
         raise Exception("You must call the parse_args() method before " \
                         "the init_api() method.")
         
     args = self._parsed_args
     
     if args.client_id and args.client_secret:
         credentials = {
             'client_id': args.client_id,
             'client_secret': args.client_secret
         }
         
     elif args.config_key:
         credentials = config.get_settings_at_path(args.config_key)
         
     elif args.default_client:
         credentials = config.default_client()
         
     elif 'CAPTURE_CLIENT_ID' in os.environ \
         and 'CAPTURE_CLIENT_SECRET' in os.environ:
         credentials = {
             'client_id': os.environ['CAPTURE_CLIENT_ID'],
             'client_secret': os.environ['CAPTURE_CLIENT_SECRET']
         }
         
     else:
         message = "You did not specify credentials to authenticate " \
                   "with the Capture API."
         raise JanrainCredentialsError(message)
     
     if args.apid_uri:
         credentials['apid_uri'] = args.apid_uri
         
     elif 'apid_uri' not in credentials:
         if 'CAPTURE_APID_URI' in os.environ:
             credentials['apid_uri'] = os.environ['CAPTURE_APID_URI']
         else:
             message = "You did not specify the URL to the Capture API"
             raise JanrainCredentialsError(message)
     
     defaults = {k: credentials[k] for k in ('client_id', 'client_secret')}
     
     if api_class:
         return api_class(credentials['apid_uri'], defaults)
     else:
         return Api(credentials['apid_uri'], defaults)