Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Merge branch 'bug/642873' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rafrombrc committed Apr 22, 2011
2 parents 91e7003 + 25783ef commit 885b303
Show file tree
Hide file tree
Showing 17 changed files with 236 additions and 142 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -5,7 +5,7 @@ BIN_DIR = bin
endif

APPNAME = server-shared-send
DEPS = server-share-core
DEPS = mozilla:server-core,github:server-share-core
VIRTUALENV = virtualenv
NOSE = $(BIN_DIR)/nosetests
NOSETESTS_ARGS = -s
Expand Down
43 changes: 29 additions & 14 deletions build.py
Expand Up @@ -39,7 +39,8 @@


CURDIR = os.path.dirname(__file__)
REPO_ROOT = 'https://github.com/mozilla/%s.git'
REPOS = {'github': ('git', 'https://github.com/mozilla/%s.git'),
'mozilla': ('hg', 'https://hg.mozilla.org/services/%s')}
PYTHON = sys.executable


Expand Down Expand Up @@ -74,21 +75,27 @@ def _envname(name):
return name.upper().replace('-', '_')


def _update_cmd(project, latest_tags=False):
def _update_cmd(project, latest_tags=False, repo_type='git'):
if latest_tags:
return 'git checkout -r "%s"' % get_latest_tag()
if repo_type == 'hg':
return 'hg up -r "%s"' % get_latest_tag()
else:
return 'git checkout -r "%s"' % get_latest_tag()
else:

# looking for an environ with a specific tag or rev
rev = os.environ.get(_envname(project))
if rev is not None:

if not verify_tag(rev):
print('Unknown tag or revision: %s' % rev)
sys.exit(1)

return 'git checkout -r "%s"' % rev
return 'git checkout'
if repo_type == 'git':
return 'git checkout -r "%s"' % rev
else:
return 'hg up -r "%s"' % rev
if repo_type == 'git':
return 'git checkout'
else:
return 'hg up'


def build_app(name, latest_tags, deps):
Expand All @@ -113,16 +120,24 @@ def build_deps(deps, latest_tags):
os.mkdir(deps_dir)

for dep in deps:
repo = REPO_ROOT % dep
target = os.path.join(deps_dir, dep)
root, name = dep.split(':')
repo_type, repo_root = REPOS[root]
repo = repo_root % name
target = os.path.join(deps_dir, name)
if os.path.exists(target):
os.chdir(target)
_run('git pull')
if repo_type == 'git':
_run('git pull')
else:
_run('hg pull')
else:
_run('git clone %s %s' % (repo, target))
os.chdir(target)
if repo_type == 'git':
_run('git clone %s %s' % (repo, target))
else:
_run('hg clone %s %s' % (repo, target))

update_cmd = _update_cmd(dep, latest_tags)
os.chdir(target)
update_cmd = _update_cmd(dep, latest_tags, repo_type)
_run(update_cmd)
_run('%s setup.py develop' % PYTHON)
finally:
Expand Down
4 changes: 4 additions & 0 deletions development.ini
Expand Up @@ -57,6 +57,10 @@ oauth.linkedin.com.request = https://api.linkedin.com/uas/oauth/requestToken
oauth.linkedin.com.access = https://api.linkedin.com/uas/oauth/accessToken
oauth.linkedin.com.authorize = https://api.linkedin.com/uas/oauth/authorize

sstatus.enabled = 0
sstatus.servers = 127.0.0.1:11211
sstatus.domains = google.com,twitter.com,facebook.com,linkedin.com

[server:main]
use = egg:Paste#http
host = 127.0.0.1
Expand Down
41 changes: 41 additions & 0 deletions linkdrop/controllers/__init__.py
@@ -0,0 +1,41 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Raindrop.
#
# The Initial Developer of the Original Code is
# Mozilla Messaging, Inc..
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s): Tarek Ziade <tarek@mozilla.com>
#

# XXX services instance to be moved in the future application
# object once Pylons gets removed

from linkoauth import Services
from pylons import config

services = None


def get_services():
global services
if services is None:
enabled = int(config.get('sstatus.ttl', '0'))
servers = config['sstatus.servers'].split(',')
domains = config['sstatus.domains'].split(',')
ttl = int(config.get('sstatus.ttl', '60'))
services = Services(domains, servers, ttl, enabled)
return services
16 changes: 8 additions & 8 deletions linkdrop/controllers/account.py
Expand Up @@ -19,6 +19,7 @@
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Rob Miller (rmiller@mozilla.com)
#

import logging
Expand All @@ -32,13 +33,12 @@
from pylons.controllers.util import redirect
from pylons.controllers.core import HTTPException

from linkoauth.errors import AccessException
from linkdrop.controllers import get_services
from linkdrop.lib.base import BaseController
from linkdrop.lib.helpers import get_redirect_response
from linkdrop.lib.metrics import metrics

from linkoauth import get_provider
from linkoauth.base import AccessException

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -66,19 +66,19 @@ def _create_account(self, domain, userid, username):
def authorize(self, *args, **kw):
provider = request.POST['domain']
log.info("authorize request for %r", provider)
service = get_provider(provider)
return service.responder().request_access(request, url, session)
services = get_services()
return services.request_access(provider, request, url, session)

# this is not a rest api
def verify(self, *args, **kw):
provider = request.params.get('provider')
log.info("verify request for %r", provider)
service = get_provider(provider)

auth = service.responder()
acct = dict()
try:
user = auth.verify(request, url, session)
services = get_services()
user = services.verify(provider, request, url, session)

account = user['profile']['accounts'][0]
if (not user.get('oauth_token')
and not user.get('oauth_token_secret')):
Expand Down
23 changes: 13 additions & 10 deletions linkdrop/controllers/contacts.py
Expand Up @@ -19,16 +19,18 @@
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Rob Miller (rmiller@mozilla.com)
#

import logging
import json

from pylons import request

from linkoauth import get_provider
from linkoauth.base import OAuthKeysException, ServiceUnavailableException
from linkoauth.errors import (OAuthKeysException, ServiceUnavailableException,
DomainNotRegisteredError)

from linkdrop.controllers import get_services
from linkdrop.lib.base import BaseController
from linkdrop.lib.helpers import json_exception_response, api_response
from linkdrop.lib.helpers import api_entry, api_arg
Expand Down Expand Up @@ -86,13 +88,6 @@ class ContactsController(BaseController):
def get(self, domain):
page_data = request.POST.get('pageData', None)
account_data = request.POST.get('account', None)
provider = get_provider(domain)
if provider is None:
error = {
'message': "'domain' is invalid",
'code': constants.INVALID_PARAMS,
}
return {'result': None, 'error': error}

acct = None
if account_data:
Expand All @@ -108,7 +103,15 @@ def get(self, domain):

page_data = page_data and json.loads(page_data) or {}
try:
result, error = provider.api(acct).getcontacts(page_data)
services = get_services()
result, error = services.getcontacts(domain, acct, page_data)
except DomainNotRegisteredError:
error = {
'message': "'domain' is invalid",
'code': constants.INVALID_PARAMS,
}
return {'result': None, 'error': error}

except OAuthKeysException, e:
# more than likely we're missing oauth tokens for some reason.
error = {'provider': domain,
Expand Down
25 changes: 14 additions & 11 deletions linkdrop/controllers/send.py
Expand Up @@ -19,6 +19,7 @@
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Rob Miller (rmiller@mozilla.com)
#

import logging
Expand All @@ -30,9 +31,10 @@

from pylons import request

from linkoauth import get_provider
from linkoauth.base import OAuthKeysException, ServiceUnavailableException
from linkoauth.errors import (OAuthKeysException, ServiceUnavailableException,
DomainNotRegisteredError)

from linkdrop.controllers import get_services
from linkdrop.lib.base import BaseController
from linkdrop.lib.helpers import json_exception_response, api_response
from linkdrop.lib.helpers import api_entry, api_arg
Expand Down Expand Up @@ -124,13 +126,6 @@ def send(self):
'code': constants.INVALID_PARAMS,
}
return {'result': result, 'error': error}
provider = get_provider(domain)
if provider is None:
error = {
'message': "'domain' is invalid",
'code': constants.INVALID_PARAMS,
}
return {'result': result, 'error': error}

if account_data:
acct = json.loads(account_data)
Expand Down Expand Up @@ -161,9 +156,17 @@ def send(self):
long_url=longurl,
short_url=shorturl,
acct_id=acct_hash)
# send the item.
# send the item
try:
result, error = provider.api(acct).sendmessage(message, args)
services = get_services()
result, error = services.sendmessage(domain, acct, message,
args)
except DomainNotRegisteredError:
error = {
'message': "'domain' is invalid",
'code': constants.INVALID_PARAMS,
}
return {'result': result, 'error': error}
except OAuthKeysException, e:
# XXX - I doubt we really want a full exception logged here?
#log.exception('error providing item to %s: %s', domain, e)
Expand Down
4 changes: 2 additions & 2 deletions linkdrop/tests/__init__.py
Expand Up @@ -16,8 +16,8 @@

__all__ = ['environ', 'url', 'TestController', 'testable_services']

testable_services = ["google.com", "yahoo.com", "facebook.com", "twitter.com",
"linkedin.com"]
testable_services = ["google.com", "facebook.com", "twitter.com",
"linkedin.com", "yahoo.com"]

# Invoke websetup with the current config file
SetupCommand('setup-app').run(
Expand Down

0 comments on commit 885b303

Please sign in to comment.