Skip to content

Commit 653979d

Browse files
#714 added SSL certificate option for protocol-add
1 parent dc1e25d commit 653979d

3 files changed

Lines changed: 43 additions & 44 deletions

File tree

plugin/commands/loadbal/protocols_add.go

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type ProtocolAddCommand struct {
2626
Sticky string
2727
ClientTimeout int
2828
ServerTimeout int
29+
SslId int
2930
}
3031

3132
func NewProtocolAddCommand(sl *metadata.SoftlayerCommand) *ProtocolAddCommand {
@@ -36,22 +37,30 @@ func NewProtocolAddCommand(sl *metadata.SoftlayerCommand) *ProtocolAddCommand {
3637
cobraCmd := &cobra.Command{
3738
Use: "protocol-add",
3839
Short: T("Add a new load balancer protocol"),
39-
Long: T("${COMMAND_NAME} sl loadbal protocol-add (--id LOADBAL_ID) [--front-protocol PROTOCOL] [back-protocol PROTOCOL] [--front-port PORT] [--back-port PORT] [-m, --method METHOD] [-c, --connections CONNECTIONS] [--sticky cookie | source-ip] [--client-timeout SECONDS] [--server-timeout SECONDS]"),
40+
Long: T(`Creates a new mapping between incoming traffic to the loadbalancer and the backend servers.
41+
Use '{COMMAND_NAME} sl security cert-list' to get IDs for the --ssl-id option.
42+
See: https://cloud.ibm.com/docs/loadbalancer-service?topic=loadbalancer-service-about-ibm-cloud-load-balancer for more details
43+
44+
Example:
45+
${COMMAND_NAME} sl loadbal protocol-add --id 1115129 --front-port 443 --front-protocol HTTPS --back-port 80 --back-protocol HTTP --ssl-id 335659 --client-timeout 60 --connections 100
46+
Creates a new protocol on Load Balancer 1115129 that terminates SSL on port 443, mapping to a backend port 80 HTTP. Using SSL cert 335659
47+
`),
4048
Args: metadata.NoArgs,
4149
RunE: func(cmd *cobra.Command, args []string) error {
4250
return thisCmd.Run(args)
4351
},
4452
}
4553
cobraCmd.Flags().IntVar(&thisCmd.Id, "id", 0, T("ID for the load balancer [required]"))
4654
cobraCmd.Flags().StringVar(&thisCmd.FrontProtocol, "front-protocol", "HTTP", T("Protocol type to use for incoming connections: [HTTP|HTTPS|TCP]. Default: HTTP"))
47-
cobraCmd.Flags().StringVar(&thisCmd.BackProtocol, "back-protocol", "", T("Protocol type to use when connecting to backend servers: [HTTP|HTTPS|TCP]. Defaults to whatever --front-protocol is"))
55+
cobraCmd.Flags().StringVar(&thisCmd.BackProtocol, "back-protocol", "HTTP", T("Protocol type to use when connecting to backend servers: [HTTP|HTTPS|TCP]. Defaults to whatever --front-protocol is"))
4856
cobraCmd.Flags().IntVar(&thisCmd.FrontPort, "front-port", 80, T("Internet side port"))
4957
cobraCmd.Flags().IntVar(&thisCmd.BackPort, "back-port", 80, T("Private side port"))
5058
cobraCmd.Flags().StringVarP(&thisCmd.Method, "method", "m", "ROUNDROBIN", T("Balancing Method: [ROUNDROBIN|LEASTCONNECTION|WEIGHTED_RR]"))
5159
cobraCmd.Flags().IntVarP(&thisCmd.Connections, "connections", "c", 0, T("Maximum number of connections to allow"))
5260
cobraCmd.Flags().StringVar(&thisCmd.Sticky, "sticky", "", T("Use 'cookie' or 'source-ip' to stick"))
5361
cobraCmd.Flags().IntVar(&thisCmd.ClientTimeout, "client-timeout", 0, T("Client side timeout setting, in seconds"))
5462
cobraCmd.Flags().IntVar(&thisCmd.ServerTimeout, "server-timeout", 0, T("Server side timeout setting, in seconds"))
63+
cobraCmd.Flags().IntVar(&thisCmd.SslId, "ssl-id", 0, T("Identifier of the SSL certificate to attach to this protocol. Only valid for HTTPS."))
5564
thisCmd.Command = cobraCmd
5665
return thisCmd
5766
}
@@ -62,42 +71,19 @@ func (cmd *ProtocolAddCommand) Run(args []string) error {
6271
return errors.NewMissingInputError("--id")
6372
}
6473

65-
frontProtocol := cmd.FrontProtocol
66-
if frontProtocol == "" {
67-
frontProtocol = "HTTP"
68-
}
69-
70-
backProtocol := cmd.BackProtocol
71-
if backProtocol == "" {
72-
backProtocol = frontProtocol
73-
}
74-
75-
frontPort := cmd.FrontPort
76-
if frontPort == 0 {
77-
frontPort = 80
78-
}
79-
80-
backPort := cmd.BackPort
81-
if backPort == 0 {
82-
backPort = 80
83-
}
84-
85-
method := cmd.Method
86-
if method == "" {
87-
method = "ROUNDROBIN"
88-
}
8974

9075
loadbalancerUUID, err := cmd.LoadBalancerManager.GetLoadBalancerUUID(loadbalID)
9176
if err != nil {
9277
return errors.New(T("Failed to get load balancer: {{.ERR}}.", map[string]interface{}{"ERR": err.Error()}))
9378
}
9479

80+
// Sets up all the required parameters
9581
protocolConfigurations := datatypes.Network_LBaaS_LoadBalancerProtocolConfiguration{
96-
BackendPort: &backPort,
97-
BackendProtocol: &backProtocol,
98-
FrontendPort: &frontPort,
99-
FrontendProtocol: &frontProtocol,
100-
LoadBalancingMethod: &method,
82+
BackendPort: &cmd.BackPort,
83+
BackendProtocol: &cmd.BackProtocol,
84+
FrontendPort: &cmd.FrontPort,
85+
FrontendProtocol: &cmd.FrontProtocol,
86+
LoadBalancingMethod: &cmd.Method,
10187
}
10288

10389
var sessionType string
@@ -112,21 +98,23 @@ func (cmd *ProtocolAddCommand) Run(args []string) error {
11298
}
11399

114100
if cmd.Connections != 0 {
115-
connections := cmd.Connections
116-
protocolConfigurations.MaxConn = &connections
101+
protocolConfigurations.MaxConn = &cmd.Connections
117102
}
118103

119104
if cmd.ClientTimeout != 0 {
120-
cTimeout := cmd.ClientTimeout
121-
protocolConfigurations.ClientTimeout = &cTimeout
105+
protocolConfigurations.ClientTimeout = &cmd.ClientTimeout
122106
}
123107

124108
if cmd.ServerTimeout != 0 {
125-
sTimeout := cmd.ServerTimeout
126-
protocolConfigurations.ServerTimeout = &sTimeout
109+
protocolConfigurations.ServerTimeout = &cmd.ServerTimeout
127110
}
128111

129-
_, err = cmd.LoadBalancerManager.AddLoadBalancerListener(&loadbalancerUUID, []datatypes.Network_LBaaS_LoadBalancerProtocolConfiguration{protocolConfigurations})
112+
if cmd.SslId != 0 {
113+
protocolConfigurations.TlsCertificateId = &cmd.SslId
114+
}
115+
_, err = cmd.LoadBalancerManager.AddLoadBalancerListener(
116+
&loadbalancerUUID, []datatypes.Network_LBaaS_LoadBalancerProtocolConfiguration{protocolConfigurations},
117+
)
130118
if err != nil {
131119
return errors.New(T("Failed to add protocol: {{.Error}}.\n", map[string]interface{}{"Error": err.Error()}))
132120
}

plugin/commands/loadbal/protocols_add_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ var _ = Describe("LoadBal_protocol-add_Test", func() {
8787
Expect(*argsForCall[0].LoadBalancingMethod).To(Equal("ROUNDROBIN"))
8888
Expect(fakeUI.Outputs()).To(ContainSubstring("OK"))
8989
})
90+
It("--ssl-id option", func() {
91+
err := testhelpers.RunCobraCommand(cliCommand.Command, "--id", "12345", "--ssl-id=9999", "--front-protocol=HTTPS")
92+
Expect(err).NotTo(HaveOccurred())
93+
lbUUID, argsForCall := fakeLBManager.AddLoadBalancerListenerArgsForCall(0)
94+
Expect(*lbUUID).To(Equal("aaa-bbb-111"))
95+
Expect(len(argsForCall)).To(Equal(1))
96+
Expect(*argsForCall[0].FrontendProtocol).To(Equal("HTTPS"))
97+
Expect(*argsForCall[0].BackendProtocol).To(Equal("HTTP"))
98+
Expect(*argsForCall[0].TlsCertificateId).To(Equal(9999))
99+
Expect(fakeUI.Outputs()).To(ContainSubstring("OK"))
100+
})
90101
It("with sticky as cookie", func() {
91102
err := testhelpers.RunCobraCommand(cliCommand.Command, "--id", "12345", "--sticky", "cookie")
92103
Expect(err).NotTo(HaveOccurred())

plugin/i18n/v2Resources/active.en-US.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@
185185
"${COMMAND_NAME} sl loadbal order-options [-d, --datacenter DATACENTER]": {
186186
"other": "${COMMAND_NAME} sl loadbal order-options [-d, --datacenter DATACENTER]"
187187
},
188-
"${COMMAND_NAME} sl loadbal protocol-add (--id LOADBAL_ID) [--front-protocol PROTOCOL] [back-protocol PROTOCOL] [--front-port PORT] [--back-port PORT] [-m, --method METHOD] [-c, --connections CONNECTIONS] [--sticky cookie | source-ip] [--client-timeout SECONDS] [--server-timeout SECONDS]": {
189-
"other": "${COMMAND_NAME} sl loadbal protocol-add (--id LOADBAL_ID) [--front-protocol PROTOCOL] [back-protocol PROTOCOL] [--front-port PORT] [--back-port PORT] [-m, --method METHOD] [-c, --connections CONNECTIONS] [--sticky cookie | source-ip] [--client-timeout SECONDS] [--server-timeout SECONDS]"
190-
},
191188
"${COMMAND_NAME} sl loadbal protocol-delete (--lb-id LOADBAL_ID) (--protocol-uuid PROTOCOL_UUID)": {
192189
"other": "${COMMAND_NAME} sl loadbal protocol-delete (--lb-id LOADBAL_ID) (--protocol-uuid PROTOCOL_UUID)"
193190
},
@@ -1568,6 +1565,9 @@
15681565
"Created translation from {{.StaticIP}} to {{.RemoteIP}} #{{.ID}}.": {
15691566
"other": "Created translation from {{.StaticIP}} to {{.RemoteIP}} #{{.ID}}."
15701567
},
1568+
"Creates a new mapping between incoming traffic to the loadbalancer and the backend servers.\nUse '{COMMAND_NAME} sl security cert-list' to get IDs for the --ssl-id option.\nSee: https://cloud.ibm.com/docs/loadbalancer-service?topic=loadbalancer-service-about-ibm-cloud-load-balancer for more details\n\nExample:\n\t${COMMAND_NAME} sl loadbal protocol-add --id 1115129 --front-port 443 --front-protocol HTTPS --back-port 80 --back-protocol HTTP --ssl-id 335659 --client-timeout 60 --connections 100\n\tCreates a new protocol on Load Balancer 1115129 that terminates SSL on port 443, mapping to a backend port 80 HTTP. Using SSL cert 335659\n": {
1569+
"other": "Creates a new mapping between incoming traffic to the loadbalancer and the backend servers.\nUse '{COMMAND_NAME} sl security cert-list' to get IDs for the --ssl-id option.\nSee: https://cloud.ibm.com/docs/loadbalancer-service?topic=loadbalancer-service-about-ibm-cloud-load-balancer for more details\n\nExample:\n\t${COMMAND_NAME} sl loadbal protocol-add --id 1115129 --front-port 443 --front-protocol HTTPS --back-port 80 --back-protocol HTTP --ssl-id 335659 --client-timeout 60 --connections 100\n\tCreates a new protocol on Load Balancer 1115129 that terminates SSL on port 443, mapping to a backend port 80 HTTP. Using SSL cert 335659\n"
1570+
},
15711571
"Creates a purge record and also initiates the purge call.": {
15721572
"other": "Creates a purge record and also initiates the purge call."
15731573
},
@@ -3914,6 +3914,9 @@
39143914
"Identifier": {
39153915
"other": "Identifier"
39163916
},
3917+
"Identifier of the SSL certificate to attach to this protocol. Only valid for HTTPS.": {
3918+
"other": "Identifier of the SSL certificate to attach to this protocol. Only valid for HTTPS."
3919+
},
39173920
"If a volume (with replication) becomes inaccessible due to a disaster event, this method can be used to immediately\nfailover to an available replica in another location. This method does not allow for fail back via the API.\nTo fail back to the original volume after using this method, open a support ticket.\nTo test failover, use '${COMMAND_NAME} sl {{.storageType}} replica-failover' instead.\n\nEXAMPLE:\n\t${COMMAND_NAME} sl {{.storageType}} disaster-recovery-failover 12345678 87654321\n\tThis command performs failover operation for volume with ID 12345678 to replica volume with ID 87654321.": {
39183921
"other": "If a volume (with replication) becomes inaccessible due to a disaster event, this method can be used to immediately\nfailover to an available replica in another location. This method does not allow for fail back via the API.\nTo fail back to the original volume after using this method, open a support ticket.\nTo test failover, use '${COMMAND_NAME} sl {{.storageType}} replica-failover' instead.\n\nEXAMPLE:\n\t${COMMAND_NAME} sl {{.storageType}} disaster-recovery-failover 12345678 87654321\n\tThis command performs failover operation for volume with ID 12345678 to replica volume with ID 87654321."
39193922
},
@@ -5009,9 +5012,6 @@
50095012
"POOL_UUID, URL or HTTPS_PROTOCOL_UUID . It's only available in REDIRECT_POOL | REDIRECT_URL | REDIRECT_HTTPS action": {
50105013
"other": "POOL_UUID, URL or HTTPS_PROTOCOL_UUID . It's only available in REDIRECT_POOL | REDIRECT_URL | REDIRECT_HTTPS action"
50115014
},
5012-
"PPTP VPN": {
5013-
"other": "PPTP VPN"
5014-
},
50155015
"Package": {
50165016
"other": "Package"
50175017
},

0 commit comments

Comments
 (0)