forked from uyuni-project/uyuni-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove.go
More file actions
68 lines (56 loc) · 1.67 KB
/
Copy pathremove.go
File metadata and controls
68 lines (56 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-FileCopyrightText: 2026 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0
package knownhost
import (
"fmt"
"net/url"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/uyuni-project/uyuni-tools/shared/api"
. "github.com/uyuni-project/uyuni-tools/shared/l10n"
"github.com/uyuni-project/uyuni-tools/shared/types"
"github.com/uyuni-project/uyuni-tools/shared/utils"
)
func removeKnownHost(client *api.APIClient, hostname string, port string) error {
params := url.Values{
"hostname": {hostname},
"port": {port},
}
path := "admin/ssh/removeKnownHost?" + params.Encode()
var data map[string]interface{}
res, err := api.PostChecked[interface{}](client, path, "api.admin.ssh.remove_known_host", data)
if err != nil {
return utils.Errorf(err, L("error in query '%s'"), path)
}
if !res.Success {
return fmt.Errorf(L("failed to remove the host: %s"), res.Message)
}
success, ok := res.Result.(float64)
if !ok {
return fmt.Errorf(L("unexpected server response '%v'"), res.Result)
}
if int(success) == 1 {
fmt.Println(L("successfully removed host"))
} else {
fmt.Println(L("unable to remove host, server returned an error"))
}
return nil
}
func runRemoveKnownHost(_ *types.GlobalFlags, flags *apiFlags, _ *cobra.Command, args []string) error {
hostname := args[0]
// Default to port 22 if none is provided
port := "22"
if len(args) == 2 {
port = args[1]
}
log.Debug().Msgf("Removing host %s:%s", hostname, port)
client, err := api.Init(&flags.ConnectionDetails)
if err == nil {
err = client.Login()
}
if err != nil {
return utils.Errorf(err, L("unable to login to the server"))
}
return removeKnownHost(client, hostname, port)
}