Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 875e656

Browse files
committed
feat: add insecure flag to force http on the domain
1 parent b32ae76 commit 875e656

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

apis/mpas/v1alpha1/repository_types.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ type RepositorySpec struct {
5353
//+optional
5454
//+kubebuilder:validation:Pattern="^\\w+(\\.|:[0-9]).*$"
5555
Domain string `json:"domain,omitempty"`
56+
// Insecure should be defined if `domain` is not HTTPS.
57+
//+optional
58+
Insecure bool `json:"insecure,omitempty"`
5659
//+optional
5760
Maintainers []string `json:"maintainers,omitempty"`
5861
//+optional
@@ -105,7 +108,12 @@ func (in Repository) GetRepositoryURL() string {
105108
return fmt.Sprintf("%s:%s/%s", in.Spec.Domain, in.Spec.Owner, in.GetName())
106109
}
107110

108-
return fmt.Sprintf("https://%s/%s/%s", in.Spec.Domain, in.Spec.Owner, in.GetName())
111+
scheme := "https"
112+
if in.Spec.Insecure {
113+
scheme = "http"
114+
}
115+
116+
return fmt.Sprintf("%s://%s/%s/%s", scheme, in.Spec.Domain, in.Spec.Owner, in.GetName())
109117
}
110118

111119
domain := ""

config/crd/bases/mpas.ocm.software_repositories.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ spec:
8383
- adopt
8484
- fail
8585
type: string
86+
insecure:
87+
description: Insecure should be defined if `domain` is not HTTPS.
88+
type: boolean
8689
interval:
8790
type: string
8891
isOrganization:

pkg/providers/gitea/gitea.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"encoding/base64"
1111
"errors"
1212
"fmt"
13+
"net/url"
1314

1415
"code.gitea.io/sdk/gitea"
1516
deliveryv1alpha1 "github.com/open-component-model/git-controller/apis/delivery/v1alpha1"
@@ -65,11 +66,15 @@ func (c *Client) CreateRepository(ctx context.Context, obj mpasv1alpha1.Reposito
6566
return fmt.Errorf("token '%s' not found in secret", tokenKey)
6667
}
6768

68-
domain := defaultDomain
69-
if obj.Spec.Domain != "" {
70-
domain = obj.Spec.Domain
69+
u, err := url.Parse(obj.GetRepositoryURL())
70+
if err != nil {
71+
return fmt.Errorf("failed to parse repository url: %w", err)
7172
}
7273

74+
// construct the domain including the scheme and host but without the path
75+
// gitea requires a host and a scheme
76+
domain := fmt.Sprintf("%s://%s", u.Scheme, u.Host)
77+
7378
client, err := gitea.NewClient(domain, gitea.SetToken(string(token)))
7479
if err != nil {
7580
return fmt.Errorf("failed to create gitea client: %w", err)

0 commit comments

Comments
 (0)