# Path: opennode/oms/security/interaction.py
# def new_interaction(principal):
#     if not IPrincipal.providedBy(principal):
#         auth = getUtility(IAuthentication, context=None)
#         principal = auth.getPrincipal(principal)
# 
#     interaction = OmsSecurityPolicy()
#     interaction.add(SessionStub(principal))
#     return interaction


from twisted.python import log
from zope.authentication.interfaces import IAuthentication
from zope.component import getUtility
from opennode.oms.config import get_config
from opennode.oms.security.interaction import new_interaction



class DetachedProtocol(object):
    """This represents a detached background protocol used to execute commands
    in background and redirect output to logs"""

    def __init__(self, interaction=None):
        self.terminal = self
        self.protocol = self
        self.path = ['']
        self.use_security_proxy = False
        if interaction is None:
            auth = getUtility(IAuthentication)
            self.interaction = new_interaction(auth.getPrincipal('root'))
        else:
            self.interaction = interaction

    @property
    def principal(self):

# Path: opennode/oms/security/interaction.py
# def new_interaction(principal):
#     if not IPrincipal.providedBy(principal):
#         auth = getUtility(IAuthentication, context=None)
#         principal = auth.getPrincipal(principal)
# 
#     interaction = OmsSecurityPolicy()
#     interaction.add(SessionStub(principal))
#     return interaction


# Path: opennode/oms/endpoint/ssh/detached.py
from twisted.python import log
from zope.authentication.interfaces import IAuthentication
from zope.component import getUtility
from opennode.oms.config import get_config
from opennode.oms.security.interaction import new_interaction




class DetachedProtocol(object):
    """This represents a detached background protocol used to execute commands
    in background and redirect output to logs"""

    def __init__(self, interaction=None):
        self.terminal = self
        self.protocol = self
        self.path = ['']
        self.use_security_proxy = False
        if interaction is None:
            auth = getUtility(IAuthentication)
            self.interaction = new_interaction(auth.getPrincipal('root'))
        else:
            self.interaction = interaction

    @property
    def principal(self):

        return self.interaction.participations[0].principal