From 5475a326a983307201f47d88a78f56807f98ab59 Mon Sep 17 00:00:00 2001 From: Derek Horton Date: Mon, 22 Jan 2024 11:28:00 -0600 Subject: [PATCH 1/5] Use a different sources endpoint to get the rhc connection info --- internal/api/connectors/sources/impl.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/api/connectors/sources/impl.go b/internal/api/connectors/sources/impl.go index 11f47764..d2dc57b3 100644 --- a/internal/api/connectors/sources/impl.go +++ b/internal/api/connectors/sources/impl.go @@ -76,7 +76,7 @@ func (this *sourcesClientImpl) getRHCConnectionStatus(ctx context.Context, sourc ID := ID(sourceId) - res, err := this.client.GetRhcConnectionWithResponse(ctx, ID) + res, err := this.client.GetSourcesRhcConnectionWithResponse(ctx, ID, nil) if err != nil { return nil, err @@ -133,13 +133,18 @@ func (this *sourcesClientImpl) GetSourceConnectionDetails(ctx context.Context, s return SourceConnectionStatus{}, err } - rhcConnectionResponse, err := this.getRHCConnectionStatus(ctx, sourceID) + fmt.Println("sourcesResponse: ", sourcesResponse) + + source := (*sourcesResponse)[0] + + rhcConnectionResponse, err := this.getRHCConnectionStatus(ctx, *source.Id) if err != nil { return SourceConnectionStatus{}, err } - source := (*sourcesResponse)[0] + fmt.Println("rhcConnectionResponse: ", rhcConnectionResponse) + return SourceConnectionStatus{ ID: string(*source.Id), SourceName: source.Name, From f8c5ce7ab7543f3841c286da421d3683373e49cb Mon Sep 17 00:00:00 2001 From: Derek Horton Date: Mon, 22 Jan 2024 12:12:27 -0600 Subject: [PATCH 2/5] Try this --- internal/api/connectors/sources/impl.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/api/connectors/sources/impl.go b/internal/api/connectors/sources/impl.go index d2dc57b3..f0ccf322 100644 --- a/internal/api/connectors/sources/impl.go +++ b/internal/api/connectors/sources/impl.go @@ -71,7 +71,8 @@ func NewSourcesClient(cfg *viper.Viper) SourcesConnector { return NewSourcesClientWithHttpRequestDoer(cfg, &doer) } -func (this *sourcesClientImpl) getRHCConnectionStatus(ctx context.Context, sourceId string) (status *RhcConnectionRead, err error) { +func (this *sourcesClientImpl) getRHCConnectionStatus(ctx context.Context, sourceId string) (*[]RhcConnectionCollection, error) { + utils.GetLogFromContext(ctx).Debugw("Sending Sources RHC Connection Request") ID := ID(sourceId) @@ -137,18 +138,25 @@ func (this *sourcesClientImpl) GetSourceConnectionDetails(ctx context.Context, s source := (*sourcesResponse)[0] - rhcConnectionResponse, err := this.getRHCConnectionStatus(ctx, *source.Id) + rhcConnectionResponse, err := this.getRHCConnectionStatus(ctx, string(*source.Id)) if err != nil { return SourceConnectionStatus{}, err } fmt.Println("rhcConnectionResponse: ", rhcConnectionResponse) + fmt.Println("rhcConnectionResponse[0]: ", (*rhcConnectionResponse)[0]) + fmt.Println("rhcConnectionResponse[0].Data: ", (*rhcConnectionResponse)[0].Data) + + rhcInfo := (*rhcConnectionResponse)[0].Data + + fmt.Println("rhcInfo: ", rhcInfo) + fmt.Println("rhcInfo[0]: ", (*rhcInfo)[0]) return SourceConnectionStatus{ ID: string(*source.Id), SourceName: source.Name, - RhcID: rhcConnectionResponse.RhcId, - AvailabilityStatus: rhcConnectionResponse.AvailabilityStatus, + RhcID: (*rhcInfo)[0].RhcId, + AvailabilityStatus: (*rhcInfo)[0].AvailabilityStatus, }, err } From 14c14e7452ab8dbcf5e05e55d2ea94d545c6bfa9 Mon Sep 17 00:00:00 2001 From: Derek Horton Date: Mon, 22 Jan 2024 13:40:36 -0600 Subject: [PATCH 3/5] Adjust tests --- internal/api/connectors/sources/impl.go | 4 +++- internal/api/connectors/sources/sources_test.go | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/api/connectors/sources/impl.go b/internal/api/connectors/sources/impl.go index f0ccf322..f1904d1f 100644 --- a/internal/api/connectors/sources/impl.go +++ b/internal/api/connectors/sources/impl.go @@ -77,7 +77,9 @@ func (this *sourcesClientImpl) getRHCConnectionStatus(ctx context.Context, sourc ID := ID(sourceId) - res, err := this.client.GetSourcesRhcConnectionWithResponse(ctx, ID, nil) + params := GetSourcesRhcConnectionParams{} + + res, err := this.client.GetSourcesRhcConnectionWithResponse(ctx, ID, ¶ms) if err != nil { return nil, err diff --git a/internal/api/connectors/sources/sources_test.go b/internal/api/connectors/sources/sources_test.go index e732756b..148b61e2 100644 --- a/internal/api/connectors/sources/sources_test.go +++ b/internal/api/connectors/sources/sources_test.go @@ -13,7 +13,7 @@ var _ = Describe("Sources", func() { It("interperates response correctly", func() { responses := []test.MockHttpResponse{ {StatusCode: 200, Body: `{"data": [{"id": "1", "name": "test", "availability_status": "connected"}]}`}, - {StatusCode: 200, Body: `{"id": "1", "rhc_id": "6f37c752ba1c48b1bcf74ef8f585d8ee", "availability_status": "connected"}`}, + {StatusCode: 200, Body: `{"data": [{"id": "1", "rhc_id": "6f37c752ba1c48b1bcf74ef8f585d8ee", "availability_status": "connected"}]}`}, } doer := test.MockMultiResponseHttpClient(responses...) @@ -37,7 +37,7 @@ var _ = Describe("Sources", func() { It("interperates response correctly if fields are missing", func() { responses := []test.MockHttpResponse{ {StatusCode: 200, Body: `{"data": [{"id": "1", "name": "test"}]}`}, - {StatusCode: 200, Body: `{"id": "1"}`}, + {StatusCode: 200, Body: `{"data": [{"id": "1"}]}`}, } doer := test.MockMultiResponseHttpClient(responses...) From 2f1231f3f4a93ccef5412deb2d783f3271da1b4f Mon Sep 17 00:00:00 2001 From: Derek Horton Date: Mon, 22 Jan 2024 14:39:24 -0600 Subject: [PATCH 4/5] This seems wrong, but it makes the generated code happy --- internal/api/connectors/sources/sources_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/api/connectors/sources/sources_test.go b/internal/api/connectors/sources/sources_test.go index 148b61e2..97577495 100644 --- a/internal/api/connectors/sources/sources_test.go +++ b/internal/api/connectors/sources/sources_test.go @@ -13,7 +13,7 @@ var _ = Describe("Sources", func() { It("interperates response correctly", func() { responses := []test.MockHttpResponse{ {StatusCode: 200, Body: `{"data": [{"id": "1", "name": "test", "availability_status": "connected"}]}`}, - {StatusCode: 200, Body: `{"data": [{"id": "1", "rhc_id": "6f37c752ba1c48b1bcf74ef8f585d8ee", "availability_status": "connected"}]}`}, + {StatusCode: 200, Body: `[{"data": [{"id": "1", "rhc_id": "6f37c752ba1c48b1bcf74ef8f585d8ee", "availability_status": "connected"}]}]`}, } doer := test.MockMultiResponseHttpClient(responses...) @@ -37,7 +37,7 @@ var _ = Describe("Sources", func() { It("interperates response correctly if fields are missing", func() { responses := []test.MockHttpResponse{ {StatusCode: 200, Body: `{"data": [{"id": "1", "name": "test"}]}`}, - {StatusCode: 200, Body: `{"data": [{"id": "1"}]}`}, + {StatusCode: 200, Body: `[{"data": [{"id": "1"}]}]`}, } doer := test.MockMultiResponseHttpClient(responses...) From bc8a62fb6c61c26b3310dbc2c65e6181eb45a9dc Mon Sep 17 00:00:00 2001 From: Derek Horton Date: Mon, 22 Jan 2024 14:50:20 -0600 Subject: [PATCH 5/5] Print out the response from sources --- internal/api/connectors/sources/sources.gen.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/api/connectors/sources/sources.gen.go b/internal/api/connectors/sources/sources.gen.go index f9cd6c4d..68f79b6f 100644 --- a/internal/api/connectors/sources/sources.gen.go +++ b/internal/api/connectors/sources/sources.gen.go @@ -9966,6 +9966,8 @@ func ParseGetSourcesRhcConnectionResponse(rsp *http.Response) (*GetSourcesRhcCon return nil, err } + fmt.Println("bodyBytes:", string(bodyBytes)) + response := &GetSourcesRhcConnectionResponse{ Body: bodyBytes, HTTPResponse: rsp,