Skip to content

Commit ae9d800

Browse files
Ramkishor ChaladiRamkishor Chaladi
authored andcommitted
Merge branch 'issue_719' of github.ibm.com:Ramkishor-Chaladi/softlayer-cli into issue_719
testing
2 parents 3322fe9 + e83cd24 commit ae9d800

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

plugin/commands/user/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func SetupCobraCommands(sl *metadata.SoftlayerCommand) *cobra.Command {
2929
cobraCmd.AddCommand(NewVpnSubnetCommand(sl).Command)
3030
cobraCmd.AddCommand(NewVpnManualCommand(sl).Command)
3131
cobraCmd.AddCommand(NewVpnPasswordCommand(sl).Command)
32+
cobraCmd.AddCommand(NewVpnEnableCommand(sl).Command)
3233
cobraCmd.AddCommand(NewApikeyCommand(sl).Command)
3334
return cobraCmd
3435
}

plugin/commands/user/user_suite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var availableCommands = []string{
3535
"vpn-manual",
3636
"vpn-password",
3737
"vpn-subnet",
38+
"vpn-enable",
3839
}
3940

4041
// This test suite exists to make sure commands don't get accidently removed from the SetupCobraCommands

plugin/commands/user/vpn_enable.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package user
2+
3+
import (
4+
"strconv"
5+
6+
"github.com/softlayer/softlayer-go/datatypes"
7+
"github.com/softlayer/softlayer-go/sl"
8+
"github.com/spf13/cobra"
9+
10+
slErrors "github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
11+
. "github.ibm.com/SoftLayer/softlayer-cli/plugin/i18n"
12+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/managers"
13+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
14+
)
15+
16+
type VpnEnableCommand struct {
17+
*metadata.SoftlayerCommand
18+
UserManager managers.UserManager
19+
Command *cobra.Command
20+
}
21+
22+
func NewVpnEnableCommand(sl *metadata.SoftlayerCommand) (cmd *VpnEnableCommand) {
23+
thisCmd := &VpnEnableCommand{
24+
SoftlayerCommand: sl,
25+
UserManager: managers.NewUserManager(sl.Session),
26+
}
27+
28+
cobraCmd := &cobra.Command{
29+
Use: "vpn-enable " + T("USER_ID"),
30+
Short: T("Enable vpn for a user."),
31+
Args: metadata.OneArgs,
32+
RunE: func(cmd *cobra.Command, args []string) error {
33+
return thisCmd.Run(args)
34+
},
35+
}
36+
37+
thisCmd.Command = cobraCmd
38+
return thisCmd
39+
}
40+
41+
func (cmd *VpnEnableCommand) Run(args []string) error {
42+
userID, err := strconv.Atoi(args[0])
43+
if err != nil {
44+
return slErrors.NewInvalidSoftlayerIdInputError("User ID")
45+
}
46+
userTemplate := datatypes.User_Customer{
47+
SslVpnAllowedFlag: sl.Bool(true),
48+
}
49+
success, err := cmd.UserManager.EditUser(userTemplate, userID)
50+
if err != nil {
51+
return slErrors.NewAPIError(T(""), err.Error(), 2)
52+
}
53+
if success {
54+
cmd.UI.Ok()
55+
}
56+
return nil
57+
}

0 commit comments

Comments
 (0)