-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
471 additions
and
2 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,158 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/humanlogio/humanlog/internal/pkg/config" | ||
"github.com/humanlogio/humanlog/internal/pkg/state" | ||
"github.com/humanlogio/humanlog/pkg/auth" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
const ( | ||
accountCmdName = "account" | ||
) | ||
|
||
func accountCmd( | ||
getCtx func(cctx *cli.Context) context.Context, | ||
getCfg func(cctx *cli.Context) *config.Config, | ||
getState func(cctx *cli.Context) *state.State, | ||
getTokenSource func(cctx *cli.Context) *auth.UserRefreshableTokenSource, | ||
getAPIUrl func(cctx *cli.Context) string, | ||
getHTTPClient func(*cli.Context) *http.Client, | ||
) cli.Command { | ||
return cli.Command{ | ||
Name: accountCmdName, | ||
Usage: "Manage accounts for the current user or org.", | ||
Before: func(cctx *cli.Context) error { | ||
ctx := getCtx(cctx) | ||
state := getState(cctx) | ||
tokenSource := getTokenSource(cctx) | ||
apiURL := getAPIUrl(cctx) | ||
httpClient := getHTTPClient(cctx) | ||
_, err := ensureLoggedIn(ctx, cctx, state, tokenSource, apiURL, httpClient) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
Subcommands: []cli.Command{ | ||
{ | ||
Name: "set-current", | ||
Action: func(cctx *cli.Context) error { | ||
ctx := getCtx(cctx) | ||
state := getState(cctx) | ||
tokenSource := getTokenSource(cctx) | ||
apiURL := getAPIUrl(cctx) | ||
httpClient := getHTTPClient(cctx) | ||
|
||
accountName := cctx.Args().First() | ||
// lookup `accountName` and set its ID in `state` | ||
_ = ctx | ||
_ = state | ||
_ = tokenSource | ||
_ = apiURL | ||
_ = httpClient | ||
_ = accountName | ||
|
||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "get-current", | ||
Action: func(cctx *cli.Context) error { | ||
ctx := getCtx(cctx) | ||
state := getState(cctx) | ||
tokenSource := getTokenSource(cctx) | ||
apiURL := getAPIUrl(cctx) | ||
httpClient := getHTTPClient(cctx) | ||
|
||
accountName := cctx.Args().First() | ||
// lookup `account ID` in state, and resolve to `accountName` via API | ||
_ = ctx | ||
_ = state | ||
_ = tokenSource | ||
_ = apiURL | ||
_ = httpClient | ||
_ = accountName | ||
|
||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "create", | ||
Action: func(cctx *cli.Context) error { | ||
ctx := getCtx(cctx) | ||
state := getState(cctx) | ||
tokenSource := getTokenSource(cctx) | ||
apiURL := getAPIUrl(cctx) | ||
httpClient := getHTTPClient(cctx) | ||
|
||
_ = ctx | ||
_ = state | ||
_ = tokenSource | ||
_ = apiURL | ||
_ = httpClient | ||
|
||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "get", | ||
Action: func(cctx *cli.Context) error { | ||
ctx := getCtx(cctx) | ||
state := getState(cctx) | ||
tokenSource := getTokenSource(cctx) | ||
apiURL := getAPIUrl(cctx) | ||
httpClient := getHTTPClient(cctx) | ||
|
||
_ = ctx | ||
_ = state | ||
_ = tokenSource | ||
_ = apiURL | ||
_ = httpClient | ||
|
||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "update", | ||
Action: func(cctx *cli.Context) error { | ||
ctx := getCtx(cctx) | ||
state := getState(cctx) | ||
tokenSource := getTokenSource(cctx) | ||
apiURL := getAPIUrl(cctx) | ||
httpClient := getHTTPClient(cctx) | ||
|
||
_ = ctx | ||
_ = state | ||
_ = tokenSource | ||
_ = apiURL | ||
_ = httpClient | ||
|
||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "list", | ||
Usage: "list the accounts for the current user or org", | ||
Action: func(cctx *cli.Context) error { | ||
ctx := getCtx(cctx) | ||
state := getState(cctx) | ||
tokenSource := getTokenSource(cctx) | ||
apiURL := getAPIUrl(cctx) | ||
httpClient := getHTTPClient(cctx) | ||
|
||
_ = ctx | ||
_ = state | ||
_ = tokenSource | ||
_ = apiURL | ||
_ = httpClient | ||
|
||
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,76 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/humanlogio/humanlog/internal/pkg/config" | ||
"github.com/humanlogio/humanlog/internal/pkg/state" | ||
"github.com/humanlogio/humanlog/pkg/auth" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
const ( | ||
machineCmdName = "machine" | ||
) | ||
|
||
func machineCmd( | ||
getCtx func(cctx *cli.Context) context.Context, | ||
getCfg func(cctx *cli.Context) *config.Config, | ||
getState func(cctx *cli.Context) *state.State, | ||
getTokenSource func(cctx *cli.Context) *auth.UserRefreshableTokenSource, | ||
getAPIUrl func(cctx *cli.Context) string, | ||
getHTTPClient func(*cli.Context) *http.Client, | ||
) cli.Command { | ||
return cli.Command{ | ||
Name: machineCmdName, | ||
Usage: "Manage machines in the current account.", | ||
Before: func(cctx *cli.Context) error { | ||
ctx := getCtx(cctx) | ||
state := getState(cctx) | ||
tokenSource := getTokenSource(cctx) | ||
apiURL := getAPIUrl(cctx) | ||
httpClient := getHTTPClient(cctx) | ||
_, err := ensureLoggedIn(ctx, cctx, state, tokenSource, apiURL, httpClient) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
Subcommands: []cli.Command{ | ||
{ | ||
Name: "register", | ||
Usage: "register this machine to save logs in account", | ||
Action: func(cctx *cli.Context) error { | ||
ctx := getCtx(cctx) | ||
state := getState(cctx) | ||
tokenSource := getTokenSource(cctx) | ||
apiURL := getAPIUrl(cctx) | ||
httpClient := getHTTPClient(cctx) | ||
accountToken, err := createIngestionToken(ctx, cctx, state, tokenSource, apiURL, httpClient) | ||
if err != nil { | ||
return fmt.Errorf("ingestion token couldn't be generated: %v", err) | ||
} | ||
state.IngestionToken = accountToken | ||
if err := state.WriteBack(); err != nil { | ||
return fmt.Errorf("writing back generated ingestion token: %v", err) | ||
} | ||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "deregister", | ||
Usage: "deregister this machine from saving logs in account", | ||
Action: func(cctx *cli.Context) error { | ||
state := getState(cctx) | ||
state.IngestionToken = nil | ||
if err := state.WriteBack(); err != nil { | ||
return fmt.Errorf("writing back generated ingestion token: %v", err) | ||
} | ||
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 |
---|---|---|
|
@@ -175,11 +175,22 @@ func newApp() *cli.App { | |
} | ||
|
||
app := cli.NewApp() | ||
app.Author = "Antoine Grondin" | ||
app.Email = "[email protected]" | ||
app.Author = "humanlog.io" | ||
app.Email = "[email protected]" | ||
app.Name = "humanlog" | ||
app.Version = semverVersion.String() | ||
app.Usage = "reads structured logs from stdin, makes them pretty on stdout!" | ||
app.Description = `humanlog parses logs and makes them easier to read and search. | ||
When invoked with no argument, it consumes stdin and parses it, | ||
attempts to make it prettier on stdout. It also allows searching | ||
the logs that were parsed, both in a TUI by pressing "s" or in a | ||
webapp by pressing "space". | ||
If registered to ingest logs via "humanlog machine register" logs | ||
will be saved to humanlog.io for vizualization, searching and | ||
analysis. | ||
` | ||
|
||
var ( | ||
ctx context.Context | ||
|
@@ -297,6 +308,9 @@ func newApp() *cli.App { | |
app.Commands, | ||
versionCmd(getCtx, getLogger, getCfg, getState, getTokenSource, getAPIUrl, getHTTPClient), | ||
authCmd(getCtx, getCfg, getState, getTokenSource, getAPIUrl, getHTTPClient), | ||
organizationCmd(getCtx, getCfg, getState, getTokenSource, getAPIUrl, getHTTPClient), | ||
accountCmd(getCtx, getCfg, getState, getTokenSource, getAPIUrl, getHTTPClient), | ||
machineCmd(getCtx, getCfg, getState, getTokenSource, getAPIUrl, getHTTPClient), | ||
queryCmd(getCtx, getCfg, getState, getTokenSource, getAPIUrl, getHTTPClient), | ||
gennyCmd(getCtx, getCfg, getState), | ||
) | ||
|
Oops, something went wrong.