generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathwaypoint.go
141 lines (119 loc) · 4.87 KB
/
waypoint.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package clients
import (
"context"
sharedmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models"
"github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/client/waypoint_service"
waypoint_models "github.com/hashicorp/hcp-sdk-go/clients/cloud-waypoint-service/preview/2023-08-18/models"
)
// getNamespaceByLocation will retrieve a namespace by location information
// provided by HCP
func getNamespaceByLocation(_ context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation) (*waypoint_models.HashicorpCloudWaypointNamespace, error) {
namespaceParams := &waypoint_service.WaypointServiceGetNamespaceParams{
LocationOrganizationID: loc.OrganizationID,
LocationProjectID: loc.ProjectID,
}
// get namespace
ns, err := client.Waypoint.WaypointServiceGetNamespace(namespaceParams, nil)
if err != nil {
return nil, err
}
return ns.GetPayload().Namespace, nil
}
// GetApplicationTemplateByName will retrieve an application template by name
func GetApplicationTemplateByName(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, appName string) (*waypoint_models.HashicorpCloudWaypointApplicationTemplate, error) {
ns, err := getNamespaceByLocation(ctx, client, loc)
if err != nil {
return nil, err
}
params := &waypoint_service.WaypointServiceGetApplicationTemplate2Params{
ApplicationTemplateName: appName,
NamespaceID: ns.ID,
}
getResp, err := client.Waypoint.WaypointServiceGetApplicationTemplate2(params, nil)
if err != nil {
return nil, err
}
return getResp.GetPayload().ApplicationTemplate, nil
}
// GetApplicationTemplateByID will retrieve an application template by ID
func GetApplicationTemplateByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, appID string) (*waypoint_models.HashicorpCloudWaypointApplicationTemplate, error) {
ns, err := getNamespaceByLocation(ctx, client, loc)
if err != nil {
return nil, err
}
params := &waypoint_service.WaypointServiceGetApplicationTemplateParams{
ApplicationTemplateID: appID,
NamespaceID: ns.ID,
}
getResp, err := client.Waypoint.WaypointServiceGetApplicationTemplate(params, nil)
if err != nil {
return nil, err
}
return getResp.GetPayload().ApplicationTemplate, nil
}
// GetAddOnDefinitionByName will retrieve an add-on definition by name
func GetAddOnDefinitionByName(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, defName string) (*waypoint_models.HashicorpCloudWaypointAddOnDefinition, error) {
ns, err := getNamespaceByLocation(ctx, client, loc)
if err != nil {
return nil, err
}
params := &waypoint_service.WaypointServiceGetAddOnDefinition2Params{
AddOnDefinitionName: defName,
NamespaceID: ns.ID,
}
getResp, err := client.Waypoint.WaypointServiceGetAddOnDefinition2(params, nil)
if err != nil {
return nil, err
}
return getResp.GetPayload().AddOnDefinition, nil
}
// GetAddOnDefinitionByID will retrieve an add-on definition by ID
func GetAddOnDefinitionByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, defID string) (*waypoint_models.HashicorpCloudWaypointAddOnDefinition, error) {
ns, err := getNamespaceByLocation(ctx, client, loc)
if err != nil {
return nil, err
}
params := &waypoint_service.WaypointServiceGetAddOnDefinitionParams{
AddOnDefinitionID: defID,
NamespaceID: ns.ID,
}
getResp, err := client.Waypoint.WaypointServiceGetAddOnDefinition(params, nil)
if err != nil {
return nil, err
}
return getResp.GetPayload().AddOnDefinition, nil
}
// GetApplicationByName will retrieve an application by name
func GetApplicationByName(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, appName string) (*waypoint_models.HashicorpCloudWaypointApplication, error) {
ns, err := getNamespaceByLocation(ctx, client, loc)
if err != nil {
return nil, err
}
params := &waypoint_service.WaypointServiceGetApplication2Params{
ApplicationName: appName,
NamespaceID: ns.ID,
}
getResp, err := client.Waypoint.WaypointServiceGetApplication2(params, nil)
if err != nil {
return nil, err
}
return getResp.GetPayload().Application, nil
}
// GetApplicationByID will retrieve an application by ID
func GetApplicationByID(ctx context.Context, client *Client, loc *sharedmodels.HashicorpCloudLocationLocation, appID string) (*waypoint_models.HashicorpCloudWaypointApplication, error) {
ns, err := getNamespaceByLocation(ctx, client, loc)
if err != nil {
return nil, err
}
params := &waypoint_service.WaypointServiceGetApplicationParams{
ApplicationID: appID,
NamespaceID: ns.ID,
}
getResp, err := client.Waypoint.WaypointServiceGetApplication(params, nil)
if err != nil {
return nil, err
}
return getResp.GetPayload().Application, nil
}