-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for the Proxy Checks API and the Create operation.
- Loading branch information
Showing
4 changed files
with
117 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package clerk | ||
|
||
type ProxyCheck struct { | ||
APIResource | ||
Object string `json:"object"` | ||
ID string `json:"id"` | ||
DomainID string `json:"domain_id"` | ||
ProxyURL string `json:"proxy_url"` | ||
Successful bool `json:"successful"` | ||
LastRunAt *int64 `json:"last_run_at"` | ||
CreatedAt int64 `json:"created_at"` | ||
UpdatedAt int64 `json:"updated_at"` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,43 @@ | ||
// Package proxycheck provides the Proxy Checks API. | ||
package proxycheck | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/clerk/clerk-sdk-go/v2" | ||
) | ||
|
||
//go:generate go run ../cmd/gen/main.go | ||
|
||
const path = "/proxy_checks" | ||
|
||
// Client is used to invoke the Proxy Checks API. | ||
type Client struct { | ||
Backend clerk.Backend | ||
} | ||
|
||
type ClientConfig struct { | ||
clerk.BackendConfig | ||
} | ||
|
||
func NewClient(config *ClientConfig) *Client { | ||
return &Client{ | ||
Backend: clerk.NewBackend(&config.BackendConfig), | ||
} | ||
} | ||
|
||
type CreateParams struct { | ||
clerk.APIParams | ||
DomainID *string `json:"domain_id,omitempty"` | ||
ProxyURL *string `json:"proxy_url,omitempty"` | ||
} | ||
|
||
// Create creates a proxy check. | ||
func (c *Client) Create(ctx context.Context, params *CreateParams) (*clerk.ProxyCheck, error) { | ||
req := clerk.NewAPIRequest(http.MethodPost, path) | ||
req.SetParams(params) | ||
resource := &clerk.ProxyCheck{} | ||
err := c.Backend.Call(ctx, req, resource) | ||
return resource, err | ||
} |
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,40 @@ | ||
package proxycheck | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/clerk/clerk-sdk-go/v2" | ||
"github.com/clerk/clerk-sdk-go/v2/clerktest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestProxyCheckClientCreate(t *testing.T) { | ||
t.Parallel() | ||
id := "proxchk_123" | ||
proxyURL := "https://clerk.com/__proxy" | ||
domainID := "dmn_123" | ||
config := &ClientConfig{} | ||
config.HTTPClient = &http.Client{ | ||
Transport: &clerktest.RoundTripper{ | ||
T: t, | ||
In: json.RawMessage(fmt.Sprintf(`{"domain_id":"%s","proxy_url":"%s"}`, domainID, proxyURL)), | ||
Out: json.RawMessage(fmt.Sprintf(`{"id":"%s","domain_id":"%s","proxy_url":"%s","successful":true}`, id, domainID, proxyURL)), | ||
Method: http.MethodPost, | ||
Path: "/v1/proxy_checks", | ||
}, | ||
} | ||
client := NewClient(config) | ||
proxyCheck, err := client.Create(context.Background(), &CreateParams{ | ||
ProxyURL: clerk.String(proxyURL), | ||
DomainID: clerk.String(domainID), | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, id, proxyCheck.ID) | ||
require.Equal(t, proxyURL, proxyCheck.ProxyURL) | ||
require.Equal(t, domainID, proxyCheck.DomainID) | ||
require.True(t, proxyCheck.Successful) | ||
} |