Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _make_linkauth_records():
"""
:return: s3 auth record, vertica auth record
"""
slar = hyperframe.S3LinkAuthRecord('id1234', 'keyabcd', 'tokenX', 'wildprofile')
vlar = hyperframe.DBLinkAuthRecord("/Library/Vertica/ODBC/lib/libverticaodbc.dylib",
"Intuit Vertica Connection",
"Analytics",
"pprddaavth-vip.ie.intuit.net",
"kyocum",
"something",
"5433",
"require",
"superprofile")
return slar, vlar
file_link = hyperframe.FileLinkRecord(hfid, None, BUNDLE_URI_SCHEME+'Users/someuser/somefile.txt')
frames.append(hyperframe.FrameRecord(name='links', hframe_uuid=hfid,
type='LINK',
shape=(1,),
links=[file_link,]))
if hframes is not None:
frames.append(hyperframe.FrameRecord(name='hframes', hframe_uuid=hfid,
type='HFRAME',
shape=(len(hframes),),
hframes=hframes))
lr = _make_lineage_record(name, hfid)
hf = hyperframe.HyperFrameRecord(owner='vklartho', human_name=name, uuid=hfid, frames=frames, lin_obj=lr, tags=tags)
return hf
def _make_lineage_record(hframe_name, hframe_uuid, depends_on=None):
"""
Args:
hframe_name:
hframe_uuid:
depends_on:
Returns:
(`LineageRecord`)
"""
lr = hyperframe.LineageRecord(hframe_name=hframe_name, hframe_uuid=hframe_uuid,
code_repo='bigdipper', code_name='unknown',
code_semver='0.1.0', code_hash='5cd60d3',
code_branch='develop', code_method='unknown', depends_on=depends_on)
return lr
Args:
hfr (`disdat.hyperframe.HyperFrameRecord`):
Returns:
"""
# Write DB HyperFrame
result = hyperframe.w_pb_db(hfr, self.local_engine)
# Write FS Frames
for fr in hfr.get_frames(self):
hyperframe.w_pb_fs(os.path.join(self.get_object_dir(), hfr.pb.uuid), fr)
# Write FS HyperFrame
hyperframe.w_pb_fs(os.path.join(self.get_object_dir(), hfr.pb.uuid), hfr)
# Write DB Frames
for fr in hfr.get_frames(self):
hyperframe.w_pb_db(fr, self.local_engine)
# Todo: Make it an option
# Note: We are changing the default human_name to be only the task name
# self.prune_uncommitted_history(hfr.pb.human_name)
return result
if no_force_required or force:
hyperframe.update_hfr_db(self.local_engine, hyperframe.RecordState.deleted, uuid=hfr_uuid)
self.rm_db_links(hfr[0], dry_run=False)
shutil.rmtree(self.implicit_hframe_path(hfr_uuid))
hyperframe.delete_hfr_db(self.local_engine, uuid=hfr_uuid)
hyperframe.delete_fr_db(self.local_engine, hfr_uuid)
else:
print ("Disdat: Looks like you're trying to remove a committed bundle with a db link backing a view.")
print ("Disdat: Removal of this bundle with db links that back a view requires '--force'")
return False
return True
except (IOError, os.error) as why:
_logger.error("Removal of hyperframe directory {} failed with error {}.".format(self.implicit_hframe_path(hfr_uuid), why))
# Must clean up db if directory removal failed, only delete same record if state marked for removal
hyperframe.delete_hfr_db(self.local_engine, uuid=hfr_uuid, state=hyperframe.RecordState.deleted)
return False
"""
try:
hfr = self.get_hframes(uuid=hfr_uuid)
assert hfr is not None
assert len(hfr) == 1
# First, test whether any db links are used to back the current view
no_force_required = self.rm_db_links(hfr[0])
if no_force_required or force:
hyperframe.update_hfr_db(self.local_engine, hyperframe.RecordState.deleted, uuid=hfr_uuid)
self.rm_db_links(hfr[0], dry_run=False)
shutil.rmtree(self.implicit_hframe_path(hfr_uuid))
hyperframe.delete_hfr_db(self.local_engine, uuid=hfr_uuid)
hyperframe.delete_fr_db(self.local_engine, hfr_uuid)
else:
print ("Disdat: Looks like you're trying to remove a committed bundle with a db link backing a view.")
print ("Disdat: Removal of this bundle with db links that back a view requires '--force'")
return False
return True
except (IOError, os.error) as why:
_logger.error("Removal of hyperframe directory {} failed with error {}.".format(self.implicit_hframe_path(hfr_uuid), why))
# Must clean up db if directory removal failed, only delete same record if state marked for removal
hyperframe.delete_hfr_db(self.local_engine, uuid=hfr_uuid, state=hyperframe.RecordState.deleted)
return False
auths = {}
pb_types = [('*_hframe.pb', hyperframe.HyperFrameRecord, hframes),
('*_frame.pb', hyperframe.FrameRecord, frames),
('*_auth.pb', hyperframe.LinkAuthBase, auths)]
# Make all the tables first.
for glb, rcd_type, store in pb_types:
rcd_type.create_table(self.local_engine)
for uuid_dir in os.listdir(self.get_object_dir()):
for glb, rcd_type, store in pb_types:
files = glob.glob(os.path.join(os.path.join(self.get_object_dir(), uuid_dir), glb))
for f in files:
# hyperframes, frames, and links all have uuid fields
rcd = hyperframe.r_pb_fs(f, rcd_type)
store[rcd.pb.uuid] = rcd
for hfr in hframes.values():
if DataContext._validate_hframe(hfr, frames, auths):
# looks like a good hyperframe
# see if it exists, if it does do not write hframe and assume frames are also present
# if ignore_existing==False, then we will try to insert into DB anyhow.
hfr_from_db_list = hyperframe.select_hfr_db(self.local_engine, uuid=hfr.pb.uuid)
if not ignore_existing or len(hfr_from_db_list) == 0:
hyperframe.w_pb_db(hfr, self.local_engine)
for str_tuple in hfr.pb.frames:
fr_uuid = str_tuple.v
hfr_from_db_list = hyperframe.select_hfr_db(self.local_engine, uuid=fr_uuid)
if not ignore_existing or len(hfr_from_db_list) == 0:
# The frame pb doesn't store the hfr_uuid, but the db
# does. Since we are reading from disk, we need to
hfr_from_db_list = hyperframe.select_hfr_db(self.local_engine, uuid=hfr.pb.uuid)
if not ignore_existing or len(hfr_from_db_list) == 0:
hyperframe.w_pb_db(hfr, self.local_engine)
for str_tuple in hfr.pb.frames:
fr_uuid = str_tuple.v
hfr_from_db_list = hyperframe.select_hfr_db(self.local_engine, uuid=fr_uuid)
if not ignore_existing or len(hfr_from_db_list) == 0:
# The frame pb doesn't store the hfr_uuid, but the db
# does. Since we are reading from disk, we need to
# set it back into the FrameRecord.
frames[fr_uuid].hframe_uuid = hfr.pb.uuid
hyperframe.w_pb_db(frames[fr_uuid], self.local_engine)
else:
# invalid hyperframe, if present in db as valid, mark invalid
# Try to read it in
hfr_from_db_list = hyperframe.select_hfr_db(self.local_engine, uuid=hfr.pb.uuid)
assert(len(hfr_from_db_list) == 0 or len(hfr_from_db_list) == 1)
if len(hfr_from_db_list) == 1:
hfr_from_db = hfr_from_db_list[0]
if hfr_from_db.state == hyperframe.RecordState.valid:
# If it is valid, and we know it isn't, mark invalid
hyperframe.update_hfr_db(self.local_engine, hyperframe.RecordState.invalid,
uuid=hfr.pb.uuid)
# else, pending, invalid, deleted is all OK with an invalid hyperframe
if DataContext._validate_hframe(hfr, frames, auths):
# looks like a good hyperframe
# see if it exists, if it does do not write hframe and assume frames are also present
# if ignore_existing==False, then we will try to insert into DB anyhow.
hfr_from_db_list = hyperframe.select_hfr_db(self.local_engine, uuid=hfr.pb.uuid)
if not ignore_existing or len(hfr_from_db_list) == 0:
hyperframe.w_pb_db(hfr, self.local_engine)
for str_tuple in hfr.pb.frames:
fr_uuid = str_tuple.v
hfr_from_db_list = hyperframe.select_hfr_db(self.local_engine, uuid=fr_uuid)
if not ignore_existing or len(hfr_from_db_list) == 0:
# The frame pb doesn't store the hfr_uuid, but the db
# does. Since we are reading from disk, we need to
# set it back into the FrameRecord.
frames[fr_uuid].hframe_uuid = hfr.pb.uuid
hyperframe.w_pb_db(frames[fr_uuid], self.local_engine)
else:
# invalid hyperframe, if present in db as valid, mark invalid
# Try to read it in
hfr_from_db_list = hyperframe.select_hfr_db(self.local_engine, uuid=hfr.pb.uuid)
assert(len(hfr_from_db_list) == 0 or len(hfr_from_db_list) == 1)
if len(hfr_from_db_list) == 1:
hfr_from_db = hfr_from_db_list[0]
if hfr_from_db.state == hyperframe.RecordState.valid:
# If it is valid, and we know it isn't, mark invalid
hyperframe.update_hfr_db(self.local_engine, hyperframe.RecordState.invalid,
uuid=hfr.pb.uuid)
# else, pending, invalid, deleted is all OK with an invalid hyperframe
fr (`FrameRecord`):
found_auths (dict):
Returns:
valid (bool): This frame corresponds to what we have on disk
"""
if fr.is_link_frame():
for l in fr.pb.links:
if l.linkauth_uuid != '': # empty string is PB default value when not set
if l.linkauth_uuid not in found_auths:
_logger.warn("Frame name {} with invalid link auth {} in link {}".format(fr.pb.name,
l.linkauth_uuid,
l.uuid))
return False
url = hyperframe.LinkBase.find_url(l)
o = urllib.parse.urlparse(url)
if o.scheme == 's3':
_logger.warn("Disdat FS TODO check on s3 for file {}".format(url))
elif o.scheme == 'db':
pass
#_logger.warn("Disdat FS TODO support db tables in link columns")
elif o.scheme == 'bundle':
# this is OK. file links are bundle urls.
pass
#_logger.debug("Disdat FS TODO check on bundle links for {}".format(url))
elif o.scheme == 'file':
if not os.path.exists(o.path):
_logger.warn("Frame name {} contains file {} not found on disk.".format(fr.pb.name,
os.path))
return False
else: