Add auth to Git.#Repository

Signed-off-by: Guillaume de Rouville <guillaume.derouville@gmail.com>
This commit is contained in:
Guillaume de Rouville
2021-08-26 16:12:14 +02:00
parent 3b0e3f6919
commit 08f395b70d
9 changed files with 55 additions and 43 deletions

View File

@@ -11,18 +11,24 @@ import (
#Repository: {
// Git remote.
// Example: `"https://github.com/dagger/dagger"`
remote: string & dagger.#Input
remote: dagger.#Input & {string}
// Git ref: can be a commit, tag or branch.
// Example: "main"
ref: string & dagger.#Input
ref: dagger.#Input & {string}
// (optional) Subdirectory
subdir: *null | string & dagger.#Input
subdir: dagger.#Input & {*null | string}
// (optional) Keep .git directory
keepGitDir: *false | bool
// (optional) Add Personal Access Token
authToken: dagger.#Input & {*null | dagger.#Secret}
// (optional) Add OAuth Token
authHeader: dagger.#Input & {*null | dagger.#Secret}
#up: [
op.#FetchGit & {
"remote": remote
@@ -30,6 +36,12 @@ import (
if (keepGitDir) {
keepGitDir: true
}
if (authToken != null) {
"authToken": authToken
}
if (authHeader != null) {
"authHeader": authHeader
}
},
if subdir != null {
op.#Subdir & {

View File

@@ -3,8 +3,9 @@ package git
import (
"strings"
"alpha.dagger.io/git"
"alpha.dagger.io/alpine"
"alpha.dagger.io/dagger"
"alpha.dagger.io/git"
"alpha.dagger.io/os"
)
@@ -74,3 +75,25 @@ TestCurrentTags: os.#Container & {
[ $TAGS = "0=master" ]
"""
}
// Test fetching a private repo
TestPAT: dagger.#Input & {dagger.#Secret}
privateRepo: git.#Repository & {
remote: "https://github.com/dagger/dagger.git"
ref: "main"
keepGitDir: true
authToken: TestPAT
}
TestPrivateRepository: os.#Container & {
image: alpine.#Image & {
package: bash: "=5.1.0-r0"
package: git: true
}
mount: "/repo1": from: privateRepo
dir: "/repo1"
command: """
[ -d .git ]
"""
}