Skip to content

Instantly share code, notes, and snippets.

@lzap
Created May 22, 2023 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lzap/49b2f6f70892e6a8df84786c8192e344 to your computer and use it in GitHub Desktop.
Save lzap/49b2f6f70892e6a8df84786c8192e344 to your computer and use it in GitHub Desktop.
Working example for getting sources in one request
Index: internal/clients/http/sources/sources_client.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/internal/clients/http/sources/sources_client.go b/internal/clients/http/sources/sources_client.go
--- a/internal/clients/http/sources/sources_client.go (revision 5dc168130a2751cfead58bf47576a79c0b5f4218)
+++ b/internal/clients/http/sources/sources_client.go (date 1684762681785)
@@ -5,6 +5,8 @@
"encoding/json"
"errors"
"fmt"
+ stdhttp "net/http"
+ "net/url"
"github.com/RHEnVision/provisioning-backend/internal/cache"
"github.com/RHEnVision/provisioning-backend/internal/clients"
@@ -89,7 +91,10 @@
return nil, fmt.Errorf("failed to get provisioning app type: %w", err)
}
- resp, err := c.client.ListApplicationTypeSourcesWithResponse(ctx, appTypeId, &ListApplicationTypeSourcesParams{}, headers.AddSourcesIdentityHeader, headers.AddEdgeRequestIdHeader)
+ resp, err := c.client.ListApplicationTypeSourcesWithResponse(ctx, appTypeId, &ListApplicationTypeSourcesParams{}, headers.AddSourcesIdentityHeader, headers.AddEdgeRequestIdHeader, func(ctx context.Context, req *stdhttp.Request) error {
+ req.URL.RawQuery = url.QueryEscape("filter[source_type_id]") + "=4"
+ return nil
+ })
if err != nil {
logger.Warn().Err(err).Msg("Failed to fetch ApplicationTypes from sources")
return nil, fmt.Errorf("failed to get ApplicationTypes: %w", err)
@@ -103,25 +108,16 @@
return nil, fmt.Errorf("list provisioning sources call: %w", err)
}
- result := make([]*clients.Source, 0, len(*resp.JSON200.Data))
-
- for _, src := range *resp.JSON200.Data {
- sourceTypeName, err := c.GetSourceTypeName(ctx, *src.SourceTypeId)
- if err != nil {
- return nil, fmt.Errorf("could not get source type name for source type id %d: %w", src.SourceTypeId, err)
- }
-
- if sourceTypeName == models.ProviderTypeFromString(provider.String()) {
- newSrc := clients.Source{
- Id: src.Id,
- Name: src.Name,
- SourceTypeId: src.SourceTypeId,
- Uid: src.Uid,
- }
- result = append(result, &newSrc)
+ result := make([]*clients.Source, len(*resp.JSON200.Data))
+ for i, src := range *resp.JSON200.Data {
+ newSrc := clients.Source{
+ Id: src.Id,
+ Name: src.Name,
+ SourceTypeId: src.SourceTypeId,
+ Uid: src.Uid,
}
+ result[i] = &newSrc
}
-
return result, nil
}
Index: scripts/rest_examples/sources-list-aws.http
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/scripts/rest_examples/sources-list-aws.http b/scripts/rest_examples/sources-list-aws.http
new file mode 100644
--- /dev/null (date 1684757653057)
+++ b/scripts/rest_examples/sources-list-aws.http (date 1684757653057)
@@ -0,0 +1,4 @@
+// @no-log
+GET http://{{hostname}}:{{port}}/{{prefix}}/sources?provider=aws HTTP/1.1
+Content-Type: application/json
+X-Rh-Identity: {{identity}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment