Skip to content

Commit

Permalink
Combine GITEA_PUBLIC_URL + GITEA_API_URL -> GITEA_ROOT_URL
Browse files Browse the repository at this point in the history
This is easier to get right, since it mirrors Gitea's app.ini.

Also rename GITEA_API_SECRET -> GITEA_TOKEN to use Gitea's nomenclature.

Gitea also has a STATIC_URL_PREFIX which is similar to what GITEA_PUBLIC_URL
was; but we have little motivation to use it, since we are designing
that bids-hook runs _on the same server_ as gitea. Also, if we did keep
it, I would want to more closely mirror app.ini's config behaviour.
  • Loading branch information
kousu committed Feb 24, 2023
1 parent 9c422b7 commit 8688742
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
42 changes: 14 additions & 28 deletions bids-hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,15 @@ var (
// this should be entered as-in in Gitea to configure the webhook
bidsHookSecret []byte

// the base URL to reach Gitea's API
// read from environment variable GITEA_API_URL
// should end with "/api/v1"
giteaApiUrl *url.URL
// the base URL to reach Gitea
// read from environment variable GITEA_ROOT_URL
// should match Gitea's app.ini's [server].ROOT_URL
giteaRootUrl *url.URL

// secret used to authenticate api calls from bids-hook to Gitea
// read from environment variable GITEA_API_SECRET
// read from environment variable GITEA_TOKEN
// can be generated from a gitea admin account under "Settings" -> "Applications"
giteaApiSecret []byte

// the base URL for writing links to Gitea's static assets
// read from environment variable GITEA_PUBLIC_URL
// should end with "/assets"
giteaPublicUrl *url.URL
giteaToken []byte

// the path to Gitea's static assets directory
// read from environment variable GITEA_PUBLIC_PATH
Expand Down Expand Up @@ -341,7 +336,7 @@ func (j job) postStatus(ctx context.Context, state string) error {
if err != nil {
return err
}
req.Header.Add("Authorization", fmt.Sprintf("token %s", giteaApiSecret))
req.Header.Add("Authorization", fmt.Sprintf("token %s", giteaToken))
req.Header.Add("Content-Type", "application/json")

resp, err := http.DefaultClient.Do(req)
Expand Down Expand Up @@ -451,29 +446,20 @@ func readConfig() {
}
bidsHookSecret = []byte(val)

val, ok = os.LookupEnv("GITEA_API_URL")
val, ok = os.LookupEnv("GITEA_ROOT_URL")
if !ok {
log.Fatal("missing environment variable GITEA_API_URL")
log.Fatal("missing environment variable GITEA_ROOT_URL")
}
giteaApiUrl, err = url.Parse(val)
giteaRootUrl, err = url.Parse(val)
if err != nil {
log.Fatalf("error parsing GITEA_API_URL: %v", err)
}

val, ok = os.LookupEnv("GITEA_API_SECRET")
if !ok {
log.Fatal("missing environment variable GITEA_API_SECRET")
log.Fatalf("error parsing GITEA_ROOT_URL: %v", err)
}
giteaApiSecret = []byte(val)

val, ok = os.LookupEnv("GITEA_PUBLIC_URL")
val, ok = os.LookupEnv("GITEA_TOKEN")
if !ok {
log.Fatal("missing environment variable GITEA_PUBLIC_URL")
}
giteaPublicUrl, err = url.Parse(val)
if err != nil {
log.Fatalf("error parsing GITEA_PUBLIC_URL: %v", err)
log.Fatal("missing environment variable GITEA_TOKEN")
}
giteaToken = []byte(val)

val, ok = os.LookupEnv("GITEA_PUBLIC_PATH")
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions start
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
export BIDS_HOOK_URL='http://127.0.0.1:2845/bids-hook'
export BIDS_HOOK_SECRET='blabla'

export GITEA_API_URL='http://127.0.0.1:3000/api/v1'
export GITEA_API_SECRET='69e45fa9cfa75a7497633c6be8dd2347226e2f62'
export GITEA_ROOT_URL='http://127.0.0.1:3000'
export GITEA_TOKEN='69e45fa9cfa75a7497633c6be8dd2347226e2f62'

export GITEA_PUBLIC_URL='http://127.0.0.1:3000/assets'
export GITEA_PUBLIC_PATH='./custom/public'
Expand Down

0 comments on commit 8688742

Please sign in to comment.