-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ghe config option #559
Changes from 3 commits
dfa3acf
cfb608c
485f3a8
5e1eea0
5a66367
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ cmd/allstar/allstar | |
*.pem | ||
.vscode | ||
allstar.ref | ||
.idea/ | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,12 +55,27 @@ conditions on enforcement actions, ex: pinging an issue twice at the same time. | |
## Configuration via Environment Variables | ||
|
||
Allstar supports various operator configuration options which can be set via environment variables: | ||
|Name|Description|Default| | ||
|----|----|----| | ||
|APP_ID|The application ID of the created GitHub App.|| | ||
|PRIVATE_KEY|The raw value of the private key for the GitHub App. KEY_SECRET must be set to "direct".|| | ||
|KEY_SECRET|The name of a secret containing a private key.|| | ||
|DO_NOTHING_ON_OPT_OUT|Boolean flag which defines if allstar should do nothing and skip the corresponding checks when a repository is opted out.|false| | ||
|ALLSTAR_LOG_LEVEL|The minimum logging level that allstar should use when emitting logs. Acceptable values are: panic ; fatal ; error ; warn ; info ; debug ; trace|info| | ||
|NOTICE_PING_DURATION_HOURS|The duration (in hours) to wait between pinging notice actions, such as updating a GitHub issue.|24| | ||
|
||
| Name | Description | Default | | ||
|----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|---------| | ||
| APP_ID | The application ID of the created GitHub App. || | ||
| PRIVATE_KEY | The raw value of the private key for the GitHub App. KEY_SECRET must be set to "direct". || | ||
| KEY_SECRET | The name of a secret containing a private key. || | ||
| ALLSTAR_GHE_URL | The URL of the GitHub Enterprise instance to use. Leave empty to use github.com || | ||
| DO_NOTHING_ON_OPT_OUT | Boolean flag which defines if allstar should do nothing and skip the corresponding checks when a repository is opted out. | false | | ||
| ALLSTAR_LOG_LEVEL | The minimum logging level that allstar should use when emitting logs. Acceptable values are: panic ; fatal ; error ; warn ; info ; debug ; trace | info | | ||
| NOTICE_PING_DURATION_HOURS | The duration (in hours) to wait between pinging notice actions, such as updating a GitHub issue. | 24 | | ||
|
||
## Self-hosted GitHub Enterprise specifics | ||
|
||
In case you want to operate Allstar with a self-hosted GitHub Enterprise instance, you need to set the `ALLSTAR_GHE_URL` environment variable to the URL of your GitHub Enterprise instance URL. | ||
The different API endpoints for API and upload are appended automatically. | ||
|
||
Example: | ||
|
||
Given, your GHE instance URL is "https://my-ghe.example.com", you need to set the following environment variables: | ||
|
||
```shell | ||
export ALLSTAR_GHE_URL="https://my-ghe.example.com" | ||
export GH_HOST="my-ghe.example.com" # This is somehow used within a dependency and (as of now) is unclear how to set it programmatically. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, it is fine to just mention it in the docs. Thanks for the explanation 👍 |
||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ package ghclients | |
import ( | ||
"context" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/bradleyfalzon/ghinstallation/v2" | ||
"github.com/google/go-github/v59/github" | ||
|
@@ -92,19 +93,45 @@ func (g *GHClients) Get(i int64) (*github.Client, error) { | |
} | ||
|
||
var tr http.RoundTripper | ||
var err error | ||
if i == 0 { | ||
tr, err = ghinstallationNewAppsTransport(ctr, operator.AppID, g.key) | ||
appTransport, _ := ghinstallationNewAppsTransport(ctr, operator.AppID, g.key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check error |
||
// other than clien.WithEnterpriseUrls, setting the BaseUrl plainly, we need to ensure the /api/v3 ending | ||
appTransport.BaseURL = fullEnterpriseApiUrl(operator.GitHubEnterpriseUrl) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap in |
||
tr = appTransport | ||
} else { | ||
tr, err = ghinstallationNew(ctr, operator.AppID, i, g.key) | ||
ghiTransport, _ := ghinstallationNew(ctr, operator.AppID, i, g.key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check error |
||
if operator.GitHubEnterpriseUrl != "" { | ||
ghiTransport.BaseURL = fullEnterpriseApiUrl(operator.GitHubEnterpriseUrl) | ||
} | ||
tr = ghiTransport | ||
|
||
} | ||
if err != nil { | ||
return nil, err | ||
|
||
c := github.NewClient(&http.Client{Transport: tr}) | ||
if operator.GitHubEnterpriseUrl != "" { | ||
newC, err := c.WithEnterpriseURLs(operator.GitHubEnterpriseUrl, operator.GitHubEnterpriseUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
c = newC | ||
} | ||
g.clients[i] = github.NewClient(&http.Client{Transport: tr}) | ||
|
||
g.clients[i] = c | ||
return g.clients[i], nil | ||
} | ||
|
||
// fullEnterpriseApiUrl ensures the base url is in the correct format for GitHub Enterprise usage | ||
func fullEnterpriseApiUrl(baseUrl string) string { | ||
if !strings.HasSuffix(baseUrl, "/") { | ||
baseUrl += "/" | ||
} | ||
if !strings.HasSuffix(baseUrl, "api/v3/") { | ||
baseUrl += "api/v3/" | ||
} | ||
|
||
return baseUrl | ||
} | ||
|
||
func getKeyFromSecretReal(ctx context.Context, keySecretVal string) ([]byte, error) { | ||
v, err := runtimevar.OpenVariable(ctx, keySecretVal) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline at end of file