diff --git a/internal/api/connectors/sources/impl.go b/internal/api/connectors/sources/impl.go index 11f47764..f1904d1f 100644 --- a/internal/api/connectors/sources/impl.go +++ b/internal/api/connectors/sources/impl.go @@ -71,12 +71,15 @@ 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) - res, err := this.client.GetRhcConnectionWithResponse(ctx, ID) + params := GetSourcesRhcConnectionParams{} + + res, err := this.client.GetSourcesRhcConnectionWithResponse(ctx, ID, ¶ms) if err != nil { return nil, err @@ -133,17 +136,29 @@ 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, string(*source.Id)) if err != nil { return SourceConnectionStatus{}, err } - source := (*sourcesResponse)[0] + 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 } 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, diff --git a/internal/api/connectors/sources/sources_test.go b/internal/api/connectors/sources/sources_test.go index e732756b..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: `{"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...)