-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config: refactor into multiple files (#782)
- Loading branch information
1 parent
c70c4bd
commit c4ec4eb
Showing
10 changed files
with
329 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
Oops, something went wrong.