Skip to content

Commit de8f32b

Browse files
authored
Merge pull request #648 from pjbgf/gitlab-fix
2 parents 9b1140c + da91e47 commit de8f32b

File tree

4 files changed

+70
-8
lines changed

4 files changed

+70
-8
lines changed

DEVELOPMENT.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,31 @@ Deploy `source-controller` into the cluster that is configured in the local kube
128128
```sh
129129
make deploy
130130
```
131+
132+
### Debugging controller with VSCode
133+
134+
Create a `.vscode/launch.json` file:
135+
```json
136+
{
137+
"version": "0.2.0",
138+
"configurations": [
139+
{
140+
"name": "Launch Package",
141+
"type": "go",
142+
"request": "launch",
143+
"mode": "auto",
144+
"envFile": "${workspaceFolder}/build/.env",
145+
"program": "${workspaceFolder}/main.go"
146+
}
147+
]
148+
}
149+
```
150+
151+
Create the environment file containing details on how to load
152+
`libgit2` dependencies:
153+
```bash
154+
make env
155+
```
156+
157+
Start debugging by either clicking `Run` > `Start Debugging` or using
158+
the relevant shortcut.

Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,30 @@ endef
241241

242242
# Build fuzzers
243243
fuzz-build: $(LIBGIT2)
244-
rm -rf $(shell pwd)/build/fuzz/
245-
mkdir -p $(shell pwd)/build/fuzz/out/
244+
rm -rf $(BUILD_DIR)/fuzz/
245+
mkdir -p $(BUILD_DIR)/fuzz/out/
246246

247247
docker build . --tag local-fuzzing:latest -f tests/fuzz/Dockerfile.builder
248248
docker run --rm \
249249
-e FUZZING_LANGUAGE=go -e SANITIZER=address \
250250
-e CIFUZZ_DEBUG='True' -e OSS_FUZZ_PROJECT_NAME=fluxcd \
251-
-v "$(shell pwd)/build/fuzz/out":/out \
251+
-v "$(BUILD_DIR)/fuzz/out":/out \
252252
local-fuzzing:latest
253253

254254
fuzz-smoketest: fuzz-build
255255
docker run --rm \
256-
-v "$(shell pwd)/build/fuzz/out":/out \
256+
-v "$(BUILD_DIR)/fuzz/out":/out \
257257
-v "$(shell pwd)/tests/fuzz/oss_fuzz_run.sh":/runner.sh \
258258
local-fuzzing:latest \
259259
bash -c "/runner.sh"
260+
261+
# Creates an env file that can be used to load all source-controller's dependencies
262+
# this is handy when you want to run adhoc debug sessions on tests or start the
263+
# controller in a new debug session.
264+
env: $(LIBGIT2)
265+
echo 'GO_ENABLED="1"' > $(BUILD_DIR)/.env
266+
echo 'PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)"' >> $(BUILD_DIR)/.env
267+
echo 'LIBRARY_PATH="$(LIBRARY_PATH)"' >> $(BUILD_DIR)/.env
268+
echo 'CGO_CFLAGS="$(CGO_CFLAGS)"' >> $(BUILD_DIR)/.env
269+
echo 'CGO_LDFLAGS="$(CGO_LDFLAGS)"' >> $(BUILD_DIR)/.env
270+
echo 'KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS)' >> $(BUILD_DIR)/.env

pkg/git/gogit/transport.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ func transportAuth(opts *git.AuthOptions) (transport.AuthMethod, error) {
3636
}
3737
switch opts.Transport {
3838
case git.HTTPS, git.HTTP:
39-
return &http.BasicAuth{
40-
Username: opts.Username,
41-
Password: opts.Password,
42-
}, nil
39+
// Some providers (i.e. GitLab) will reject empty credentials for
40+
// public repositories.
41+
if opts.Username != "" || opts.Password != "" {
42+
return &http.BasicAuth{
43+
Username: opts.Username,
44+
Password: opts.Password,
45+
}, nil
46+
}
47+
return nil, nil
4348
case git.SSH:
4449
if len(opts.Identity) > 0 {
4550
pk, err := ssh.NewPublicKeys(opts.Username, opts.Identity, opts.Password)

pkg/git/gogit/transport_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ func Test_transportAuth(t *testing.T) {
7474
wantFunc func(g *WithT, t transport.AuthMethod, opts *git.AuthOptions)
7575
wantErr error
7676
}{
77+
{
78+
name: "Public HTTP Repositories",
79+
opts: &git.AuthOptions{
80+
Transport: git.HTTP,
81+
},
82+
wantFunc: func(g *WithT, t transport.AuthMethod, opts *git.AuthOptions) {
83+
g.Expect(t).To(BeNil())
84+
},
85+
},
86+
{
87+
name: "Public HTTPS Repositories",
88+
opts: &git.AuthOptions{
89+
Transport: git.HTTP,
90+
},
91+
wantFunc: func(g *WithT, t transport.AuthMethod, opts *git.AuthOptions) {
92+
g.Expect(t).To(BeNil())
93+
},
94+
},
7795
{
7896
name: "HTTP basic auth",
7997
opts: &git.AuthOptions{

0 commit comments

Comments
 (0)