def list(self, args, props): namespace, pname = parseQName(args.name, props) if pname: pname = ('/%s' % pname) if pname.endswith('/') else '/%s/' % pname url = 'https://%(apibase)s/namespaces/%(namespace)s/%(collection)s%(package)s?skip=%(skip)s&limit=%(limit)s%(public)s' % { 'apibase': apiBase(props), 'namespace': urllib.quote(namespace), 'collection': self.collection, 'package': pname if pname else '', 'skip': args.skip, 'limit': args.limit, 'public': '&public=true' if 'shared' in args and args.shared else '' } res = request('GET', url, auth=args.auth, verbose=args.verbose) if res.status == httplib.OK: result = json.loads(res.read()) print bold(self.collection) for e in result: print self.formatListEntity(e) return 0 else: return responseError(res)
def getEntitySummary(self, entity, includeParams=True, kind=None, namespace=None): kind = self.name if kind is None else kind namespace = entity['namespace'] if 'namespace' in entity else namespace fullName = getQName(entity['name'], namespace) annotations = entity['annotations'] description = getDescriptionFromAnnotations(annotations) summary = '%s %s' % (bold(kind), fullName) if description: summary += ': %s' % (description) if includeParams: parameterNames = getParameterNamesFromAnnotations(annotations) if parameterNames: summary += '\n (%s: %s)' % (bold('params'), ' '.join(parameterNames)) if 'actions' in entity: for a in entity['actions']: actionSummary = self.getEntitySummary(a, False, 'action', fullName) summary += '\n %s' % (actionSummary) if 'feeds' in entity: for a in entity['feeds']: actionSummary = self.getEntitySummary(a, False, 'feed ', fullName) summary += '\n %s' % (actionSummary) return summary
def printCollection(self, result, collection): if collection in result: print bold(collection) for e in result[collection]: if collection == 'actions': print Action().formatListEntity(e) elif collection == 'triggers': print Trigger().formatListEntity(e) elif collection == 'rules': print Rule().formatListEntity(e) elif collection == 'packages': print Package().formatListEntity(e)
def listNamespaces(self, args, props): url = 'https://%(apibase)s/namespaces' % { 'apibase': apiBase(props) } res = request('GET', url, auth=args.auth, verbose=args.verbose) if res.status == httplib.OK: result = json.loads(res.read()) print bold('namespaces') for n in result: print '{:<25}'.format(n) return 0 else: return responseError(res)
def listNamespaces(self, args, props): url = 'https://%(apibase)s/namespaces' % {'apibase': apiBase(props)} res = request('GET', url, auth=args.auth, verbose=args.verbose) if res.status == httplib.OK: result = json.loads(res.read()) print bold("namespaces") for n in result: print "{:<25}".format(n) return 0 else: return responseError(res)
def list(self, args, props): name = args.name if args.name else '/_' args.name = getQName(name, '_') # kludge: use default namespace unless explicitly specified res = self.listCmd(args, props) if res.status == httplib.OK: result = json.loads(res.read()) print bold('activations') for a in result: if args.full: print getPrettyJson(a) else: print '{:<45}{:<40}'.format(a['activationId'], a['name']) return 0 else: return responseError(res)
def invoke(self, args, props): res = self.doInvoke(args, props) # OK implies successful blocking invoke # ACCEPTED implies non-blocking # All else are failures if res.status == httplib.OK or res.status == httplib.ACCEPTED: result = json.loads(res.read()) if not (args.result and args.blocking and res.status == httplib.OK): print 'ok: invoked %(name)s with id %(id)s' % {'name': args.name, 'id': result['activationId'] } if res.status == httplib.OK and args.result: print getPrettyJson(result['response']['result']) elif res.status == httplib.OK : print bold('response:') print getPrettyJson(result['response']) return 0 else: return responseError(res)
def invoke(self, args, props): res = self.doInvoke(args, props) # OK implies successful blocking invoke # ACCEPTED implies non-blocking # All else are failures if res.status == httplib.OK or res.status == httplib.ACCEPTED: result = json.loads(res.read()) if not (args.result and args.blocking and res.status == httplib.OK): print 'ok: invoked %(name)s with id %(id)s' % { 'name': args.name, 'id': result['activationId'] } if res.status == httplib.OK and args.result: print getPrettyJson(result['response']['result']) elif res.status == httplib.OK: print bold('response:') print getPrettyJson(result['response']) return 0 else: return responseError(res)
def getEntitySummary(self, entity, includeParams = True, kind = None, namespace = None): kind = self.name if kind is None else kind namespace = entity['namespace'] if 'namespace' in entity else namespace fullName = getQName(entity['name'], namespace) annotations = entity['annotations'] description = getDescriptionFromAnnotations(annotations) summary = '%s %s' % (bold(kind), fullName) if description: summary += ': %s' % (description) if includeParams: parameterNames = getParameterNamesFromAnnotations(annotations) if parameterNames: summary += '\n (%s: %s)' % (bold('params'), ' '.join(parameterNames)) if 'actions' in entity: for a in entity['actions']: actionSummary = self.getEntitySummary(a, False, 'action', fullName) summary += '\n %s' % (actionSummary) if 'feeds' in entity: for a in entity['feeds']: actionSummary = self.getEntitySummary(a, False, 'feed ', fullName) summary += '\n %s' % (actionSummary) return summary
def listEntitiesInNamespace(self, args, props): namespace, _ = parseQName(args.name, props) url = 'https://%(apibase)s/namespaces/%(namespace)s' % { 'apibase': apiBase(props), 'namespace': urllib.quote(namespace) } res = request('GET', url, auth=args.auth, verbose=args.verbose) if res.status == httplib.OK: result = json.loads(res.read()) print 'entities in namespace: %s' % bold(namespace if namespace != '_' else 'default') self.printCollection(result, 'packages') self.printCollection(result, 'actions') self.printCollection(result, 'triggers') self.printCollection(result, 'rules') return 0 else: return responseError(res)
def listEntitiesInNamespace(self, args, props): namespace, _ = parseQName(args.name, props) url = 'https://%(apibase)s/namespaces/%(namespace)s' % { 'apibase': apiBase(props), 'namespace': urllib.quote(namespace) } res = request('GET', url, auth=args.auth, verbose=args.verbose) if res.status == httplib.OK: result = json.loads(res.read()) print 'entities in namespace: %s' % bold( namespace if namespace != '_' else 'default') self.printCollection(result, 'packages') self.printCollection(result, 'actions') self.printCollection(result, 'triggers') self.printCollection(result, 'rules') return 0 else: return responseError(res)