-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovider_credential_tests.go
More file actions
47 lines (39 loc) · 1.37 KB
/
provider_credential_tests.go
File metadata and controls
47 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package api
import (
"context"
"encoding/json"
"fmt"
"net/http"
"gopkg.in/nullstone-io/go-api-client.v0/response"
)
type ProviderCredentialTests struct {
Client *Client
}
func (s ProviderCredentialTests) testSavedPath(providerName string) string {
return fmt.Sprintf("orgs/%s/providers/%s/credential_test", s.Client.Config.OrgName, providerName)
}
func (s ProviderCredentialTests) testNewPath() string {
return fmt.Sprintf("orgs/%s/provider_credential_tests", s.Client.Config.OrgName)
}
type TestNewProviderCredentialsInput struct {
ProviderType string `json:"providerType"`
ProviderId string `json:"providerId"`
Credentials json.RawMessage `json:"credentials"`
}
// TestSaved - GET /orgs/:orgName/providers/:providerName/credential_test
func (s ProviderCredentialTests) TestSaved(ctx context.Context, providerName string) error {
res, err := s.Client.Do(ctx, http.MethodGet, s.testSavedPath(providerName), nil, nil, nil)
if err != nil {
return err
}
return response.Verify(res)
}
// TestNew - POST /orgs/:orgName/provider_credential_tests
func (s ProviderCredentialTests) TestNew(ctx context.Context, input TestNewProviderCredentialsInput) error {
rawPayload, _ := json.Marshal(input)
res, err := s.Client.Do(ctx, http.MethodPost, s.testNewPath(), nil, nil, json.RawMessage(rawPayload))
if err != nil {
return err
}
return response.Verify(res)
}