-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cmd/authenticator and misc command tweaks
Add an authenticator command that will register, and re-authenticate, a telemetry client system, and will report the current auth token's issuer and expiration date. Extended TelemtryClient with methods to get the ExpirationDate() and Issuer() for the currently active token. Added internal helper methods to support this. Quietened some log messages by switching them to debug level and tweaked some others to be more useful. Added output messages to cmd/generator describing the steps that it has performed. Similarly updated cmd/clientds to say that nothing was found if the client datastore is empty. Note that this change pulls support for JWT processing into the client side library.
- Loading branch information
Showing
14 changed files
with
283 additions
and
20 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,15 @@ | ||
module github.com/SUSE/telemetry/cmd/authenticator | ||
|
||
go 1.21 | ||
|
||
replace github.com/SUSE/telemetry => ../../ | ||
|
||
require github.com/SUSE/telemetry v0.0.0-00010101000000-000000000000 | ||
|
||
require ( | ||
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/mattn/go-sqlite3 v1.14.22 // indirect | ||
github.com/xyproto/randomstring v1.0.5 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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,18 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= | ||
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= | ||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= | ||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= | ||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU= | ||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,124 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log/slog" | ||
|
||
"github.com/SUSE/telemetry/pkg/client" | ||
"github.com/SUSE/telemetry/pkg/config" | ||
"github.com/SUSE/telemetry/pkg/logging" | ||
) | ||
|
||
// options is a struct of the options | ||
type options struct { | ||
config string | ||
dryrun bool | ||
noregister bool | ||
authenticate bool | ||
debug bool | ||
} | ||
|
||
var opts options | ||
|
||
func main() { | ||
if err := logging.SetupBasicLogging(opts.debug); err != nil { | ||
panic(err) | ||
} | ||
|
||
slog.Debug("Authenticator", slog.Any("options", opts)) | ||
|
||
cfg, err := config.NewConfig(opts.config) | ||
if err != nil { | ||
slog.Error( | ||
"Failed to load config", | ||
slog.String("config", opts.config), | ||
slog.String("error", err.Error()), | ||
) | ||
panic(err) | ||
} | ||
|
||
// setup logging based upon config settings | ||
lm := logging.NewLogManager() | ||
if err := lm.Config(&cfg.Logging); err != nil { | ||
panic(err) | ||
} | ||
|
||
// override config log level to debug if option specified | ||
if opts.debug { | ||
lm.SetLevel("DEBUG") | ||
slog.Debug("Debug mode enabled") | ||
} | ||
|
||
if err := lm.Setup(); err != nil { | ||
panic(err) | ||
} | ||
|
||
tc, err := client.NewTelemetryClient(cfg) | ||
if err != nil { | ||
slog.Error( | ||
"Failed to instantiate TelemetryClient", | ||
slog.String("config", opts.config), | ||
slog.String("error", err.Error()), | ||
) | ||
panic(err) | ||
} | ||
|
||
if !opts.noregister { | ||
err = tc.Register() | ||
if err != nil { | ||
slog.Error( | ||
"Failed to register TelemetryClient", | ||
slog.String("error", err.Error()), | ||
) | ||
panic(err) | ||
} | ||
} | ||
|
||
if opts.authenticate { | ||
err = tc.Authenticate() | ||
if err != nil { | ||
slog.Error( | ||
"Failed to (re)uthenticate TelemetryClient", | ||
slog.String("error", err.Error()), | ||
) | ||
panic(err) | ||
} | ||
} | ||
|
||
issuer, err := tc.AuthIssuer() | ||
if err != nil { | ||
slog.Error( | ||
"AuthIssuer() failed", | ||
slog.String("err", err.Error()), | ||
) | ||
} | ||
|
||
expiration, err := tc.AuthExpiration() | ||
if err != nil { | ||
slog.Error( | ||
"AuthExpiration() failed", | ||
slog.String("err", err.Error()), | ||
) | ||
} | ||
|
||
fmt.Printf( | ||
"Current Auth Token:\n %-[1]*[2]s %[3]s\n %-[1]*[4]s %[5]s\n %-[1]*[6]s %[7]s\n", | ||
19, | ||
"Issuer:", | ||
issuer, | ||
"Expiration (UTC):", | ||
expiration.UTC().Format("2006-01-02T15:04:05.000000"), | ||
"Expiration (local):", | ||
expiration.Format("2006-01-02T15:04:05.000000Z07:00"), | ||
) | ||
} | ||
|
||
func init() { | ||
flag.StringVar(&opts.config, "config", client.CONFIG_PATH, "Path to config file to read") | ||
flag.BoolVar(&opts.debug, "debug", false, "Whether to enable debug level logging.") | ||
flag.BoolVar(&opts.dryrun, "dryrun", false, "Process provided JSON files but do add them to the telemetry staging area.") | ||
flag.BoolVar(&opts.noregister, "noregister", false, "Whether to skip registering the telemetry client if it is needed.") | ||
flag.BoolVar(&opts.authenticate, "authenticate", false, "Whether to (re)authenticate the telemetry client.") | ||
flag.Parse() | ||
} |
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
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
Oops, something went wrong.