Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
minor edits
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpitz committed Sep 6, 2021
1 parent 2d9f014 commit ab4dbed
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 37 deletions.
8 changes: 4 additions & 4 deletions charts/aetherfs/Chart.yaml → charts/dex/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: v2
type: application
name: aetherfs
description: A Helm chart for Kubernetes
version: 0.1.0
appVersion: "1.16.0"
name: dex
description: A Helm chart for deploying Dex, a federated identity provider.
version: 0.0.0
appVersion: 0.0.0
dependencies:
- repository: https://charts.dexidp.io
name: dex
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions internal/auth/authn_func.go → internal/auth/authn_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"golang.org/x/oauth2"
)

// OIDCAuthenticationFunc returns a HandleFunc who authenticates a user with the provided issuer using an access_token
// AuthenticatorOIDC returns a HandleFunc who authenticates a user with the provided issuer using an access_token
// attached to the request. If provided, this access_token is exchanged for the authenticated users information. It's
// important to know that this function does not handle authorization and requires an additional HandleFunc to do so.
func OIDCAuthenticationFunc(issuerURL string) HandleFunc {
func AuthenticatorOIDC(cfg *OIDCIssuer) HandleFunc {
mu := &sync.Mutex{}
var provider *oidc.Provider

Expand All @@ -24,7 +24,7 @@ func OIDCAuthenticationFunc(issuerURL string) HandleFunc {

if provider == nil {
var err error
provider, err = oidc.NewProvider(ctx, issuerURL)
provider, err = oidc.NewProvider(ctx, cfg.ServerURL)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/auth/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type contextKey string

const userInfoContextKey = contextKey("user_info")

// ExtractUserInfo will extract the oidc.UserInfo from the request. This function assumes the OIDCAuthenticationFunc has
// ExtractUserInfo will extract the oidc.UserInfo from the request. This function assumes the AuthenticatorOIDC has
// run. If it hasn't then the UserInfo
func ExtractUserInfo(ctx context.Context) *oidc.UserInfo {
v := ctx.Value(userInfoContextKey)
Expand Down
4 changes: 3 additions & 1 deletion internal/commands/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (

// AgentConfig encapsulates the requirements for configuring and starting up the Agent process.
type AgentConfig struct {
OIDCIssuer auth.OIDCIssuer `json:"oidc_issuer,omitempty"`
OIDC struct {
Issuer auth.OIDCIssuer `json:"issuer,omitempty"`
} `json:"oidc,omitempty"`
}

// Agent returns a cli.Command that can be added to an existing application.
Expand Down
4 changes: 3 additions & 1 deletion internal/commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (

// ServerConfig encapsulates the requirements for configuring and starting up the Server process.
type ServerConfig struct {
OIDCIssuer auth.OIDCIssuer `json:"oidc_issuer,omitempty"`
OIDC struct {
Issuer auth.OIDCIssuer `json:"issuer,omitempty"`
} `json:"oidc,omitempty"`
}

// Server returns a cli.Command that can be added to an existing application.
Expand Down
2 changes: 1 addition & 1 deletion internal/flagset/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func extract(prefix []string, v interface{}) []cli.Flag {

// recursive field types
switch fieldValue.Kind() {
case reflect.Ptr, reflect.Struct:
case reflect.Struct:
pre := prefix
if name != "" {
pre = append(pre, name)
Expand Down
20 changes: 20 additions & 0 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package logger

import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

// Config encapsulates the configurable elements of the logger.
type Config struct {
Level *zapcore.Level `json:"level,omitempty" usage:"adjust the verbosity of the logs"`
Format string `json:"format,omitempty" usage:"configure the format of the logs"`
}

// Setup creates a logger given the provided configuration.
func Setup(cfg Config) (*zap.Logger, error) {
zapConfig := zap.NewProductionConfig()
zapConfig.Level.SetLevel(*(cfg.Level))
zapConfig.Encoding = cfg.Format
return zapConfig.Build()
}
49 changes: 23 additions & 26 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@ import (
"context"
_ "embed"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"time"

"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"github.com/urfave/cli/v2"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"github.com/mjpitz/aetherfs/internal/authors"
"github.com/mjpitz/aetherfs/internal/commands"
"github.com/mjpitz/aetherfs/internal/flagset"
"github.com/mjpitz/aetherfs/internal/logger"
)

type GlobalConfig struct {
Log logger.Config `json:"log,omitempty"`
State string `json:"state,omitempty" usage:"location where AetherFS can write small amounts of data"`
Config string `json:"config,omitempty" usage:"location of the client configuration file"`
}

//go:embed AUTHORS
var authorsFileContents string

Expand All @@ -46,7 +52,13 @@ func main() {
}

logLevel := zapcore.InfoLevel
logFormat := "json"
cfg := &GlobalConfig{
Log: logger.Config{
Level: &logLevel,
Format: "json",
},
State: "/usr/local/aetherfs",
}

app := &cli.App{
Name: "aetherfs",
Expand All @@ -61,34 +73,18 @@ func main() {
commands.Push(),
commands.Server(),
},
Flags: []cli.Flag{
&cli.GenericFlag{
Name: "log-level",
Usage: "the verbosity of logs",
Value: &logLevel,
EnvVars: []string{"LOG_LEVEL"},
},
&cli.StringFlag{
Name: "log-format",
Usage: "how logs should be format",
Destination: &logFormat,
Value: logFormat,
EnvVars: []string{"LOG_FORMAT"},
},
},
Flags: flagset.Extract(cfg),
Before: func(ctx *cli.Context) error {
cfg := zap.NewProductionConfig()
cfg.Level.SetLevel(logLevel)
cfg.Encoding = logFormat

logger, err := cfg.Build()
log, err := logger.Setup(cfg.Log)
if err != nil {
return err
}

log.Debug("before")

var cancel context.CancelFunc
ctx.Context, cancel = context.WithCancel(ctx.Context)
ctx.Context = ctxzap.ToContext(ctx.Context, logger)
ctx.Context = ctxzap.ToContext(ctx.Context, log)

halt := make(chan os.Signal, 1)
signal.Notify(halt, syscall.SIGINT, syscall.SIGTERM)
Expand All @@ -97,7 +93,7 @@ func main() {
<-halt
signal.Stop(halt)

logger.Info("shutting down")
log.Info("shutting down")
cancel()
}()

Expand All @@ -108,6 +104,7 @@ func main() {
// - destroy outgoing connections
// - ensure db files are closed
// - etc
ctxzap.Extract(ctx.Context).Debug("after")
return nil
},
Compiled: compiled,
Expand All @@ -117,6 +114,6 @@ func main() {

err = app.Run(os.Args)
if err != nil {
log.Print(err)
fmt.Println(err)
}
}

0 comments on commit ab4dbed

Please sign in to comment.