-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command for staff for controller logs
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
- Loading branch information
Showing
5 changed files
with
139 additions
and
1 deletion.
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,66 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"time" | ||
|
||
"github.com/self-actuated/actuated-cli/pkg" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func makeControllerLogs() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "logs", | ||
Short: "Fetch logs from the controller's systemd service", | ||
Example: ` # Latest logs for a given host: | ||
actuated controller logs --age 15m | ||
`, | ||
} | ||
|
||
cmd.RunE = runControllerLogsE | ||
|
||
cmd.Flags().DurationP("age", "a", time.Minute*15, "Age of logs to fetch") | ||
cmd.Flags().StringP("output", "o", "cat", "Output format, use \"cat\" for brevity") | ||
|
||
return cmd | ||
} | ||
|
||
func runControllerLogsE(cmd *cobra.Command, args []string) error { | ||
|
||
pat, err := getPat(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
outputFormat, err := cmd.Flags().GetString("output") | ||
if err != nil { | ||
return err | ||
} | ||
age, err := cmd.Flags().GetDuration("age") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(pat) == 0 { | ||
return fmt.Errorf("pat is required") | ||
} | ||
|
||
c := pkg.NewClient(http.DefaultClient, os.Getenv("ACTUATED_URL")) | ||
|
||
res, status, err := c.GetControllerLogs(pat, outputFormat, age) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
if status != http.StatusOK { | ||
return fmt.Errorf("unexpected status code: %d, body: %s", status, res) | ||
} | ||
|
||
fmt.Println(res) | ||
|
||
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,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func makeController() *cobra.Command { | ||
|
||
controller := &cobra.Command{ | ||
Use: "controller", | ||
Short: "Staff commands for the controller", | ||
Hidden: true, | ||
SilenceErrors: true, | ||
SilenceUsage: true, | ||
} | ||
|
||
controller.AddCommand(makeControllerLogs()) | ||
|
||
return controller | ||
} |
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