Skip to content

Commit

Permalink
Merge pull request #893 from syself/handle-unauthorized
Browse files Browse the repository at this point in the history
🐛 Handle remaining unauthorized
  • Loading branch information
batistein authored Sep 3, 2023
2 parents 95fab03 + 5b56c88 commit 5a4324b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/services/hcloud/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,25 @@ func (c *realClient) AddTargetServerToLoadBalancer(ctx context.Context, opts hcl

func (c *realClient) AddIPTargetToLoadBalancer(ctx context.Context, opts hcloud.LoadBalancerAddIPTargetOpts, lb *hcloud.LoadBalancer) error {
_, _, err := c.client.LoadBalancer.AddIPTarget(ctx, lb, opts)
if err != nil && strings.Contains(err.Error(), errStringUnauthorized) {
return fmt.Errorf("%w: %w", ErrUnauthorized, err)
}
return err
}

func (c *realClient) DeleteTargetServerOfLoadBalancer(ctx context.Context, lb *hcloud.LoadBalancer, server *hcloud.Server) error {
_, _, err := c.client.LoadBalancer.RemoveServerTarget(ctx, lb, server)
if err != nil && strings.Contains(err.Error(), errStringUnauthorized) {
return fmt.Errorf("%w: %w", ErrUnauthorized, err)
}
return err
}

func (c *realClient) DeleteIPTargetOfLoadBalancer(ctx context.Context, lb *hcloud.LoadBalancer, ip net.IP) error {
_, _, err := c.client.LoadBalancer.RemoveIPTarget(ctx, lb, ip)
if err != nil && strings.Contains(err.Error(), errStringUnauthorized) {
return fmt.Errorf("%w: %w", ErrUnauthorized, err)
}
return err
}

Expand Down Expand Up @@ -196,7 +205,11 @@ func (c *realClient) GetServer(ctx context.Context, id int) (*hcloud.Server, err
}

func (c *realClient) ListServerTypes(ctx context.Context) ([]*hcloud.ServerType, error) {
return c.client.ServerType.All(ctx)
resp, err := c.client.ServerType.All(ctx)
if err != nil && strings.Contains(err.Error(), errStringUnauthorized) {
return resp, fmt.Errorf("%w: %w", ErrUnauthorized, err)
}
return resp, err
}

func (c *realClient) GetServerType(ctx context.Context, name string) (*hcloud.ServerType, error) {
Expand Down

0 comments on commit 5a4324b

Please sign in to comment.