def init_for_twisted_amp(commands): from twisted.protocols import amp type_map = { 'string': amp.String(), 'unicode': amp.String( ), # originally was amp.Unicode() - but I don't think Unicode is necessary for JSON strings 'boolean': amp.Boolean(), 'float': amp.Float(), 'integer': amp.Integer() } def convert_args(argdata): return [(x[0], type_map[x[1]]) for x in argdata] CMD = {} for name, data in commands.iteritems(): CMD[name] = type( name, (amp.Command, ), { 'commandName': name, 'arguments': convert_args(data['arguments']), 'response': convert_args(data['response']), 'errors': convert_args(data.get('errors', ())), 'requiresAnswer': data.get('requiresAnswer', True) }) return CMD
class Authenticate(amp.Command): """Authenticate the remote side. The procedure is as follows: - When establishing a new connection, the region and the cluster call `Authenticate` on each other, passing a random chunk of data in `message`. This message must be unique to avoid replay attacks. - The remote side adds some salt to the message, and calculates an HMAC digest, keyed with the shared secret. The salt is intended to prevent replay attacks: it prevents an intruder from authenticating itself by calling `Authenticate` on the caller (or another endpoint in the same MAAS installation) and sending the same message, receiving the digest and passing it back to the caller. - The remote side returns this digest and the salt. The caller performs the same calculation, and compares the digests. - If the digests match, the connection is put into rotation. - If the digests do not match, the connection is closed immediately, and an error is logged. :since: 1.7 """ arguments = [(b"message", amp.String())] response = [ (b"digest", amp.String()), (b"salt", amp.String()), # Is 'salt' the right term here? ] errors = []
class ListRelationsCommand(BaseCommand): # comma delimited strings arguments = [( "client_id", amp.String(), )] response = [("members", amp.String())]
class StartController(amp.Command): arguments = [('search_type', amp.String()), ('search_name', amp.String()), ('network', amp.String()), ('cloud_user', amp.String()), ('cloud_pass', amp.String())] response = [('started', amp.Boolean())]
class RelationSetCommand(BaseCommand): commandName = "relation_set" arguments = [( "client_id", amp.String(), ), ("json_blob", amp.String())] response = []
class ContinuationCommand(amp.Command): arguments = [ ('continuation', amp.String(optional=True)), ] response = [ ('items', amp.ListOf(amp.String())), ('continuation', amp.String(optional=True)), ]
class SetAutoScheduleModeCommand(amp.Command): arguments = [ ('uid', amp.String()), ('autoScheduleMode', amp.String()), ] response = [ ('success', amp.Boolean()), ]
class ContainsUIDsCommand(amp.Command): arguments = [ ('uid', amp.String()), ('testUid', amp.String()), ] response = [ ('result', amp.Boolean()), ]
class EventFired(amp.Command): """ Received by client when an event he has registered as a listener to has fired """ arguments = [("event_name", amp.String()), ("data", amp.String())] response = []
class ReSyncSession(amp.Command): arguments = [('sessId', amp.Integer()), ('ip', amp.String()), ('hostname', amp.String()), ('delim', amp.String()), ('playerId', amp.Integer()), ('time_connected', amp.Integer()), ('last_activity', amp.Float()), ('mxp', amp.Boolean())] response = [] errors = {Exception: 'EXCEPTION'}
class NewSession(amp.Command): arguments = [ ('sessId', amp.Integer()), ('ip', amp.String()), ('delim', amp.String()), ] response = [] errors = {Exception: 'EXCEPTION'}
class RecordWithGUIDCommand(amp.Command): arguments = [ ('guid', amp.String()), ('timeoutSeconds', amp.Integer(optional=True)), ] response = [ ('fields', amp.String()), ]
class WikiAccessForUIDCommand(amp.Command): arguments = [ ('wikiUID', amp.String()), ('uid', amp.String()), ] response = [ ('access', amp.String()), ]
class VerifyPlaintextPasswordCommand(amp.Command): arguments = [ ('uid', amp.String()), ('password', amp.String()), ] response = [ ('authenticated', amp.Boolean()), ]
class ExpandedMemberUIDsCommand(amp.Command): arguments = [ ('uid', amp.String()), ] response = [ ('items', amp.ListOf(amp.String())), ('continuation', amp.String(optional=True)), ]
class SetMembersCommand(amp.Command): arguments = [ ('uid', amp.String()), ('memberUIDs', amp.ListOf(amp.String())), ] response = [ ('success', amp.Boolean()), ]
class RecordWithShortNameCommand(amp.Command): arguments = [ ('recordType', amp.String()), ('shortName', amp.String()), ('timeoutSeconds', amp.Integer(optional=True)), ] response = [ ('fields', amp.String()), ]
class MsgServer2Portal(amp.Command): """ Message server -> portal """ key = "MsgServer2Portal" arguments = [('hashid', amp.String()), ('data', amp.String()), ('ipart', amp.Integer()), ('nparts', amp.Integer())] errors = [(Exception, 'EXCEPTION')] response = []
class MsgLauncher2Portal(amp.Command): """ Message Launcher -> Portal """ key = "MsgLauncher2Portal" arguments = [('operation', amp.String()), ('arguments', amp.String())] errors = {Exception: 'EXCEPTION'} response = []
class MsgStatus(amp.Command): """ Check Status between AMP services """ key = "MsgStatus" arguments = [('status', amp.String())] errors = {Exception: 'EXCEPTION'} response = [('status', amp.String())]
class Count(amp.Command): arguments = [('n', amp.Integer())] response = [('oki', amp.Integer()), ('oks', amp.String()), ('oku', amp.Unicode()), ('okb', amp.Boolean()), ('okf', amp.Float()), ('okd', amp.Decimal()), ('okt', amp.DateTime()), ('okl1', amp.ListOf(amp.Integer())), ('okl2', amp.ListOf(amp.ListOf(amp.String()))), ('okla', amp.AmpList([('a', amp.Integer()), ('b', amp.Unicode())]))]
class MsgLauncher2Portal(amp.Command): """ Message Launcher -> Portal """ key = "MsgLauncher2Portal" arguments = [(b"operation", amp.String()), (b"arguments", amp.String())] errors = {Exception: b"EXCEPTION"} response = []
class RelationGetCommand(BaseCommand): commandName = "relation_get" arguments = [( "client_id", amp.String(), ), ( "unit_name", amp.String(), ), ("setting_name", amp.String())] response = [("data", amp.String())]
class OnlineAccountVerifier_RegisterAddressToBallot(Command): arguments = [(b'ballot_id', amp.Integer()), (b'pickled_signed_token', amp.String()), (b'pickled_token', amp.String()), (b'pickled_voter_address', amp.String())] response = [(b'ok', amp.Boolean())] errors = { #TODO add errors Exception: b'OnlineAccountVerifier_RegisterAddressToBallot' }
class OnlineAccountVerifier_SignBlindToken(Command): arguments = [(b'user_id', amp.Integer()), (b'ballot_id', amp.Integer()), (b'blind_token', amp.String())] response = [(b'ok', amp.String())] errors = { psycopg2.IntegrityError: b'IntegrityError', psycopg2.ProgrammingError: b'ProgrammingError', UserNotRegisterdForBallot: b'NotRegistered', Exception: b'OnlineAccountVerifier_SignBlindToken' }
class AddClient(amp.Command): arguments = [('observer', amp.Boolean())] response = [ ('added', amp.Boolean()), ('reason', amp.Unicode()), ('ready', amp.Boolean()), ('player_count', amp.Integer()), ('experiment_pickle', amp.String()), ('conditions_pickle', amp.String()), ]
class MsgPortal2Server(amp.Command): """ Message portal -> server """ key = "MsgPortal2Server" arguments = [('sessid', amp.Integer()), ('ipart', amp.Integer()), ('nparts', amp.Integer()), ('msg', amp.String()), ('data', amp.String())] errors = [(Exception, 'EXCEPTION')] response = []
class RecordsWithEmailAddressCommand(amp.Command): arguments = [ ('emailAddress', amp.String()), ('limitResults', amp.Integer(optional=True)), ('timeoutSeconds', amp.Integer(optional=True)), ] response = [ ('items', amp.ListOf(amp.String())), ('continuation', amp.String(optional=True)), ]
class RegisterGame(amp.Command): ''' Registers a game running on the client with the server. ''' arguments = [('game', amp.String()), ('version', amp.String()), ('port', amp.Integer())] response = [] errors = { NotAuthenticated: 'NO_AUTH', PortUnreachable: 'BAD_PORT', }
class RecordsMatchingTokensCommand(amp.Command): arguments = [ ('tokens', amp.ListOf(amp.String())), ('context', amp.String(optional=True)), ('limitResults', amp.Integer(optional=True)), ('timeoutSeconds', amp.Integer(optional=True)), ] response = [ ('items', amp.ListOf(amp.String())), ('continuation', amp.String(optional=True)), ]