Skip to content

Commit 9cd5b44

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Support optional/configurable IAMEndpoint for Minio Client (go-gitea#32581) (go-gitea#32581) Update the list of watchers and stargazers when clicking watch/unwatch or star/unstar (go-gitea#32570) Apply to became a maintainer (go-gitea#32614)
2 parents 5fdcb5d + 713364f commit 9cd5b44

File tree

9 files changed

+61
-15
lines changed

9 files changed

+61
-15
lines changed

MAINTAINERS

+1
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ Tim-Niclas Oelschläger <[email protected]> (@zokkis)
6363
Yu Liu <[email protected]> (@HEREYUA)
6464
Kemal Zebari <[email protected]> (@kemzeb)
6565
Rowan Bohde <[email protected]> (@bohde)
66+
hiifong <[email protected]> (@hiifong)

custom/conf/app.example.ini

+14
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,13 @@ LEVEL = Info
19441944
;; Minio secretAccessKey to connect only available when STORAGE_TYPE is `minio`
19451945
;MINIO_SECRET_ACCESS_KEY =
19461946
;;
1947+
;; Preferred IAM Endpoint to override Minio's default IAM Endpoint resolution only available when STORAGE_TYPE is `minio`.
1948+
;; If not provided and STORAGE_TYPE is `minio`, will search for and derive endpoint from known environment variables
1949+
;; (AWS_CONTAINER_AUTHORIZATION_TOKEN, AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE, AWS_CONTAINER_CREDENTIALS_RELATIVE_URI,
1950+
;; AWS_CONTAINER_CREDENTIALS_FULL_URI, AWS_WEB_IDENTITY_TOKEN_FILE, AWS_ROLE_ARN, AWS_ROLE_SESSION_NAME, AWS_REGION),
1951+
;; or the DefaultIAMRoleEndpoint if not provided otherwise.
1952+
;MINIO_IAM_ENDPOINT =
1953+
;;
19471954
;; Minio bucket to store the attachments only available when STORAGE_TYPE is `minio`
19481955
;MINIO_BUCKET = gitea
19491956
;;
@@ -2688,6 +2695,13 @@ LEVEL = Info
26882695
;; Minio secretAccessKey to connect only available when STORAGE_TYPE is `minio`
26892696
;MINIO_SECRET_ACCESS_KEY =
26902697
;;
2698+
;; Preferred IAM Endpoint to override Minio's default IAM Endpoint resolution only available when STORAGE_TYPE is `minio`.
2699+
;; If not provided and STORAGE_TYPE is `minio`, will search for and derive endpoint from known environment variables
2700+
;; (AWS_CONTAINER_AUTHORIZATION_TOKEN, AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE, AWS_CONTAINER_CREDENTIALS_RELATIVE_URI,
2701+
;; AWS_CONTAINER_CREDENTIALS_FULL_URI, AWS_WEB_IDENTITY_TOKEN_FILE, AWS_ROLE_ARN, AWS_ROLE_SESSION_NAME, AWS_REGION),
2702+
;; or the DefaultIAMRoleEndpoint if not provided otherwise.
2703+
;MINIO_IAM_ENDPOINT =
2704+
;;
26912705
;; Minio bucket to store the attachments only available when STORAGE_TYPE is `minio`
26922706
;MINIO_BUCKET = gitea
26932707
;;

modules/setting/storage.go

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type MinioStorageConfig struct {
4343
Endpoint string `ini:"MINIO_ENDPOINT" json:",omitempty"`
4444
AccessKeyID string `ini:"MINIO_ACCESS_KEY_ID" json:",omitempty"`
4545
SecretAccessKey string `ini:"MINIO_SECRET_ACCESS_KEY" json:",omitempty"`
46+
IamEndpoint string `ini:"MINIO_IAM_ENDPOINT" json:",omitempty"`
4647
Bucket string `ini:"MINIO_BUCKET" json:",omitempty"`
4748
Location string `ini:"MINIO_LOCATION" json:",omitempty"`
4849
BasePath string `ini:"MINIO_BASE_PATH" json:",omitempty"`

modules/setting/storage_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,19 @@ MINIO_BASE_PATH = /prefix
470470
cfg, err = NewConfigProviderFromData(`
471471
[storage]
472472
STORAGE_TYPE = minio
473+
MINIO_IAM_ENDPOINT = 127.0.0.1
474+
MINIO_USE_SSL = true
475+
MINIO_BASE_PATH = /prefix
476+
`)
477+
assert.NoError(t, err)
478+
assert.NoError(t, loadRepoArchiveFrom(cfg))
479+
assert.EqualValues(t, "127.0.0.1", RepoArchive.Storage.MinioConfig.IamEndpoint)
480+
assert.EqualValues(t, true, RepoArchive.Storage.MinioConfig.UseSSL)
481+
assert.EqualValues(t, "/prefix/repo-archive/", RepoArchive.Storage.MinioConfig.BasePath)
482+
483+
cfg, err = NewConfigProviderFromData(`
484+
[storage]
485+
STORAGE_TYPE = minio
473486
MINIO_ACCESS_KEY_ID = my_access_key
474487
MINIO_SECRET_ACCESS_KEY = my_secret_key
475488
MINIO_USE_SSL = true

modules/storage/minio.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func NewMinioStorage(ctx context.Context, cfg *setting.Storage) (ObjectStorage,
9797
}
9898

9999
minioClient, err := minio.New(config.Endpoint, &minio.Options{
100-
Creds: buildMinioCredentials(config, credentials.DefaultIAMRoleEndpoint),
100+
Creds: buildMinioCredentials(config),
101101
Secure: config.UseSSL,
102102
Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: config.InsecureSkipVerify}},
103103
Region: config.Location,
@@ -164,7 +164,7 @@ func (m *MinioStorage) buildMinioDirPrefix(p string) string {
164164
return p
165165
}
166166

167-
func buildMinioCredentials(config setting.MinioStorageConfig, iamEndpoint string) *credentials.Credentials {
167+
func buildMinioCredentials(config setting.MinioStorageConfig) *credentials.Credentials {
168168
// If static credentials are provided, use those
169169
if config.AccessKeyID != "" {
170170
return credentials.NewStaticV4(config.AccessKeyID, config.SecretAccessKey, "")
@@ -184,7 +184,9 @@ func buildMinioCredentials(config setting.MinioStorageConfig, iamEndpoint string
184184
&credentials.FileAWSCredentials{},
185185
// read IAM role from EC2 metadata endpoint if available
186186
&credentials.IAM{
187-
Endpoint: iamEndpoint,
187+
// passing in an empty Endpoint lets the IAM Provider
188+
// decide which endpoint to resolve internally
189+
Endpoint: config.IamEndpoint,
188190
Client: &http.Client{
189191
Transport: http.DefaultTransport,
190192
},

modules/storage/minio_test.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ func TestMinioCredentials(t *testing.T) {
107107
cfg := setting.MinioStorageConfig{
108108
AccessKeyID: ExpectedAccessKey,
109109
SecretAccessKey: ExpectedSecretAccessKey,
110+
IamEndpoint: FakeEndpoint,
110111
}
111-
creds := buildMinioCredentials(cfg, FakeEndpoint)
112+
creds := buildMinioCredentials(cfg)
112113
v, err := creds.Get()
113114

114115
assert.NoError(t, err)
@@ -117,13 +118,15 @@ func TestMinioCredentials(t *testing.T) {
117118
})
118119

119120
t.Run("Chain", func(t *testing.T) {
120-
cfg := setting.MinioStorageConfig{}
121+
cfg := setting.MinioStorageConfig{
122+
IamEndpoint: FakeEndpoint,
123+
}
121124

122125
t.Run("EnvMinio", func(t *testing.T) {
123126
t.Setenv("MINIO_ACCESS_KEY", ExpectedAccessKey+"Minio")
124127
t.Setenv("MINIO_SECRET_KEY", ExpectedSecretAccessKey+"Minio")
125128

126-
creds := buildMinioCredentials(cfg, FakeEndpoint)
129+
creds := buildMinioCredentials(cfg)
127130
v, err := creds.Get()
128131

129132
assert.NoError(t, err)
@@ -135,7 +138,7 @@ func TestMinioCredentials(t *testing.T) {
135138
t.Setenv("AWS_ACCESS_KEY", ExpectedAccessKey+"AWS")
136139
t.Setenv("AWS_SECRET_KEY", ExpectedSecretAccessKey+"AWS")
137140

138-
creds := buildMinioCredentials(cfg, FakeEndpoint)
141+
creds := buildMinioCredentials(cfg)
139142
v, err := creds.Get()
140143

141144
assert.NoError(t, err)
@@ -144,11 +147,11 @@ func TestMinioCredentials(t *testing.T) {
144147
})
145148

146149
t.Run("FileMinio", func(t *testing.T) {
147-
t.Setenv("MINIO_SHARED_CREDENTIALS_FILE", "testdata/minio.json")
148150
// prevent loading any actual credentials files from the user
151+
t.Setenv("MINIO_SHARED_CREDENTIALS_FILE", "testdata/minio.json")
149152
t.Setenv("AWS_SHARED_CREDENTIALS_FILE", "testdata/fake")
150153

151-
creds := buildMinioCredentials(cfg, FakeEndpoint)
154+
creds := buildMinioCredentials(cfg)
152155
v, err := creds.Get()
153156

154157
assert.NoError(t, err)
@@ -161,7 +164,7 @@ func TestMinioCredentials(t *testing.T) {
161164
t.Setenv("MINIO_SHARED_CREDENTIALS_FILE", "testdata/fake.json")
162165
t.Setenv("AWS_SHARED_CREDENTIALS_FILE", "testdata/aws_credentials")
163166

164-
creds := buildMinioCredentials(cfg, FakeEndpoint)
167+
creds := buildMinioCredentials(cfg)
165168
v, err := creds.Get()
166169

167170
assert.NoError(t, err)
@@ -187,7 +190,9 @@ func TestMinioCredentials(t *testing.T) {
187190
defer server.Close()
188191

189192
// Use the provided EC2 Instance Metadata server
190-
creds := buildMinioCredentials(cfg, server.URL)
193+
creds := buildMinioCredentials(setting.MinioStorageConfig{
194+
IamEndpoint: server.URL,
195+
})
191196
v, err := creds.Get()
192197

193198
assert.NoError(t, err)

routers/web/repo/repo.go

+3
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ func Action(ctx *context.Context) {
352352
ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID)
353353
}
354354

355+
// see the `hx-trigger="refreshUserCards ..."` comments in tmpl
356+
ctx.RespHeader().Add("hx-trigger", "refreshUserCards")
357+
355358
switch ctx.PathParam(":action") {
356359
case "watch", "unwatch", "star", "unstar":
357360
// we have to reload the repository because NumStars or NumWatching (used in the templates) has just changed

routers/web/repo/view.go

-3
Original file line numberDiff line numberDiff line change
@@ -1123,8 +1123,6 @@ func RenderUserCards(ctx *context.Context, total int, getter func(opts db.ListOp
11231123
func Watchers(ctx *context.Context) {
11241124
ctx.Data["Title"] = ctx.Tr("repo.watchers")
11251125
ctx.Data["CardsTitle"] = ctx.Tr("repo.watchers")
1126-
ctx.Data["PageIsWatchers"] = true
1127-
11281126
RenderUserCards(ctx, ctx.Repo.Repository.NumWatches, func(opts db.ListOptions) ([]*user_model.User, error) {
11291127
return repo_model.GetRepoWatchers(ctx, ctx.Repo.Repository.ID, opts)
11301128
}, tplWatchers)
@@ -1134,7 +1132,6 @@ func Watchers(ctx *context.Context) {
11341132
func Stars(ctx *context.Context) {
11351133
ctx.Data["Title"] = ctx.Tr("repo.stargazers")
11361134
ctx.Data["CardsTitle"] = ctx.Tr("repo.stargazers")
1137-
ctx.Data["PageIsStargazers"] = true
11381135
RenderUserCards(ctx, ctx.Repo.Repository.NumStars, func(opts db.ListOptions) ([]*user_model.User, error) {
11391136
return repo_model.GetStargazers(ctx, ctx.Repo.Repository, opts)
11401137
}, tplWatchers)

templates/repo/user_cards.tmpl

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
<div class="user-cards">
1+
<!-- Refresh the content if a htmx response contains "HX-Trigger" header.
2+
This usually happens when a user stays on the watchers/stargazers page
3+
when they watched/unwatched/starred/unstarred and the list should be refreshed.
4+
To test go to the watchers page and click the watch button. The user cards should reload.
5+
At the moment, no JS initialization would re-trigger (fortunately there is no JS for this page).
6+
-->
7+
<div class="no-loading-indicator tw-hidden"></div>
8+
<div class="user-cards"
9+
hx-trigger="refreshUserCards from:body" hx-indicator=".no-loading-indicator"
10+
hx-get="{{$.CurrentURL}}" hx-swap="outerHTML" hx-select=".user-cards"
11+
>
212
{{if .CardsTitle}}
313
<h2 class="ui dividing header">
414
{{.CardsTitle}}

0 commit comments

Comments
 (0)