def read(fn): d = dict() lines = storage.read_file(fn, True) for line in lines: edgeid = int(line.split("=")[0]) d[edgeid] = line[:-1].split("=")[1].split(",") return d
def read_volume_pubkey( volume_name, prefix=None ): # support prefix, since sometimes this can be called before storage is initialized if prefix is None: prefix = "/" pubkey_path = storage.path_join(prefix, volume_pubkey_path( volume_name )) return storage.read_file( pubkey_path, volume=None )
def read_gateway_port(): name_path = storage.local_path( GATEWAY_STORAGE_DIR, "gateway_port" ) rc = storage.read_file( name_path, volume=None ) try: rc = int(rc) return rc except: return None
def load_private_key_from_path( key_path, password, local ): encrypted_privkey_str = None if local: encrypted_privkey_str = storage.read_file( key_path, volume=None ) else: encrypted_privkey_str = storage.read_file( key_path ) if encrypted_privkey_str is None: log.error("Failed to load key from %s" % key_path ) return None try: encrypted_private_key = storage.json_to_tuple( EncryptedPrivateKey, encrypted_privkey_str ) except Exception, e: log.error("Failed to unserialize private key") return None
def read_gateway_privkey( password, gateway_name ): path = gateway_privkey_path( gateway_name ) encrypted_privkey_json = storage.read_file( path, volume=None ) try: encrypted_privkey = storage.json_to_tuple( keys.EncryptedPrivateKey, encrypted_privkey_json ) except Exception, e: log.exception(e) log.error("Failed to unserialize encrypted private gateway key") return None
def load_public_key( key_name, syndicate_user_pubkey ): key_path = make_key_local_path( key_name + ".pub" ) pubkey_json = storage.read_file( key_path, volume=None ) if pubkey_json is None: log.error("Failed to load public key") return False try: pubkey = storage.json_to_tuple( SignedPublicKey, pubkey_json ) except Exception, e: log.error("Failed to unserialize signed public key") log.exception(e) return False
def load_options( argv, description, config_opts, default_config_file_path ): parser = conf.build_parser( argv[0], description, config_opts ) opts = parser.parse_args( argv[1:] ) # load everything into a dictionary and return it config = None config_str = None config_file_path = None if hasattr( opts, "config" ) and opts.config != None: config_file_path = opts.config[0] else: config_file_path = default_config_file_path config_str = storage.read_file( config_file_path ) if config_str == None: log.warning("Failed to read config file at %s" % config_file_path ) config = conf.load_config( config_str, config_opts, opts ) if config == None: raise Exception("Failed to parse configuration from %s" % config_file_path) return config
def read_gateway_name(): name_path = storage.local_path( GATEWAY_STORAGE_DIR, "gateway_name" ) return storage.read_file( name_path, volume=None )
except Exception, e: log.exception(e) log.error("Failed to set up Volume access") cleanup_syntool( [expected_gateway_pkey_path, expected_gateway_signingkey_path], tmpdir ) return False cleanup_files = [expected_gateway_pkey_path, expected_gateway_signingkey_path] if gateway_pkey_pem is None: # get the private key if not storage.path_exists( expected_gateway_pkey_path, volume=None ): log.error("Failed to create gateway %s (no key in %s), ret = %s" % (gateway_name, expected_gateway_pkey_path, gateway_info) ) cleanup_syntool( cleanup_files, tmpdir ) return False gateway_pkey_pem = storage.read_file( expected_gateway_pkey_path, volume=None ) if gateway_pkey_pem is None: log.error("Failed to load private key from %s" % expected_gateway_pkey_path ) cleanup_syntool( cleanup_files, tmpdir ) return None # store the key rc = write_gateway_privkey( mail_password, gateway_name, gateway_pkey_pem ) if not rc: log.error("Failed to store gateway private key") cleanup_syntool( cleanup_files, tmpdir ) return False else: # everything should be in place already cleanup_files = []
def update_repo(storage, sign): filelists = {} primary = {} revision = "0" if storage.exists('repodata/repomd.xml'): data = storage.read_file('repodata/repomd.xml') filelists, primary, revision = parse_repomd(data) data = storage.read_file(filelists['location']) filelists = parse_filelists(gunzip_string(data)) data = storage.read_file(primary['location']) primary = parse_primary(gunzip_string(data)) recorded_files = set() for package in primary.values(): recorded_files.add((package['location'], float(package['file_time']))) existing_files = set() expr = r'^.*\.rpm$' for file_path in storage.files('.'): match = re.match(expr, file_path) if not match: continue mtime = storage.mtime(file_path) existing_files.add((file_path, mtime)) files_to_add = existing_files - recorded_files for file_to_add in files_to_add: file_path = file_to_add[0] mtime = file_to_add[1] print("Adding: '%s'" % file_path) tmpdir = tempfile.mkdtemp() storage.download_file(file_path, os.path.join(tmpdir, 'package.rpm')) rpminfo = rpmfile.RpmInfo() header = rpminfo.parse_file(os.path.join(tmpdir, 'package.rpm')) sha256 = file_checksum(os.path.join(tmpdir, 'package.rpm'), "sha256") statinfo = os.stat(os.path.join(tmpdir, 'package.rpm')) size = statinfo.st_size shutil.rmtree(tmpdir) nerv, prim = header_to_primary(header, sha256, mtime, file_path, rpminfo.header_start, rpminfo.header_end, size) _, flist = header_to_filelists(header, sha256) primary[nerv] = prim filelists[nerv] = flist revision = str(int(revision) + 1) filelists_str = dump_filelists(filelists) primary_str = dump_primary(primary) repomd_str = generate_repomd(filelists_str, primary_str, revision) filelists_gz = gzip_string(filelists_str) primary_gz = gzip_string(primary_str) filelists_gz_sha256 = string_checksum(filelists_gz, 'sha256') primary_gz_sha256 = string_checksum(primary_gz, 'sha256') filelists_name = 'repodata/%s-filelists.xml.gz' % filelists_gz_sha256 primary_name = 'repodata/%s-primary.xml.gz' % primary_gz_sha256 storage.write_file(filelists_name, filelists_gz) storage.write_file(primary_name, primary_gz) storage.write_file('repodata/repomd.xml', repomd_str) if sign: repomd_str_signed = gpg_sign_string(repomd_str) storage.write_file('repodata/repomd.xml.asc', repomd_str_signed)