File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
cloud-controller-manager/osc/oapi Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import (
1414
1515 osc "github.com/outscale/osc-sdk-go/v2"
1616 "k8s.io/klog/v2"
17+ "k8s.io/utils/ptr"
1718)
1819
1920const (
@@ -33,11 +34,11 @@ var (
3334
3435func (c * OscClient ) CheckCredentials (ctx context.Context ) error {
3536 logger := klog .FromContext (ctx )
36- req := osc.ReadVmsRequest {}
37+ req := osc.ReadVmsRequest {DryRun : ptr . To ( true ) }
3738 logger .V (4 ).Info ("Check credentials" , "OAPI" , "ReadVms" )
3839 _ , httpRes , err := c .api .VmApi .ReadVms (c .WithAuth (ctx )).ReadVmsRequest (req ).Execute ()
3940 switch {
40- case err == nil || httpRes .StatusCode == http .StatusTooManyRequests :
41+ case err == nil || ( httpRes != nil && httpRes .StatusCode == http .StatusTooManyRequests ) :
4142 return nil
4243 case httpRes == nil :
4344 logger .V (3 ).Error (err , "OAPI error" , "OAPI" , "ReadVms" )
Original file line number Diff line number Diff line change @@ -21,4 +21,12 @@ func TestCheckCredentials(t *testing.T) {
2121 err = api .OAPI ().CheckCredentials (t .Context ())
2222 require .ErrorIs (t , err , oapi .ErrInvalidCredentials )
2323 })
24+ t .Run ("CheckCredentials returns an error in case of a network problem" , func (t * testing.T ) {
25+ t .Setenv ("OSC_ACCESS_KEY" , "foo" )
26+ t .Setenv ("OSC_SECRET_KEY" , "bar" )
27+ api , err := oapi .NewClient ("foo" )
28+ require .NoError (t , err )
29+ err = api .OAPI ().CheckCredentials (t .Context ())
30+ require .Error (t , err )
31+ })
2432}
You can’t perform that action at this time.
0 commit comments