-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cloud-provisioning): Adds functions to cloudproviders web client
Closes VC-33251
- Loading branch information
1 parent
bb54865
commit 9aad422
Showing
5 changed files
with
104 additions
and
10 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
internal/datasource/webclient/cloudproviders/cloudproviders.go
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,3 +1,46 @@ | ||
package cloudproviders | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/Khan/genqlient/graphql" | ||
"github.com/google/uuid" | ||
) | ||
|
||
//go:generate go run -mod=mod github.com/Khan/genqlient genqlient.yaml | ||
|
||
type CloudProvidersClient struct { | ||
graphqlClient graphql.Client | ||
} | ||
|
||
func NewCloudProvidersClient(url string, httpClient *http.Client) *CloudProvidersClient { | ||
return &CloudProvidersClient{ | ||
graphqlClient: graphql.NewClient(url, httpClient), | ||
} | ||
} | ||
|
||
func (c *CloudProvidersClient) GetCloudProviderByName(ctx context.Context, name string) (*CloudProvider, error) { | ||
if name == "" { | ||
return nil, fmt.Errorf("cloud provider name cannot be empty") | ||
} | ||
resp, err := GetCloudProviderByName(ctx, c.graphqlClient, name) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to retrieve Cloud Provider with name %s: %w", name, err) | ||
} | ||
if resp == nil || resp.GetCloudProviders() == nil || len(resp.GetCloudProviders().Nodes) != 1 { | ||
return nil, fmt.Errorf("could not find Cloud Provider with name %s", name) | ||
} | ||
|
||
cp := resp.GetCloudProviders().Nodes[0] | ||
|
||
return &CloudProvider{ | ||
ID: uuid.MustParse(cp.GetId()), | ||
Name: cp.GetName(), | ||
Type: string(cp.GetType()), | ||
Status: string(cp.GetStatus()), | ||
StatusDetails: *cp.GetStatusDetails(), | ||
KeystoresCount: cp.GetKeystoresCount(), | ||
}, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package cloudproviders | ||
|
||
import "github.com/google/uuid" | ||
|
||
type CloudProvider struct { | ||
ID uuid.UUID | ||
Name string | ||
Type string | ||
Status string | ||
StatusDetails string | ||
KeystoresCount int | ||
} |
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