-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⭕ retry on failed create of server, load balancer, and SSH key
- Loading branch information
1 parent
b63f052
commit 5d35e15
Showing
6 changed files
with
188 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
TF_ACC=1 | ||
BINARYLANE_API_TOKEN= | ||
|
||
# Uncomment to enable debug logging (will dump request bodies) | ||
# TF_LOG=DEBUG | ||
|
||
# Uncomment to disable the Go cache when testing, useful for flaky tests | ||
# GOCACHE=off |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package binarylane | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"net/http/httputil" | ||
|
||
"github.com/deepmap/oapi-codegen/pkg/securityprovider" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
) | ||
|
||
func NewClientWithAuth(endpoint string, token string) (*ClientWithResponses, error) { | ||
if token == "" { | ||
return nil, errors.New("missing or empty value for the Binary Lane API " + | ||
"token. Set the `api_token` value in the configuration or use the " + | ||
"BINARYLANE_API_TOKEN environment variable. If either is already set, " + | ||
"ensure the value is not empty") | ||
} | ||
|
||
auth, err := securityprovider.NewSecurityProviderBearerToken(token) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create API client with supplied API token: %w", err) | ||
} | ||
|
||
if endpoint == "" { | ||
endpoint = "https://api.binarylane.com.au/v2" | ||
} | ||
|
||
client, err := NewClientWithResponses( | ||
endpoint, | ||
WithRequestEditorFn(func(ctx context.Context, req *http.Request) error { | ||
dump, err := httputil.DumpRequestOut(req, true) | ||
if err != nil { | ||
return err | ||
} | ||
tflog.Debug(ctx, fmt.Sprintf("%q\n", dump)) | ||
return nil | ||
}), | ||
WithRequestEditorFn(auth.Intercept), // include auth AFTER the request logger | ||
) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("failed to create Binary Lane API client: %w", err) | ||
} | ||
|
||
return client, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters