This repository has been archived by the owner on Jun 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cut-down copy of go.apps.http_api app in go.apps.http_api_nostream.
- Loading branch information
Showing
11 changed files
with
1,242 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from zope.interface import implements | ||
|
||
from twisted.internet.defer import inlineCallbacks, returnValue | ||
from twisted.web import resource | ||
from twisted.cred import portal, checkers, credentials, error | ||
|
||
|
||
class ConversationRealm(object): | ||
implements(portal.IRealm) | ||
|
||
def __init__(self, resource): | ||
self.resource = resource | ||
|
||
def requestAvatar(self, user, mind, *interfaces): | ||
if resource.IResource in interfaces: | ||
return (resource.IResource, self.resource, lambda: None) | ||
raise NotImplementedError() | ||
|
||
|
||
class ConversationAccessChecker(object): | ||
implements(checkers.ICredentialsChecker) | ||
credentialInterfaces = (credentials.IUsernamePassword,) | ||
|
||
def __init__(self, vumi_api, conversation_key): | ||
self.vumi_api = vumi_api | ||
self.conversation_key = conversation_key | ||
|
||
@inlineCallbacks | ||
def requestAvatarId(self, credentials): | ||
username = credentials.username | ||
token = credentials.password | ||
user_exists = yield self.vumi_api.user_exists(username) | ||
if user_exists: | ||
user_api = self.vumi_api.get_user_api(username) | ||
conversation = yield user_api.get_wrapped_conversation( | ||
self.conversation_key) | ||
if conversation is not None: | ||
tokens = conversation.config.get('http_api_nostream', {}).get( | ||
'api_tokens', []) | ||
if token in tokens: | ||
returnValue(username) | ||
raise error.UnauthorizedLogin() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from go.vumitools.conversation.definition import ConversationDefinitionBase | ||
|
||
|
||
class ConversationDefinition(ConversationDefinitionBase): | ||
conversation_type = u'http_api_nostream' |
Oops, something went wrong.