Skip to content

Commit

Permalink
config: refactor into multiple files (#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
julesjcraske authored Sep 24, 2024
1 parent c70c4bd commit c4ec4eb
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 295 deletions.
33 changes: 33 additions & 0 deletions lib/config/aws.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package config

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
)

// AWS configures credentials for access to Amazon Web Services.
// It is intended to be used in composition rather than a key.
type AWS struct {
AccessKeyID string `json:"access_key_id"`
AccessKeySecret string `json:"access_key_secret"`

Region string `json:"region,omitempty"`
}

// Credentials returns a configured set of AWS credentials.
func (a AWS) Credentials() *credentials.Credentials {
if a.AccessKeyID != "" && a.AccessKeySecret != "" {
return credentials.NewStaticCredentials(a.AccessKeyID, a.AccessKeySecret, "")
}

return nil
}

// Session returns an AWS Session configured with region and credentials.
func (a AWS) Session() (*session.Session, error) {
return session.NewSession(&aws.Config{
Region: aws.String(a.Region),
Credentials: a.Credentials(),
})
}
276 changes: 0 additions & 276 deletions lib/config/common.go

This file was deleted.

24 changes: 24 additions & 0 deletions lib/config/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package config

import (
"context"
"os"
"os/signal"
"syscall"
)

func ContextWithCancelOnSignal(ctx context.Context) context.Context {
ctx, cancel := context.WithCancel(ctx)
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)

go func() {
defer cancel()
select {
case <-stop:
case <-ctx.Done():
}
}()

return ctx
}
9 changes: 9 additions & 0 deletions lib/config/jwt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package config

// JWT configures public (and optionally private) keys and issuer for
// JSON Web Tokens. It is intended to be used in composition rather than a key.
type JWT struct {
Issuer string `json:"issuer"`
Public string `json:"public"`
Private string `json:"private,omitempty"`
}
Loading

0 comments on commit c4ec4eb

Please sign in to comment.