Export contents of a Secretfile from the Vault server
    into a specified directory.
484918
def export(vault_client, opt):
    """"""
    ctx = Context.load(get_secretfile(opt), opt) \
                 .fetch(vault_client)
    for resource in ctx.resources():
        resource.export(opt.directory)
1116518
def export(self, out_filename):
        
        with zipfile.ZipFile(out_filename, 'w', zipfile.ZIP_DEFLATED) as arc:
            id_list = list(self.get_thread_info())
            for num, my_info in enumerate(id_list):
                logging.info('Working on item %i : %s', num, my_info['number'])
                my_thread = GitHubCommentThread(
                    self.gh_info.owner, self.gh_info.realm, my_info['title'],
                    self.gh_info.user, self.gh_info.token,
                    thread_id=my_info['number'])
                csec = my_thread.get_comment_section()
                cdict = [item.to_dict() for item in csec.comments]
                my_json = json.dumps(cdict)
                arc.writestr('%i__%s' % (my_info['number'], my_info['title']),
                             my_json)
1132504
def exportCertificate(self, certificate, folder):
        """"""
        url = self._url + "/sslcertificates/%s/export" % certificate
        params = {
            "f" : "json",
        }
        return self._get(url=url,
                         param_dict=params,
                        out_folder=folder)
1099203
def thaw(vault_client, src_file, opt):
    """"""
    if not os.path.exists(src_file):
        raise aomi.exceptions.AomiFile("%s does not exist" % src_file)

    tmp_dir = ensure_tmpdir()
    zip_file = thaw_decrypt(vault_client, src_file, tmp_dir, opt)
    archive = zipfile.ZipFile(zip_file, 'r')
    for archive_file in archive.namelist():
        archive.extract(archive_file, tmp_dir)
        os.chmod("%s/%s" % (tmp_dir, archive_file), 0o640)
        LOG.debug("Extracted %s from archive", archive_file)

    LOG.info("Thawing secrets into %s", opt.secrets)
    config = get_secretfile(opt)
    Context.load(config, opt) \
           .thaw(tmp_dir)
1007107
def dump(self, directory):
    """"""
    payload = '{}:{}'.format(self.fingerprint, self.serialized_bytes_length)
    safe_file_dump(self._path(directory), payload=payload)
39517
function outputFile(options, conf) {
    const json = JSON.stringify(options),
          sha1 = crypto.createHash('sha1').update(json).digest('hex'),
          format = options.format || DEF_FORMAT;
    return conf.storage + path.sep + sha1 + '.' + format;
}
293337
function copyFile(srcPath, destPath) {
        let srcFileInfo = path.parse(srcPath) || {};
        if (!path.extname(destPath) && srcFileInfo.ext) {
            // destination is a directory!
            return copyFileIntoDirectory(srcPath, destPath);
        } else {
            return new Promise(function (resolve, reject) {
                fs.copy(srcPath, destPath, function (err) {
                    if (!err) {
                        resolve();
                    } else {
                        reject(err);
                    }
                });
            });
        }
    }
404030
def render(directory, opt):
    """"""
    if not os.path.exists(directory) and not os.path.isdir(directory):
        os.mkdir(directory)

    a_secretfile = render_secretfile(opt)
    s_path = "%s/Secretfile" % directory
    LOG.debug("writing Secretfile to %s", s_path)
    open(s_path, 'w').write(a_secretfile)
    ctx = Context.load(yaml.safe_load(a_secretfile), opt)
    for resource in ctx.resources():
        if not resource.present:
            continue

        if issubclass(type(resource), Policy):
            if not os.path.isdir("%s/policy" % directory):
                os.mkdir("%s/policy" % directory)

            filename = "%s/policy/%s" % (directory, resource.path)
            open(filename, 'w').write(resource.obj())
            LOG.debug("writing %s to %s", resource, filename)
        elif issubclass(type(resource), AWSRole):
            if not os.path.isdir("%s/aws" % directory):
                os.mkdir("%s/aws" % directory)

            if 'policy' in resource.obj():
                filename = "%s/aws/%s" % (directory,
                                          os.path.basename(resource.path))
                r_obj = resource.obj()
                if 'policy' in r_obj:
                    LOG.debug("writing %s to %s", resource, filename)
                    open(filename, 'w').write(r_obj['policy'])
792571
def extract_file_args(subparsers):
    """"""
    extract_parser = subparsers.add_parser('extract_file',
                                           help='Extract a single secret from'
                                           'Vault to a local file')
    extract_parser.add_argument('vault_path',
                                help='Full path (including key) to secret')
    extract_parser.add_argument('destination',
                                help='Location of destination file')
    base_args(extract_parser)
525736
function copyFileIntoDirectory(srcPath, destPath) {
        return ensureDestinationDirectory(destPath).then(function () {
            return new Promise(function (resolve, reject) {
                fs.readFile(srcPath, 'utf8', function (err, contents) {
                    if (!err) {
                        resolve();
                    } else {
                        reject(err);
                    }
                    fs.outputFile(destPath + '/' + path.basename(srcPath), contents, function (err) {
                        if (!err) {
                            resolve();
                        } else {
                            reject(err);
                        }
                    });
                });
            });
        });
    }
260758
def export_handle(self, directory):
        """"""
        filename = getattr(self, 'filename')
        dest_file = "%s/%s" % (directory, filename)
        dest_dir = os.path.dirname(dest_file)
        if not os.path.isdir(dest_dir):
            os.mkdir(dest_dir, 0o700)

        return open(dest_file, 'w')
1104862
def _extract(self, path, outdir, filter_func=None):
    """"""
    with open_zip(path) as archive_file:
      for name in archive_file.namelist():
        # While we're at it, we also perform this safety test.
        if name.startswith('/') or name.startswith('..'):
          raise ValueError('Zip file contains unsafe path: {}'.format(name))
        if (not filter_func or filter_func(name)):
          archive_file.extract(name, outdir)
28575
def copyfile(src, dest, no_progress_bar=False, name=None):
    """"""
    from dvc.progress import progress

    copied = 0
    name = name if name else os.path.basename(dest)
    total = os.stat(src).st_size

    if os.path.isdir(dest):
        dest = os.path.join(dest, os.path.basename(src))

    with open(src, "rb") as fsrc, open(dest, "wb+") as fdest:
        while True:
            buf = fsrc.read(LOCAL_CHUNK_SIZE)
            if not buf:
                break
            fdest.write(buf)
            copied += len(buf)
            if not no_progress_bar:
                progress.update_target(name, copied, total)

    if not no_progress_bar:
        progress.finish_target(name)
705212
def create(vault_id, file, options = {:headers => {"Content-Type"=>"application/octet-stream"}})
      options.merge!(default_options_to_merge_with)
      options[:body] = file.read
      self.class.post("/#{@api_ver}/vaults/#{vault_id}/blobs", options)
    end
694324
def detect_secrets():
    
    # use
    # blah blah = "foo"     # pragma: whitelist secret
    # to ignore a false posites
    errors_file = "detect-secrets-results.txt"

    print(execute_get_text("pwd"))

    command = "{0} detect-secrets --scan --base64-limit 4 --exclude .idea|.js|.min.js|.html|.xsd|" \
              "lock.json|synced_folders|.scss|Pipfile.lock|" \
              "lint.txt|{1}".format(PIPENV, errors_file).strip()
    print(command)
    bash_process = subprocess.Popen(command.split(" "),
                                    #shell=True,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE
                                    )
    foo = bash_process.wait()
    out, err = bash_process.communicate()  # wait


    with open(errors_file, "w+") as file_handle:
        if len(out)==0:
            print("Warning- no output from detect secrets. Happens with git hook, but not from ordinary command line.")
            return
        file_handle.write(out.decode())



    with open(errors_file) as f:
        try:
            data = json.load(f)
        except Exception:
            print("Can't read json")
            exit(-1)
            return

    if data["results"]:
        for result in data["results"]:
            print(result)
        print("detect-secrets has discovered high entropy strings, possibly passwords?")
        exit(-1)
1099801
def export(outfile, pk):
    """"""
    load_dbenv_if_not_loaded(
    )  # Important to load the dbenv in the last moment

    from aiida.orm import load_node
    node = load_node(pk)
    string = str(node)

    if outfile:
        with open(outfile, 'w') as f:
            f.write(string)
    else:
        click.echo(string)
174415
def export_pipeline(conf, args):
    """"""
    # Export the source pipeline and save it to file
    src = conf.config['instances'][args.src_instance]
    src_url = api.build_pipeline_url(build_instance_url(src))
    src_auth = tuple([conf.creds['instances'][args.src_instance]['user'],
                      conf.creds['instances'][args.src_instance]['pass']])
    verify_ssl = src.get('verify_ssl', True)
    export_json = api.export_pipeline(src_url, args.src_pipeline_id, src_auth, verify_ssl)
    with open(args.out, 'w') as outFile:
        outFile.write(json.dumps(export_json, indent=4, sort_keys=False))
        return (0, '')