-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgithub_app.go
58 lines (52 loc) · 1.41 KB
/
github_app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package config
import (
"encoding/base64"
"log/slog"
"github.com/m-mizutani/octovy/pkg/domain/types"
"github.com/urfave/cli/v2"
)
type GitHubApp struct {
ID types.GitHubAppID
Secret types.GitHubAppSecret
privateKey types.GitHubAppPrivateKey
}
func (x *GitHubApp) Flags() []cli.Flag {
return []cli.Flag{
&cli.Int64Flag{
Name: "github-app-id",
Usage: "GitHub App ID",
Category: "GitHub App",
Destination: (*int64)(&x.ID),
EnvVars: []string{"OCTOVY_GITHUB_APP_ID"},
Required: true,
},
&cli.StringFlag{
Name: "github-app-private-key",
Usage: "GitHub App Private Key",
Category: "GitHub App",
Destination: (*string)(&x.privateKey),
EnvVars: []string{"OCTOVY_GITHUB_APP_PRIVATE_KEY"},
Required: true,
},
&cli.StringFlag{
Name: "github-app-secret",
Usage: "GitHub App Webhook Secret",
Category: "GitHub App",
Destination: (*string)(&x.Secret),
EnvVars: []string{"OCTOVY_GITHUB_APP_SECRET"},
},
}
}
func (x *GitHubApp) PrivateKey() types.GitHubAppPrivateKey {
if raw, err := base64.StdEncoding.DecodeString(string(x.privateKey)); err == nil {
return types.GitHubAppPrivateKey(raw)
}
return x.privateKey
}
func (x *GitHubApp) LogValue() slog.Value {
return slog.GroupValue(
slog.Any("ID", x.ID),
slog.Any("Secret.len", len(x.Secret)),
slog.Any("PrivateKey.len", len(x.privateKey)),
)
}