Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions internal/cmd/loadbalancer/add_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var AddServiceCmd = base.Cmd{
cmd.Flags().Bool("http-sticky-sessions", false, "Enable Sticky Sessions")
cmd.Flags().String("http-cookie-name", "", "Sticky Sessions: Cookie Name we set")
cmd.Flags().Duration("http-cookie-lifetime", 0, "Sticky Sessions: Lifetime of the cookie")
cmd.Flags().Int64Slice("http-certificates", []int64{}, "ID of Certificates which are attached to this Load Balancer")
cmd.Flags().StringSlice("http-certificates", []string{}, "IDs or names of Certificates which should be attached to this Load Balancer")
cmd.Flags().Bool("http-redirect-http", false, "Redirect all traffic on port 80 to port 443")

cmd.Flags().String("health-check-protocol", "", "The protocol the health check is performed over")
Expand All @@ -53,7 +53,7 @@ var AddServiceCmd = base.Cmd{
protocol, _ := cmd.Flags().GetString("protocol")
listenPort, _ := cmd.Flags().GetInt("listen-port")
destinationPort, _ := cmd.Flags().GetInt("destination-port")
httpCertificates, _ := cmd.Flags().GetInt64Slice("http-certificates")
httpCertificates, _ := cmd.Flags().GetStringSlice("http-certificates")

if protocol == "" {
return fmt.Errorf("required flag protocol not set")
Expand Down Expand Up @@ -123,8 +123,12 @@ var AddServiceCmd = base.Cmd{
if httpCookieLifetime != 0 {
opts.HTTP.CookieLifetime = &httpCookieLifetime
}
for _, certificateID := range httpCertificates {
opts.HTTP.Certificates = append(opts.HTTP.Certificates, &hcloud.Certificate{ID: certificateID})
for _, idOrName := range httpCertificates {
cert, _, err := s.Client().Certificate().Get(s, idOrName)
if err != nil {
return err
}
opts.HTTP.Certificates = append(opts.HTTP.Certificates, cert)
}
}

Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/loadbalancer/add_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func TestAddServiceWithHealthCheck(t *testing.T) {
fx.Client.LoadBalancerClient.EXPECT().
Get(gomock.Any(), "123").
Return(&hcloud.LoadBalancer{ID: 123}, nil, nil)
fx.Client.CertificateClient.EXPECT().
Get(gomock.Any(), "1").
Return(&hcloud.Certificate{ID: 1}, nil, nil)
fx.Client.LoadBalancerClient.EXPECT().
AddService(gomock.Any(), &hcloud.LoadBalancer{ID: 123}, hcloud.LoadBalancerAddServiceOpts{
Protocol: hcloud.LoadBalancerServiceProtocolHTTP,
Expand Down
12 changes: 8 additions & 4 deletions internal/cmd/loadbalancer/update_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var UpdateServiceCmd = base.Cmd{
cmd.Flags().Bool("http-sticky-sessions", false, "Enable or disable (with --http-sticky-sessions=false) Sticky Sessions")
cmd.Flags().String("http-cookie-name", "", "Sticky Sessions: Cookie Name which will be set")
cmd.Flags().Duration("http-cookie-lifetime", 0, "Sticky Sessions: Lifetime of the cookie")
cmd.Flags().Int64Slice("http-certificates", []int64{}, "ID of Certificates which are attached to this Load Balancer")
cmd.Flags().StringSlice("http-certificates", []string{}, "IDs or names of Certificates which should be attached to this Load Balancer")

cmd.Flags().String("health-check-protocol", "", "The protocol the health check is performed over")
cmd.Flags().Int("health-check-port", 0, "The port the health check is performed over")
Expand Down Expand Up @@ -104,9 +104,13 @@ var UpdateServiceCmd = base.Cmd{
opts.HTTP.CookieLifetime = &cookieLifetime
}
if cmd.Flag("http-certificates").Changed {
certificates, _ := cmd.Flags().GetInt64Slice("http-certificates")
for _, certificateID := range certificates {
opts.HTTP.Certificates = append(opts.HTTP.Certificates, &hcloud.Certificate{ID: certificateID})
certificates, _ := cmd.Flags().GetStringSlice("http-certificates")
for _, idOrName := range certificates {
cert, _, err := s.Client().Certificate().Get(s, idOrName)
if err != nil {
return err
}
opts.HTTP.Certificates = append(opts.HTTP.Certificates, cert)
}
}
// Health Check
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/loadbalancer/update_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func TestUpdateService(t *testing.T) {
fx.Client.LoadBalancerClient.EXPECT().
Get(gomock.Any(), "123").
Return(&hcloud.LoadBalancer{ID: 123}, nil, nil)
fx.Client.CertificateClient.EXPECT().
Get(gomock.Any(), "1").
Return(&hcloud.Certificate{ID: 1}, nil, nil)
fx.Client.LoadBalancerClient.EXPECT().
UpdateService(gomock.Any(), &hcloud.LoadBalancer{ID: 123}, 80, hcloud.LoadBalancerUpdateServiceOpts{
DestinationPort: hcloud.Ptr(8080),
Expand Down