def setUp(self): self.opener = MockOpener() self.mock_datetime = MockDateTime() self.start_time = datetime.datetime(2011, 3, 1, 10, 25, 13, 300826) self.mock_datetime.mock_now = self.start_time self.client = oauth2_client.OAuth2Client( oauth2_client.OAuth2Provider( 'Sample OAuth Provider', 'https://provider.example.com/oauth/provider?mode=authorize', 'https://provider.example.com/oauth/provider?mode=token'), 'clid', 'clsecret', url_opener=self.opener, datetime_strategy=self.mock_datetime)
def OAuth2ClientFromBotoConfig(config): token_cache = None token_cache_type = config.get('OAuth2', 'token_cache', 'file_system') if token_cache_type == 'file_system': if config.has_option('OAuth2', 'token_cache_path_pattern'): token_cache = oauth2_client.FileSystemTokenCache( path_pattern=config.get('OAuth2', 'token_cache_path_pattern')) else: token_cache = oauth2_client.FileSystemTokenCache() elif token_cache_type == 'in_memory': token_cache = oauth2_client.InMemoryTokenCache() else: raise Exception( "Invalid value for config option OAuth2/token_cache: %s" % token_cache_type) proxy = None if (config.has_option('Boto', 'proxy') and config.has_option('Boto', 'proxy_port')): proxy = "%s:%s" % (config.get( 'Boto', 'proxy'), config.get('Boto', 'proxy_port')) provider_label = config.get('OAuth2', 'provider_label', GOOGLE_OAUTH2_PROVIDER_LABEL) provider_authorization_uri = config.get( 'OAuth2', 'provider_authorization_uri', GOOGLE_OAUTH2_PROVIDER_AUTHORIZATION_URI) provider_token_uri = config.get('OAuth2', 'provider_token_uri', GOOGLE_OAUTH2_PROVIDER_TOKEN_URI) client_id = config.get('OAuth2', 'client_id', GSUTIL_CLIENT_ID) client_secret = config.get('OAuth2', 'client_secret', GSUTIL_CLIENT_NOTSOSECRET) return oauth2_client.OAuth2Client(oauth2_client.OAuth2Provider( provider_label, provider_authorization_uri, provider_token_uri), client_id, client_secret, proxy=proxy, access_token_cache=token_cache)