Skip to content

Commit 1243c6f

Browse files
Chore: go.mod Update to latest openapi spec (#1905)
* update to latest openapi spec * Fix unexpected application/text content-type * Use generated transport from openapi client * Update only the transport and not the whole client * Try it again... * Skipping alerting message test for versions previous than 10.0.0 * Restore original file * Add it too inOrg test * Use content-type negotiator only for affected query * Remove unused imports 😒 * Rename file --------- Co-authored-by: spinillos <[email protected]>
1 parent 2b68f37 commit 1243c6f

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/go-openapi/strfmt v0.23.0
1212
github.com/grafana/amixr-api-go-client v0.0.16 // main branch
1313
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240807172819-ac10800522a3
14-
github.com/grafana/grafana-openapi-client-go v0.0.0-20240723170622-ae2c94b7c9a3
14+
github.com/grafana/grafana-openapi-client-go v0.0.0-20241113095943-9cb2bbfeb8a3
1515
github.com/grafana/machine-learning-go-client v0.8.2
1616
github.com/grafana/slo-openapi-client/go/slo v0.0.0-20240807172758-1b7d00838fc7
1717
github.com/grafana/synthetic-monitoring-agent v0.29.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ github.com/grafana/amixr-api-go-client v0.0.16 h1:CXdqnLKjvo6QoNPBKxmZ2kGKCcUoAl
140140
github.com/grafana/amixr-api-go-client v0.0.16/go.mod h1:N6x26XUrM5zGtK5zL5vNJnAn2JFMxLFPPLTw/6pDkFE=
141141
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240807172819-ac10800522a3 h1:CVLTffnWgBGvVaXfUUcSgFrZbiMzvj0/Hpi909zdeG0=
142142
github.com/grafana/grafana-com-public-clients/go/gcom v0.0.0-20240807172819-ac10800522a3/go.mod h1:u9d0BESoKlztYm93CpoRleQjMbYBcZ+JOLHHP2nN6Wg=
143-
github.com/grafana/grafana-openapi-client-go v0.0.0-20240723170622-ae2c94b7c9a3 h1:W35ScJIkeyLuDlOo3F+u1JSRRvmoIYYf/ghA/17Y18Q=
144-
github.com/grafana/grafana-openapi-client-go v0.0.0-20240723170622-ae2c94b7c9a3/go.mod h1:hiZnMmXc9KXNUlvkV2BKFsiWuIFF/fF4wGgYWEjBitI=
143+
github.com/grafana/grafana-openapi-client-go v0.0.0-20241113095943-9cb2bbfeb8a3 h1:poKxGlUaEYVp2DMofC/I2GHw/vvtHAZ20c48I8rFB6M=
144+
github.com/grafana/grafana-openapi-client-go v0.0.0-20241113095943-9cb2bbfeb8a3/go.mod h1:hiZnMmXc9KXNUlvkV2BKFsiWuIFF/fF4wGgYWEjBitI=
145145
github.com/grafana/grafana-plugin-sdk-go v0.250.0 h1:9EBucp9jLqMx2b8NTlOXH+4OuQWUh6L85c6EJUN8Jdo=
146146
github.com/grafana/grafana-plugin-sdk-go v0.250.0/go.mod h1:gCGN9kHY3KeX4qyni3+Kead38Q+85pYOrsDcxZp6AIk=
147147
github.com/grafana/machine-learning-go-client v0.8.2 h1:TvU4e+Kgg4GhwBNYTMjBUNq4tbhcxe0L8w1eo/UfV2M=

internal/resources/grafana/common_check_exists_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package grafana_test
22

33
import (
44
"fmt"
5+
"net/http"
56
"os"
67
"strconv"
78
"strings"
@@ -41,7 +42,7 @@ var (
4142
alertingMessageTemplateCheckExists = newCheckExistsHelper(
4243
func(t *models.NotificationTemplate) string { return t.Name },
4344
func(client *goapi.GrafanaHTTPAPI, id string) (*models.NotificationTemplate, error) {
44-
resp, err := client.Provisioning.GetTemplate(id)
45+
resp, err := client.Provisioning.GetTemplate(id, grafana.ContentTypeNegotiator(http.DefaultTransport))
4546
return payloadOrError(resp, err)
4647
},
4748
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package grafana
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/go-openapi/runtime"
7+
"github.com/go-openapi/runtime/middleware"
8+
)
9+
10+
func ContentTypeNegotiator(tripper http.RoundTripper) func(operation *runtime.ClientOperation) {
11+
return func(operation *runtime.ClientOperation) {
12+
operation.Client = &http.Client{Transport: newContentTypeRoundTripperTest(tripper)}
13+
}
14+
}
15+
16+
// contentTypeRoundTripperTest identifies unexpected "text/pain" responses when "application/json" is expected.
17+
// It could happen when something fails related to an "implementation bug".
18+
type contentTypeRoundTripperTest struct {
19+
originalRoundTripper http.RoundTripper
20+
}
21+
22+
func newContentTypeRoundTripperTest(originalRoundTripper http.RoundTripper) http.RoundTripper {
23+
return &contentTypeRoundTripperTest{originalRoundTripper: originalRoundTripper}
24+
}
25+
26+
func (r *contentTypeRoundTripperTest) RoundTrip(req *http.Request) (*http.Response, error) {
27+
resp, err := r.originalRoundTripper.RoundTrip(req)
28+
if err != nil {
29+
return nil, err
30+
}
31+
32+
mid := middleware.NegotiateContentType(req, []string{"application/json", "application/text"}, "application/text")
33+
resp.Header.Set("Content-Type", mid)
34+
35+
return resp, nil
36+
}

internal/resources/grafana/resource_alerting_message_template.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ func putMessageTemplate(ctx context.Context, data *schema.ResourceData, meta int
145145
func deleteMessageTemplate(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
146146
client, _, name := OAPIClientFromExistingOrgResource(meta, data.Id())
147147

148-
_, err := client.Provisioning.DeleteTemplate(name)
148+
params := provisioning.NewDeleteTemplateParams().WithName(name)
149+
_, err := client.Provisioning.DeleteTemplate(params)
149150
diag, _ := common.CheckReadError("message template", data, err)
150151
return diag
151152
}

0 commit comments

Comments
 (0)