Skip to content

Commit

Permalink
Use pointers to pass options
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Aug 12, 2020
1 parent 85430b5 commit 88495ec
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
- Download pre-built binary into a server

```console
curl -fsSL -O https://github.com/appscodelabs/offline-license-server/releases/download/v0.0.9/offline-license-server-linux-amd64
curl -fsSL -O https://github.com/appscode/offline-license-server/releases/download/v0.0.3/offline-license-server-linux-amd64
chmod +x offline-license-server-linux-amd64
mv offline-license-server-linux-amd64 /usr/local/bin/offline-license-server
```

- Install systemd service

```console
curl -fsSL -O https://github.com/appscodelabs/offline-license-server/raw/v0.0.9/hack/systemd/offline-license-server.service
curl -fsSL -O https://github.com/appscode/offline-license-server/raw/v0.0.3/hack/systemd/offline-license-server.service
chmod +x offline-license-server.service

# edit offline-license-server.service file to add `--ssl --secret-key=<uuid>`
# 1. Copy Google cloud service account json key to /root/app/gcloud.json
# 2. Edit offline-license-server.service file to
# - set MAILGUN_KEY
# - add `--ssl`

mv offline-license-server.service /lib/systemd/system/offline-license-server.service
```
Expand All @@ -33,4 +36,4 @@ sudo journalctl -f -u offline-license-server

```
curl -d "[email protected]" -X POST http://localhost:4000/register
```
```
4 changes: 2 additions & 2 deletions cmds/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (

func NewRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "gh-ci [command]",
Short: `gh-ci by AppsCode - GitHub CI for private repos`,
Use: "offline-license-server [command]",
Short: `offline-license-server by AppsCode - Offline License server for AppsCode products`,
DisableAutoGenTag: true,
}

Expand Down
9 changes: 5 additions & 4 deletions hack/systemd/offline-license-server.service
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ref: https://fabianlee.org/2017/05/21/golang-running-a-go-binary-as-a-systemd-service-on-ubuntu-16-04/
[Unit]
Description=GitHub CI Webhook Service
Description=AppsCode Offline License Server
After=network.target

[Service]
Expand All @@ -13,9 +13,10 @@ Restart=on-failure
RestartSec=10
startLimitIntervalSec=60

# GitHub Env Vars
Environment=GITHUB_USER=1gtm
Environment=GITHUB_TOKEN=
# Env Vars
Environment=GOOGLE_APPLICATION_CREDENTIALS=/root/app/gcloud.json
Environment=MAILGUN_DOMAIN=mail.appscode.com
Environment=MAILGUN_KEY=

WorkingDirectory=/root
ExecStart=/usr/local/bin/offline-license-server run
Expand Down
6 changes: 3 additions & 3 deletions pkg/server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ type Options struct {
MailReplyTo string
}

func NewOptions() Options {
return Options{
func NewOptions() *Options {
return &Options{
CertDir: "certs",
CertEmail: "[email protected]",
Hosts: []string{"license-issuer.appscode.com"},
Expand All @@ -59,7 +59,7 @@ func NewOptions() Options {
}
}

func (s Options) AddFlags(fs *pflag.FlagSet) {
func (s *Options) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.CertDir, "ssl.cert-dir", s.CertDir, "Directory where certs are stored")
fs.StringVar(&s.CertEmail, "ssl.email", s.CertEmail, "Email used by Let's Encrypt to notify about problems with issued certificates")
fs.StringSliceVar(&s.Hosts, "ssl.hosts", s.Hosts, "Hosts for which certificate will be issued")
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ import (
)

type Server struct {
opts Options
opts *Options

certs *certstore.CertStore
fs *blobfs.BlobFS
mg mailgun.Mailgun
}

func New(opts Options) (*Server, error) {
func New(opts *Options) (*Server, error) {
fs := blobfs.New("gs://" + opts.LicenseBucket)
certs, err := certstore.New(fs, CACertificatesPath(), LicenseIssuerName)
if err != nil {
Expand Down

0 comments on commit 88495ec

Please sign in to comment.