示例#1
0
 def handle(self):
     salt = uuid4().hex
     input = self.request.input
     input.password = tech_account_password(uuid4().hex, salt)
     
     with closing(self.odb.session()) as session:
         cluster = session.query(Cluster).filter_by(id=input.cluster_id).first()
         
         # Let's see if we already have an account of that name before committing
         # any stuff into the database.
         existing_one = session.query(TechnicalAccount).\
             filter(Cluster.id==input.cluster_id).\
             filter(TechnicalAccount.name==input.name).first()
         
         if existing_one:
             raise Exception('Technical account [{0}] already exists on this cluster'.format(input.name))
         
         try:
             tech_account = TechnicalAccount(None, input.name, input.is_active, input.password, salt, cluster=cluster)
             session.add(tech_account)
             session.commit()
             
         except Exception, e:
             msg = 'Could not create a technical account, e:[{e}]'.format(e=format_exc(e))
             self.logger.error(msg)
             session.rollback()
             
             raise 
         else:
示例#2
0
def change_password(req):
    return _change_password(req, 'zato.security.tech-account.change-password')


@method_allowed('GET')
def get_by_id(req, id_, cluster_id):
    try:
        response = req.zato.client.invoke(
            'zato.security.tech-account.get-by-id', {'id': id_})
    except Exception, e:
        msg = 'Could not fetch the technical account, e:[{e}]'.format(
            e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
    else:
        tech_account = TechnicalAccount()
        tech_account.id = response.data.id
        tech_account.name = response.data.name
        tech_account.is_active = response.data.is_active

        return HttpResponse(tech_account.to_json(),
                            mimetype='application/javascript')


class Index(_Index):
    method_allowed = 'GET'
    url_name = 'security-tech-account'
    template = 'zato/security/tech-account.html'

    service_name = 'zato.security.tech-account.get-list'
    output_class = TechnicalAccount
示例#3
0
    
@method_allowed('POST')
def change_password(req):
    return _change_password(req, 'zato.security.tech-account.change-password')
    
    
@method_allowed('GET')
def get_by_id(req, id_, cluster_id):
    try:
        response = req.zato.client.invoke('zato.security.tech-account.get-by-id', {'id':id_})
    except Exception, e:
        msg = 'Could not fetch the technical account, e:[{e}]'.format(e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
    else:
        tech_account = TechnicalAccount()
        tech_account.id = response.data.id
        tech_account.name = response.data.name
        tech_account.is_active = response.data.is_active

        return HttpResponse(tech_account.to_json(), mimetype='application/javascript')
    
class Index(_Index):
    method_allowed = 'GET'
    url_name = 'security-tech-account'
    template = 'zato/security/tech-account.html'
    
    service_name = 'zato.security.tech-account.get-list'
    output_class = TechnicalAccount
    
    class SimpleIO(_Index.SimpleIO):
示例#4
0
def change_password(req):
    return _change_password(req, "zato:security.tech-account.change-password")


@meth_allowed("GET")
def get_by_id(req, tech_account_id, cluster_id):
    try:
        zato_message, soap_response = invoke_admin_service(
            req.zato.cluster, "zato:security.tech-account.get-by-id", {"tech_account_id": tech_account_id}
        )
    except Exception, e:
        msg = "Could not fetch the technical account, e:[{e}]".format(e=format_exc(e))
        logger.error(msg)
        return HttpResponseServerError(msg)
    else:
        tech_account = TechnicalAccount()
        tech_account_elem = zato_message.response.item

        tech_account.id = tech_account_elem.id.text
        tech_account.name = tech_account_elem.name.text
        tech_account.is_active = is_boolean(tech_account_elem.is_active.text)

        return HttpResponse(tech_account.to_json(), mimetype="application/javascript")


class Index(_Index):
    meth_allowed = "GET"
    url_name = "security-tech-account"
    template = "zato/security/tech-account.html"

    soap_action = "zato:security.tech-account.get-list"