-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jkoberg <[email protected]>
- Loading branch information
Showing
24 changed files
with
737 additions
and
3 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
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
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
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
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 command | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/owncloud/ocis/v2/ocis-pkg/config" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/config/parser" | ||
"github.com/owncloud/ocis/v2/ocis/pkg/command/helper" | ||
"github.com/owncloud/ocis/v2/ocis/pkg/register" | ||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/command" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
// AuthServiceCommand is the entrypoint for the AuthService command. | ||
func AuthServiceCommand(cfg *config.Config) *cli.Command { | ||
return &cli.Command{ | ||
Name: cfg.AuthService.Service.Name, | ||
Usage: helper.SubcommandDescription(cfg.AuthService.Service.Name), | ||
Category: "services", | ||
Before: func(c *cli.Context) error { | ||
configlog.Error(parser.ParseConfig(cfg, true)) | ||
cfg.AuthService.Commons = cfg.Commons | ||
fmt.Println("SERVICE", cfg.AuthService.Commons.TokenManager.JWTSecret) | ||
return nil | ||
}, | ||
Subcommands: command.GetCommands(cfg.AuthService), | ||
} | ||
} | ||
|
||
func init() { | ||
register.AddCommand(AuthServiceCommand) | ||
} |
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
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,37 @@ | ||
SHELL := bash | ||
NAME := auth-service | ||
|
||
include ../../.make/recursion.mk | ||
|
||
############ tooling ############ | ||
ifneq (, $(shell command -v go 2> /dev/null)) # suppress `command not found warnings` for non go targets in CI | ||
include ../../.bingo/Variables.mk | ||
endif | ||
|
||
############ go tooling ############ | ||
include ../../.make/go.mk | ||
|
||
############ release ############ | ||
include ../../.make/release.mk | ||
|
||
############ docs generate ############ | ||
include ../../.make/docs.mk | ||
|
||
.PHONY: docs-generate | ||
docs-generate: config-docs-generate | ||
|
||
############ generate ############ | ||
include ../../.make/generate.mk | ||
|
||
.PHONY: ci-go-generate | ||
ci-go-generate: # CI runs ci-node-generate automatically before this target | ||
|
||
.PHONY: ci-node-generate | ||
ci-node-generate: | ||
|
||
############ licenses ############ | ||
.PHONY: ci-node-check-licenses | ||
ci-node-check-licenses: | ||
|
||
.PHONY: ci-node-save-licenses | ||
ci-node-save-licenses: |
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,14 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/command" | ||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/config/defaults" | ||
) | ||
|
||
func main() { | ||
if err := command.Execute(defaults.DefaultConfig()); err != nil { | ||
os.Exit(1) | ||
} | ||
} |
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,54 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" | ||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/config" | ||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/config/parser" | ||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/logging" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
// Health is the entrypoint for the health command. | ||
func Health(cfg *config.Config) *cli.Command { | ||
return &cli.Command{ | ||
Name: "health", | ||
Usage: "check health status", | ||
Category: "info", | ||
Before: func(c *cli.Context) error { | ||
return configlog.ReturnError(parser.ParseConfig(cfg)) | ||
}, | ||
Action: func(c *cli.Context) error { | ||
logger := logging.Configure(cfg.Service.Name, cfg.Log) | ||
|
||
resp, err := http.Get( | ||
fmt.Sprintf( | ||
"http://%s/healthz", | ||
cfg.Debug.Addr, | ||
), | ||
) | ||
|
||
if err != nil { | ||
logger.Fatal(). | ||
Err(err). | ||
Msg("Failed to request health check") | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
logger.Fatal(). | ||
Int("code", resp.StatusCode). | ||
Msg("Health seems to be in bad state") | ||
} | ||
|
||
logger.Debug(). | ||
Int("code", resp.StatusCode). | ||
Msg("Health got a good state") | ||
|
||
return nil | ||
}, | ||
} | ||
} |
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,34 @@ | ||
package command | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/owncloud/ocis/v2/ocis-pkg/clihelper" | ||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/config" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
// GetCommands provides all commands for this service | ||
func GetCommands(cfg *config.Config) cli.Commands { | ||
return []*cli.Command{ | ||
// start this service | ||
Server(cfg), | ||
|
||
// interaction with this service | ||
|
||
// infos about this service | ||
Health(cfg), | ||
Version(cfg), | ||
} | ||
} | ||
|
||
// Execute is the entry point for the ocis-auth-service command. | ||
func Execute(cfg *config.Config) error { | ||
app := clihelper.DefaultApp(&cli.App{ | ||
Name: "auth-service", | ||
Usage: "Provide service authentication for oCIS", | ||
Commands: GetCommands(cfg), | ||
}) | ||
|
||
return app.Run(os.Args) | ||
} |
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,99 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path" | ||
|
||
"github.com/cs3org/reva/v2/cmd/revad/runtime" | ||
"github.com/gofrs/uuid" | ||
"github.com/oklog/run" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/config/configlog" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/registry" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/sync" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/version" | ||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/config" | ||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/config/parser" | ||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/logging" | ||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/revaconfig" | ||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/server/debug" | ||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/tracing" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
// Server is the entry point for the server command. | ||
func Server(cfg *config.Config) *cli.Command { | ||
return &cli.Command{ | ||
Name: "server", | ||
Usage: fmt.Sprintf("start the %s service without runtime (unsupervised mode)", cfg.Service.Name), | ||
Category: "server", | ||
Before: func(c *cli.Context) error { | ||
return configlog.ReturnFatal(parser.ParseConfig(cfg)) | ||
}, | ||
Action: func(c *cli.Context) error { | ||
logger := logging.Configure(cfg.Service.Name, cfg.Log) | ||
err := tracing.Configure(cfg, logger) | ||
if err != nil { | ||
return err | ||
} | ||
gr := run.Group{} | ||
ctx, cancel := defineContext(cfg) | ||
|
||
defer cancel() | ||
|
||
pidFile := path.Join(os.TempDir(), "revad-"+cfg.Service.Name+"-"+uuid.Must(uuid.NewV4()).String()+".pid") | ||
|
||
rcfg := revaconfig.AuthMachineConfigFromStruct(cfg) | ||
|
||
gr.Add(func() error { | ||
runtime.RunWithOptions(rcfg, pidFile, runtime.WithLogger(&logger.Logger)) | ||
return nil | ||
}, func(err error) { | ||
logger.Error(). | ||
Err(err). | ||
Str("server", cfg.Service.Name). | ||
Msg("Shutting down server") | ||
|
||
cancel() | ||
}) | ||
|
||
debugServer, err := debug.Server( | ||
debug.Logger(logger), | ||
debug.Context(ctx), | ||
debug.Config(cfg), | ||
) | ||
|
||
if err != nil { | ||
logger.Info().Err(err).Str("server", "debug").Msg("Failed to initialize server") | ||
return err | ||
} | ||
|
||
gr.Add(debugServer.ListenAndServe, func(_ error) { | ||
cancel() | ||
}) | ||
|
||
if !cfg.Supervised { | ||
sync.Trap(&gr, cancel) | ||
} | ||
|
||
grpcSvc := registry.BuildGRPCService(cfg.GRPC.Namespace+"."+cfg.Service.Name, uuid.Must(uuid.NewV4()).String(), cfg.GRPC.Addr, version.GetString()) | ||
if err := registry.RegisterService(ctx, grpcSvc, logger); err != nil { | ||
logger.Fatal().Err(err).Msg("failed to register the grpc service") | ||
} | ||
|
||
return gr.Run() | ||
}, | ||
} | ||
} | ||
|
||
// defineContext sets the context for the service. If there is a context configured it will create a new child from it, | ||
// if not, it will create a root context that can be cancelled. | ||
func defineContext(cfg *config.Config) (context.Context, context.CancelFunc) { | ||
return func() (context.Context, context.CancelFunc) { | ||
if cfg.Context == nil { | ||
return context.WithCancel(context.Background()) | ||
} | ||
return context.WithCancel(cfg.Context) | ||
}() | ||
} |
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,50 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/owncloud/ocis/v2/ocis-pkg/registry" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/version" | ||
|
||
tw "github.com/olekukonko/tablewriter" | ||
"github.com/owncloud/ocis/v2/services/auth-service/pkg/config" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
// Version prints the service versions of all running instances. | ||
func Version(cfg *config.Config) *cli.Command { | ||
return &cli.Command{ | ||
Name: "version", | ||
Usage: "print the version of this binary and the running service instances", | ||
Category: "info", | ||
Action: func(c *cli.Context) error { | ||
fmt.Println("Version: " + version.GetString()) | ||
fmt.Printf("Compiled: %s\n", version.Compiled()) | ||
fmt.Println("") | ||
|
||
reg := registry.GetRegistry() | ||
services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Service.Name) | ||
if err != nil { | ||
fmt.Println(fmt.Errorf("could not get %s services from the registry: %v", cfg.Service.Name, err)) | ||
return err | ||
} | ||
|
||
if len(services) == 0 { | ||
fmt.Println("No running " + cfg.Service.Name + " service found.") | ||
return nil | ||
} | ||
|
||
table := tw.NewWriter(os.Stdout) | ||
table.SetHeader([]string{"Version", "Address", "Id"}) | ||
table.SetAutoFormatHeaders(false) | ||
for _, s := range services { | ||
for _, n := range s.Nodes { | ||
table.Append([]string{s.Version, n.Address, n.Id}) | ||
} | ||
} | ||
table.Render() | ||
return nil | ||
}, | ||
} | ||
} |
Oops, something went wrong.