本文整理汇总了Python中calvin.utilities.security.Security.set_principal方法的典型用法代码示例。如果您正苦于以下问题:Python Security.set_principal方法的具体用法?Python Security.set_principal怎么用?Python Security.set_principal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calvin.utilities.security.Security
的用法示例。
在下文中一共展示了Security.set_principal方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compile
# 需要导入模块: from calvin.utilities.security import Security [as 别名]
# 或者: from calvin.utilities.security.Security import set_principal [as 别名]
def compile(source_text, filename='', content=None, credentials=None, verify=True):
# Steps taken:
# 1) Verify signature when credentials supplied
# 2) parser .calvin file -> IR. May produce syntax errors/warnings
# 3) checker IR -> IR. May produce syntax errors/warnings
# 4) analyzer IR -> app. Should not fail. Sets 'valid' property of IR to True/False
deployable = {'valid': False, 'actors': {}, 'connections': {}}
errors = [] #TODO: fill in something meaningful
warnings = []
if credentials:
_log.debug("Check credentials...")
sec = Security()
sec.set_principal(credentials)
if not sec.authenticate_principal():
_log.error("Check credentials...failed authentication")
# This error reason is detected in calvin control and gives proper REST response
errors.append({'reason': "401: UNAUTHORIZED", 'line': 0, 'col': 0})
return deployable, errors, warnings
if not sec.verify_signature_content(content, "application"):
_log.error("Check credentials...failed application verification")
# This error reason is detected in calvin control and gives proper REST response
errors.append({'reason': "401: UNAUTHORIZED", 'line': None, 'col': None})
return deployable, errors, warnings
_log.debug("Parsing...")
ir, errors, warnings = calvin_parser(source_text, filename)
_log.debug("Parsed %s, %s, %s" % (ir, errors, warnings))
# If there were errors during parsing no IR will be generated
if not errors:
c_errors, c_warnings = check(ir, verify=verify)
errors.extend(c_errors)
warnings.extend(c_warnings)
deployable = generate_app_info(ir, verify=verify)
if errors:
deployable['valid'] = False
_log.debug("Compiled %s, %s, %s" % (deployable, errors, warnings))
return deployable, errors, warnings
示例2: _new_actor
# 需要导入模块: from calvin.utilities.security import Security [as 别名]
# 或者: from calvin.utilities.security.Security import set_principal [as 别名]
def _new_actor(self, actor_type, actor_id=None, credentials=None):
"""Return a 'bare' actor of actor_type, raises an exception on failure."""
if credentials is not None:
sec = Security()
sec.set_principal(credentials)
sec.authenticate_principal()
else:
sec = None
(found, is_primitive, class_) = ActorStore(security=sec).lookup(actor_type)
if not found:
# Here assume a primtive actor, now become shadow actor
_log.analyze(self.node.id, "+ NOT FOUND CREATE SHADOW ACTOR", {'class': class_})
found = True
is_primitive = True
class_ = ShadowActor
if not found or not is_primitive:
_log.error("Requested actor %s is not available" % (actor_type))
raise Exception("ERROR_NOT_FOUND")
try:
# Create a 'bare' instance of the actor
a = class_(actor_type, actor_id=actor_id)
except Exception as e:
_log.exception("")
_log.error("The actor %s(%s) can't be instantiated." % (actor_type, class_.__init__))
raise(e)
try:
a.set_credentials(credentials, security=sec)
a._calvinsys = self.node.calvinsys()
a.check_requirements()
except Exception as e:
_log.exception("Catched new from state")
_log.analyze(self.node.id, "+ FAILED REQS CREATE SHADOW ACTOR", {'class': class_})
a = ShadowActor(actor_type, actor_id=actor_id)
a.set_credentials(credentials, security=sec)
a._calvinsys = self.node.calvinsys()
return a
示例3: Actor
# 需要导入模块: from calvin.utilities.security import Security [as 别名]
# 或者: from calvin.utilities.security.Security import set_principal [as 别名]
#.........这里部分代码省略.........
self.control = calvincontrol.get_calvincontrol()
self.metering = metering.get_metering()
self._migrating_to = None # During migration while on the previous node set to the next node id
self._last_time_warning = 0.0
self.credentials = None
self.inports = {p: actorport.InPort(p, self) for p in self.inport_names}
self.outports = {p: actorport.OutPort(p, self) for p in self.outport_names}
hooks = {
(Actor.STATUS.PENDING, Actor.STATUS.ENABLED): self.will_start,
(Actor.STATUS.ENABLED, Actor.STATUS.PENDING): self.will_stop,
}
self.fsm = Actor.FSM(Actor.STATUS, Actor.STATUS.LOADED, Actor.VALID_TRANSITIONS, hooks,
allow_invalid_transitions=allow_invalid_transitions,
disable_transition_checks=disable_transition_checks,
disable_state_checks=disable_state_checks)
self.metering.add_actor_info(self)
def set_credentials(self, credentials, security=None):
""" Sets the credentials the actor operates under
This will trigger an authentication of the credentials
Optionally an authenticated Security instance can be supplied,
to reduce the needed authentication processing.
"""
_log.debug("actor.py: set_credentials: %s" % credentials)
if credentials is None:
return
self.credentials = credentials
if security:
self.sec = security
else:
self.sec = Security()
self.sec.set_principal(self.credentials)
self.sec.authenticate_principal()
def get_credentials(self):
_log.debug("actor.py: get_credentials: %s" % self.credentials)
return self.credentials
@verify_status([STATUS.LOADED])
def setup_complete(self):
self.fsm.transition_to(Actor.STATUS.READY)
def init(self):
raise Exception("Implementing 'init()' is mandatory.")
def will_start(self):
"""Override in actor subclass if actions need to be taken before starting."""
pass
def will_stop(self):
"""Override in actor subclass if actions need to be taken before stopping."""
pass
def will_migrate(self):
"""Override in actor subclass if actions need to be taken before migrating."""
pass
def did_migrate(self):
"""Override in actor subclass if actions need to be taken after migrating."""
pass
def will_end(self):
"""Override in actor subclass if actions need to be taken before destruction."""
pass