-
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.
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
- Loading branch information
Showing
2 changed files
with
126 additions
and
0 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,77 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"strings" | ||
|
||
"github.com/self-actuated/actuated-cli/pkg" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func makeDisable() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "disable", | ||
Short: "Disable the actuated service remotely.", | ||
Example: ` # Disable the actuated systemd service from restarting | ||
actuated-cli disable --owner ORG HOST | ||
`, | ||
} | ||
|
||
cmd.RunE = runDisableE | ||
|
||
cmd.Flags().StringP("owner", "o", "", "Owner") | ||
|
||
return cmd | ||
} | ||
|
||
func runDisableE(cmd *cobra.Command, args []string) error { | ||
if len(args) < 1 { | ||
return fmt.Errorf("specify the host as an argument") | ||
} | ||
host := strings.TrimSpace(args[0]) | ||
|
||
pat, err := getPat(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
staff, err := cmd.Flags().GetBool("staff") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
owner, err := cmd.Flags().GetString("owner") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(owner) == 0 { | ||
return fmt.Errorf("owner is required") | ||
} | ||
|
||
if len(pat) == 0 { | ||
return fmt.Errorf("pat is required") | ||
} | ||
|
||
c := pkg.NewClient(http.DefaultClient, os.Getenv("ACTUATED_URL")) | ||
|
||
res, status, err := c.DisableAgent(pat, owner, host, staff) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if status != http.StatusOK && status != http.StatusAccepted && | ||
status != http.StatusNoContent && status != http.StatusCreated { | ||
return fmt.Errorf("unexpected status code: %d, error: %s", status, res) | ||
} | ||
|
||
fmt.Printf("Disable requested for %s, status: %d\n", owner, status) | ||
if strings.TrimSpace(res) != "" { | ||
fmt.Printf("Response: %s\n", 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