本文整理汇总了Python中organization.Organization类的典型用法代码示例。如果您正苦于以下问题:Python Organization类的具体用法?Python Organization怎么用?Python Organization使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Organization类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _generate_ovpn_conf
def _generate_ovpn_conf(self):
if not self.get_orgs():
raise ValueError("Ovpn conf cannot be generated without " + "any organizations")
logger.debug("Generating server ovpn conf. %r" % {"server_id": self.id})
if not self.primary_organization or not self.primary_user:
self._create_primary_user()
if not os.path.isfile(self.dh_param_path):
self._generate_dh_param()
primary_org = Organization(self.primary_organization)
primary_user = primary_org.get_user(self.primary_user)
self.generate_ca_cert()
self._generate_tls_verify()
self._generate_user_pass_verify()
if self.local_network:
push = "route %s %s" % self._parse_network(self.local_network)
else:
push = "redirect-gateway"
server_conf = OVPN_SERVER_CONF % (
self.port,
self.protocol,
self.interface,
self.ca_cert_path,
primary_user.cert_path,
primary_user.key_path,
self.tls_verify_path,
self.dh_param_path,
"%s %s" % self._parse_network(self.network),
self.ifc_pool_path,
push,
self.ovpn_status_path,
4 if self.debug else 1,
8 if self.debug else 3,
)
if self.otp_auth:
server_conf += "auth-user-pass-verify %s via-file\n" % (self.user_pass_verify_path)
if self.lzo_compression:
server_conf += 'comp-lzo\npush "comp-lzo"\n'
if self.local_network:
server_conf += "client-to-client\n"
with open(self.ovpn_conf_path, "w") as ovpn_conf:
ovpn_conf.write(server_conf)
示例2: leave_organization
def leave_organization(self, organization_id):
"""
remove relationship between user and organization
:param organization_id:
:return:
"""
#TODO exception handling
org = Organization()
org.id = organization_id
user_org_relationship = self._graph_db.match_one(start_node=self.user_node,
rel_type=GraphRelationship.MEMBER_OF,
end_node=org.org_node)
self._graph_db.delete(user_org_relationship)
示例3: _fill_users_pool
def _fill_users_pool(self):
end = True
for org in itertools.chain(Organization.iter_orgs(),
Organization.iter_orgs_pool()):
if not cache_db.set_length('openssl_tasks') and \
app_server.user_pool_size - org.client_pool_count > 0:
end = False
org.new_user(type=CERT_CLIENT_POOL)
if not cache_db.set_length('openssl_tasks') and \
app_server.server_user_pool_size - \
org.server_pool_size > 0:
end = False
org.new_user(type=CERT_SERVER_POOL)
if not end:
self._fill_users_pool()
示例4: _upgrade_data
def _upgrade_data(self):
version = self._get_version()
cur_version = self._get_data_version()
if cur_version and cur_version < self._get_version_int('0.10.5'):
logger.info('Upgrading data to v0.10.5...')
from server import Server
for server in Server.iter_servers():
server._upgrade_0_10_5()
from organization import Organization
for org in Organization.iter_orgs():
org._upgrade_0_10_5()
if cur_version and cur_version < self._get_version_int('0.10.6'):
logger.info('Upgrading data to v0.10.6...')
if self.password:
from cache import persist_db
logger.info('Upgrading config to v0.10.6...')
salt = base64.b64encode(
'2511cebca93d028393735637bbc8029207731fcf')
password = base64.b64encode(self.password.decode('hex'))
persist_db.dict_set('auth', 'password',
'0$%s$%s' % (salt, password))
self.password = None
self.commit()
from server import Server
for server in Server.iter_servers():
server._upgrade_0_10_6()
if cur_version and cur_version < self._get_version_int('0.10.9'):
logger.info('Upgrading data to v0.10.9...')
from server import Server
for server in Server.iter_servers():
server._upgrade_0_10_9()
from organization import Organization
for org in Organization.iter_orgs():
for user in org.iter_users():
user._upgrade_0_10_9()
org.sort_users_cache()
if cur_version != version:
from pritunl import __version__
version_path = os.path.join(self.data_path, VERSION_NAME)
with open(version_path, 'w') as version_file:
version_file.write('%s\n' % __version__)
示例5: get_event_admins
def get_event_admins(event):
global_admins = get_global_admins()
local_admins = Organization.gql(
'WHERE incidents = :1 AND is_admin = True AND name != :2',
event.key(), 'Admin'
)
return global_admins + list(local_admins)
示例6: AuthenticatedPost
def AuthenticatedPost(self, org, event):
# get and check args
ids = [int(id) for id in self.request.get('ids', '').split(',')]
selected_org = (
Organization.get(self.request.get('org'))
if self.request.get('org') else None
)
status = self.request.get('status')
action = self.request.get('action', None)
if action not in self.BULK_ACTIONS:
self.abort(404)
# get authorised events
if org.is_global_admin:
event_keys = list(event_db.Event.all(keys_only=True))
elif org.is_local_admin:
event_keys = org.incidents
# handle bulk action
fn = self.BULK_ACTIONS[action]
for id in ids:
site = Site.get_by_id(id)
authorised = (
site.event.key() in event_keys
and (selected_org is None or any(
incident_key in event_keys for incident_key in [
incident.key() for incident in org.incidents
])
)
)
if authorised:
fn(self, site, org=selected_org, status=status)
# redirect back to work orders table
self.redirect('/admin-view-work-orders')
示例7: dispatch
def dispatch(self, *args, **kwargs):
" All requests must have valid, in-date activation codes. "
self.page_blocks = page_db.get_page_block_dict()
self.activation_code = self.request.get('code')
if not self.activation_code:
self.abort(404)
# lookup org by activation code
orgs_by_code = Organization.all() \
.filter('activation_code', self.activation_code)
if orgs_by_code.count() != 1:
self.abort(404)
self.org_by_code = orgs_by_code[0]
# send response if already activated
if self.org_by_code.is_active:
self.render(
already_activated_template,
org=self.org_by_code
)
return
# send response if too late
if self.org_by_code.activate_by < datetime.datetime.utcnow():
self.render(
activation_too_late_template,
org=self.org_by_code
)
return
# continue handling request
super(ActivationHandler, self).dispatch(*args, **kwargs)
示例8: join_organization
def join_organization(self, organization_id):
"""
add user to organization
:param organization_id: string uuid
:return: list of tuple of interests
"""
#TODO exception handling
org = Organization()
org.id = organization_id
user_org_relationship = Relationship(self.user_node,
GraphRelationship.MEMBER_OF,
org.org_node)
try:
self._graph_db.create_unique(user_org_relationship)
except:
print sys.exc_info()[0]
示例9: _fill_cache
def _fill_cache(self):
logger.info('Preloading cache...')
from organization import Organization
for org in Organization.iter_orgs():
org._cache_users()
from server import Server
for server in Server.iter_servers():
server.load()
示例10: _generate_ovpn_conf
def _generate_ovpn_conf(self):
if not self.get_orgs():
raise ValueError('Ovpn conf cannot be generated without ' + \
'any organizations')
logger.debug('Generating server ovpn conf. %r' % {
'server_id': self.id,
})
if not self.primary_organization or not self.primary_user:
self._create_primary_user()
if not os.path.isfile(self.dh_param_path):
self._generate_dh_param()
primary_org = Organization(self.primary_organization)
primary_user = primary_org.get_user(self.primary_user)
self.generate_ca_cert()
self._generate_tls_verify()
if self.local_network:
push = 'route %s %s' % self._parse_network(
self.local_network)
else:
push = 'redirect-gateway'
with open(self.ovpn_conf_path, 'w') as ovpn_conf:
ovpn_conf.write(OVPN_SERVER_CONF % (
self.port,
self.protocol,
self.interface,
self.ca_cert_path,
primary_user.cert_path,
primary_user.key_path,
self.tls_verify_path,
self.dh_param_path,
'%s %s' % self._parse_network(self.network),
self.ifc_pool_path,
push,
self.ovpn_status_path,
4 if self.debug else 1,
8 if self.debug else 3,
))
示例11: user_orgs
def user_orgs(self):
"""
:return:
"""
user_orgs = self._graph_db.match(start_node=self.user_node,
rel_type=GraphRelationship.MEMBER_OF,
end_node=None)
orgs_list = []
for rel in user_orgs:
org_properties = dict(rel.end_node.properties)
org = Organization()
org.id = org_properties['id']
interests = org.org_interests
interests_list = []
for interest in interests:
interests_list.append(interest['name'])
org_properties['interests'] = interests_list
orgs_list.append(org_properties)
return orgs_list
示例12: get_org
def get_org(self, org_id):
if org_id in self.organizations:
org = Organization.get_org(id=org_id)
try:
org.load()
except IOError:
logger.exception('Failed to load org conf. %r' % {
'org_id': org_id,
})
return
return org
示例13: _remove_primary_user
def _remove_primary_user(self):
logger.debug("Removing primary user. %r" % {"server_id": self.id})
primary_organization = self.primary_organization
primary_user = self.primary_user
self.primary_organization = None
self.primary_user = None
if not primary_organization or not primary_user:
return
org = Organization(primary_organization)
user = org.get_user(primary_user)
if not user:
logger.debug(
"Primary user not found, skipping remove. %r"
% {"server_id": self.id, "org_id": org.id, "user_id": user.id}
)
return
if user:
user.remove()
示例14: organizations
def organizations(self):
"""
Active, verified organizations related to this incident.
Handles current and legacy incident/s properties.
"""
from organization import Organization # avoid circular import
# lookup using new incidents field
orgs = list(
Organization.all().filter('incidents', self.key())
.filter('org_verified', True)
.filter('is_active', True)
)
# build list of id and look for global admin
org_ids = set()
seen_global_admin = False
for org in orgs:
if org.is_global_admin:
seen_global_admin = True
org_id = org.key().id()
if org_id not in org_ids:
org_ids.add(org_id)
# check legacy incident field
legacy_field_orgs = Organization.all().filter('incident', self.key()) \
.filter('org_verified', True) \
.filter('is_active', True)
for org in legacy_field_orgs:
if org.key().id() not in org_ids:
orgs.append(org)
# prepend global admin if not encountered
if not seen_global_admin:
orgs = (
list(Organization.all().filter('name', 'Admin')) +
orgs
)
return orgs
示例15: iter_orgs
def iter_orgs(self):
orgs_dict = {}
orgs_sort = []
for org_id in self.organizations:
org = Organization.get_org(id=org_id)
if not org:
continue
name_id = '%s_%s' % (org.name, org.id)
orgs_dict[name_id] = org
orgs_sort.append(name_id)
for name_id in sorted(orgs_sort):
yield orgs_dict[name_id]