Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
clause = cl_bundle_dependency.c.child_uuid == cl_bundle.c.uuid
else: # embedded
clause = cl_bundle.c.uuid.in_(
alias(select([cl_bundle_dependency.c.child_uuid]).where(condition))
)
elif key.startswith('dependency/'):
_, name = key.split('/', 1)
condition = make_condition(key, cl_bundle_dependency.c.parent_uuid, value)
if condition is None: # top-level
clause = and_(
cl_bundle_dependency.c.child_uuid == cl_bundle.c.uuid, # Join constraint
cl_bundle_dependency.c.child_path
== name, # Match the 'type' of dependent (child_path)
)
else: # embedded
clause = cl_bundle.c.uuid.in_(
alias(
select([cl_bundle_dependency.c.child_uuid]).where(
and_(
cl_bundle_dependency.c.child_path
== name, # Match the 'type' of dependent (child_path)
condition,
)
)
)
)
elif key == 'host_worksheet':
condition = make_condition(key, cl_worksheet_item.c.worksheet_uuid, value)
if condition is None: # top-level
clause = cl_worksheet_item.c.bundle_uuid == cl_bundle.c.uuid # Join constraint
else:
clause = cl_bundle.c.uuid.in_(
def remove_data_hash_references(self, uuids):
with self.engine.begin() as connection:
connection.execute(
cl_bundle.update().where(cl_bundle.c.uuid.in_(uuids)).values({'data_hash': None})
)
cl_group_bundle_permission.delete().where(
cl_group_bundle_permission.c.object_uuid.in_(uuids)
)
)
connection.execute(
cl_worksheet_item.delete().where(cl_worksheet_item.c.bundle_uuid.in_(uuids))
)
connection.execute(
cl_bundle_metadata.delete().where(cl_bundle_metadata.c.bundle_uuid.in_(uuids))
)
connection.execute(
cl_bundle_dependency.delete().where(cl_bundle_dependency.c.child_uuid.in_(uuids))
)
# In case something goes wrong, delete bundles that are currently running on workers.
connection.execute(cl_worker_run.delete().where(cl_worker_run.c.run_uuid.in_(uuids)))
connection.execute(cl_bundle.delete().where(cl_bundle.c.uuid.in_(uuids)))
else: # embedded
clause = cl_bundle.c.uuid.in_(
select([cl_bundle_metadata.c.bundle_uuid]).where(
and_(cl_bundle_metadata.c.metadata_key == key, condition)
)
)
if clause is not None:
clauses.append(clause)
clause = and_(*clauses)
if user_id != self.root_user_id:
# Restrict to the bundles that we have access to.
access_via_owner = cl_bundle.c.owner_id == user_id
access_via_group = cl_bundle.c.uuid.in_(
select([cl_group_bundle_permission.c.object_uuid]).where(
and_(
or_( # Join constraint (group)
cl_group_bundle_permission.c.group_uuid
== self.public_group_uuid, # Public group
cl_group_bundle_permission.c.group_uuid.in_(
alias(
select([cl_user_group.c.group_uuid]).where(
cl_user_group.c.user_id == user_id
)
)
), # Private group
),
cl_group_bundle_permission.c.permission
>= GROUP_OBJECT_PERMISSION_READ, # Match the uuid of the parent
)
select([cl_bundle_metadata.c.bundle_uuid]).where(
and_(
cl_bundle_metadata.c.metadata_key == 'name',
cl_bundle_metadata.c.metadata_value.like('%' + value + '%'),
)
)
)
)
)
clause = or_(*clause)
elif key == '': # Match any field
clause = []
clause.append(cl_bundle.c.uuid.like('%' + value + '%'))
clause.append(cl_bundle.c.command.like('%' + value + '%'))
clause.append(
cl_bundle.c.uuid.in_(
alias(
select([cl_bundle_metadata.c.bundle_uuid]).where(
cl_bundle_metadata.c.metadata_value.like('%' + value + '%')
)
)
)
)
clause = or_(*clause)
# Otherwise, assume metadata.
else:
condition = make_condition(key, cl_bundle_metadata.c.metadata_value, value)
if condition is None: # top-level
clause = and_(
cl_bundle.c.uuid == cl_bundle_metadata.c.bundle_uuid,
cl_bundle_metadata.c.metadata_key == key,
)
select([cl_group_bundle_permission.c.object_uuid]).where(
and_(
cl_group_bundle_permission.c.group_uuid.in_(
alias(
select([cl_user_group.c.group_uuid]).where(
cl_user_group.c.user_id == user_id
)
)
),
cl_group_bundle_permission.c.permission >= GROUP_OBJECT_PERMISSION_READ,
)
)
)
elif key == 'group': # shared with group with read permission
group_uuid = get_group_info(value, False)['uuid']
clause = cl_bundle.c.uuid.in_(
select([cl_group_bundle_permission.c.object_uuid]).where(
and_(
cl_group_bundle_permission.c.group_uuid == group_uuid,
cl_group_bundle_permission.c.permission >= GROUP_OBJECT_PERMISSION_READ,
)
)
)
# Special fields
elif key == 'dependency':
# Match uuid of dependency
condition = make_condition(key, cl_bundle_dependency.c.parent_uuid, value)
if condition is None: # top-level
clause = cl_bundle_dependency.c.child_uuid == cl_bundle.c.uuid
else: # embedded
clause = cl_bundle.c.uuid.in_(
alias(select([cl_bundle_dependency.c.child_uuid]).where(condition))