コード例 #1
0
ファイル: git2r_cred.c プロジェクト: krlmlr/git2r
/**
 * Create credential object from S4 class 'cred_env'.
 *
 * @param cred The newly created credential object.
 * @param allowed_types A bitmask stating which cred types are OK to return.
 * @param credentials The S4 class object with credentials.
 * @return 0 on success, else -1.
 */
static int git2r_cred_env(
    git_cred **cred,
    unsigned int allowed_types,
    SEXP credentials)
{
    if (GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) {
        int err;
        git_buf username = GIT_BUF_INIT;
        git_buf password = GIT_BUF_INIT;

        /* Read value of the username environment variable */
        err = git__getenv(&username,
                          CHAR(STRING_ELT(
                                   GET_SLOT(credentials,
                                            Rf_install("username")), 0)));
        if (err)
            goto cleanup;

        if (!git_buf_len(&username)) {
            err = -1;
            goto cleanup;
        }

        /* Read value of the password environment variable */
        err = git__getenv(&password,
                          CHAR(STRING_ELT(
                                   GET_SLOT(credentials,
                                            Rf_install("password")), 0)));
        if (err)
            goto cleanup;

        if (!git_buf_len(&password)) {
            err = -1;
            goto cleanup;
        }

        err = git_cred_userpass_plaintext_new(
            cred,
            git_buf_cstr(&username),
            git_buf_cstr(&password));

    cleanup:
        git_buf_free(&username);
        git_buf_free(&password);

        if (err)
            return -1;

        return 0;
    }

    return -1;
}
コード例 #2
0
ファイル: git2r_cred.c プロジェクト: krlmlr/git2r
/**
 * Create credential object from S4 class 'cred_token'.
 *
 * @param cred The newly created credential object.
 * @param allowed_types A bitmask stating which cred types are OK to return.
 * @param credentials The S4 class object with credentials.
 * @return 0 on success, else -1.
 */
static int git2r_cred_token(
    git_cred **cred,
    unsigned int allowed_types,
    SEXP credentials)
{
    if (GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) {
        int err;
        git_buf token = GIT_BUF_INIT;

        /* Read value of the personal access token from the
         * environment variable */
        err = git__getenv(&token,
                          CHAR(STRING_ELT(GET_SLOT(credentials,
                                                   Rf_install("token")), 0)));
        if (err)
            goto cleanup;

        err = git_cred_userpass_plaintext_new(cred, " ", git_buf_cstr(&token));

    cleanup:
        git_buf_free(&token);

        if (err)
            return -1;

        return 0;
    }

    return -1;
}
コード例 #3
0
ファイル: clar_libgit2.c プロジェクト: Angeldude/sonic-pi
char *cl_getenv(const char *name)
{
	git_buf out = GIT_BUF_INIT;
	int error = git__getenv(&out, name);

	cl_assert(error >= 0 || error == GIT_ENOTFOUND);

	if (error == GIT_ENOTFOUND)
		return NULL;

	if (out.size == 0) {
		char *dup = git__strdup("");
		cl_assert(dup);

		return dup;
	}

	return git_buf_detach(&out);
}