RobertIndie commented on code in PR #2437: URL: https://github.com/apache/streampipes/pull/2437#discussion_r1530622969
########## streampipes-client-go/streampipes/streampipes_client.go: ########## @@ -0,0 +1,73 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package streampipes + +import ( + "errors" + "github.com/apache/streampipes/streampipes-client-go/streampipes/config" + "github.com/apache/streampipes/streampipes-client-go/streampipes/utils" + "log" + "net/url" + "strings" +) + +/* + This is the central point of contact with StreamPipes and provides all the functionalities to interact with it. + The client provides so-called "API", each of which refers to the endpoint of the StreamPipes API. + e.g. `DataLakeMeasure` provides the actual methods to interact with StreamPipes API. +*/ + +type StreamPipesClient struct { + Config config.StreamPipesClientConfig +} + +func NewStreamPipesClient(Config config.StreamPipesClientConfig) (*StreamPipesClient, error) { + + //NewStreamPipesClient returns an instance of * StreamPipesClient + //Temporarily does not support HTTPS connections, nor does it support connecting to port 443 Review Comment: ```suggestion // Currently, it does not support HTTPS connections or connections to port 443. ``` ########## streampipes-client-go/streampipes/endpoint.go: ########## @@ -0,0 +1,72 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package streampipes + +import ( + "errors" + "github.com/apache/streampipes/streampipes-client-go/streampipes/config" + headers "github.com/apache/streampipes/streampipes-client-go/streampipes/internal/http_headers" + "net/http" +) + +type endpoint struct { + config config.StreamPipesClientConfig +} + +func (e *endpoint) makeHeaderAndHttpClient(method string, endPointUrl string) (*http.Response, error) { Review Comment: The name of the method doesn't reflect the actual method behavior. It actually executes the request and returns the response, rather than making the header and client. ########## streampipes-client-go/streampipes/streampipes_client.go: ########## @@ -0,0 +1,73 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package streampipes + +import ( + "errors" + "github.com/apache/streampipes/streampipes-client-go/streampipes/config" + "github.com/apache/streampipes/streampipes-client-go/streampipes/utils" + "log" + "net/url" + "strings" +) + +/* + This is the central point of contact with StreamPipes and provides all the functionalities to interact with it. + The client provides so-called "API", each of which refers to the endpoint of the StreamPipes API. + e.g. `DataLakeMeasure` provides the actual methods to interact with StreamPipes API. +*/ + +type StreamPipesClient struct { + Config config.StreamPipesClientConfig +} + +func NewStreamPipesClient(Config config.StreamPipesClientConfig) (*StreamPipesClient, error) { + + //NewStreamPipesClient returns an instance of * StreamPipesClient + //Temporarily does not support HTTPS connections, nor does it support connecting to port 443 + + if Config.Credential == (config.StreamPipesApiKeyCredentials{}) { + log.Fatal("No credential entered") + } + + if !utils.CheckUrl(Config.Url) { + log.Fatal("Please check if the URL is correct,Must be in the form of A://B:C," + + "where A is either HTTP, not case sensitive.B must be the host and C must be the port.") + } + + Url, err := url.Parse(Config.Url) + if err != nil { + log.Fatal("Please enter the correct URL", err) + } + + if strings.EqualFold(Url.Scheme, "https") || Url.Port() == "443" { + return &StreamPipesClient{}, errors.New( Review Comment: ```suggestion return nil, errors.New( ``` ########## streampipes-client-go/streampipes/streampipes_client.go: ########## @@ -0,0 +1,73 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package streampipes + +import ( + "errors" + "github.com/apache/streampipes/streampipes-client-go/streampipes/config" + "github.com/apache/streampipes/streampipes-client-go/streampipes/utils" + "log" + "net/url" + "strings" +) + +/* + This is the central point of contact with StreamPipes and provides all the functionalities to interact with it. + The client provides so-called "API", each of which refers to the endpoint of the StreamPipes API. + e.g. `DataLakeMeasure` provides the actual methods to interact with StreamPipes API. +*/ + +type StreamPipesClient struct { + Config config.StreamPipesClientConfig Review Comment: ```suggestion config config.StreamPipesClientConfig ``` ########## streampipes-client-go/streampipes/data_lake_measure_api.go: ########## @@ -0,0 +1,194 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package streampipes + +import ( + "errors" + "github.com/apache/streampipes/streampipes-client-go/streampipes/config" + "github.com/apache/streampipes/streampipes-client-go/streampipes/internal/serializer" + "github.com/apache/streampipes/streampipes-client-go/streampipes/internal/util" + "github.com/apache/streampipes/streampipes-client-go/streampipes/model/data_lake" + "io" + "log" + "net/http" +) + +/* + DataLakeMeasure connects to the DataLakeMeasure endpoint of streamPipes. + DataLakeMeasure supports GET and DELETE to delete or obtain resources + The specific interaction behavior is provided by the method bound to the DataLakeMeasure struct. +*/ + +type DataLakeMeasure struct { + endpoint +} + +func NewDataLakeMeasures(clientConfig config.StreamPipesClientConfig) *DataLakeMeasure { + // NewDataLakeMeasure is used to return an instance of *DataLakeMeasure, + + return &DataLakeMeasure{ + endpoint{config: clientConfig}, + } +} + +func (d *DataLakeMeasure) AllDataLakeMeasure() ([]data_lake.DataLakeMeasure, error) { + // Get a list of all measure + + endPointUrl := util.NewStreamPipesApiPath([]string{d.config.Url}).FromStreamPipesBasePath().AddToPath([]string{"api", "v4", "datalake", "measurements"}).String() + log.Println(endPointUrl) Review Comment: We need to enhance the detail of this log message. ########## streampipes-client-go/streampipes/streampipes_client.go: ########## @@ -0,0 +1,73 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package streampipes + +import ( + "errors" + "github.com/apache/streampipes/streampipes-client-go/streampipes/config" + "github.com/apache/streampipes/streampipes-client-go/streampipes/utils" + "log" + "net/url" + "strings" +) + +/* + This is the central point of contact with StreamPipes and provides all the functionalities to interact with it. + The client provides so-called "API", each of which refers to the endpoint of the StreamPipes API. + e.g. `DataLakeMeasure` provides the actual methods to interact with StreamPipes API. +*/ + +type StreamPipesClient struct { + Config config.StreamPipesClientConfig +} + +func NewStreamPipesClient(Config config.StreamPipesClientConfig) (*StreamPipesClient, error) { + + //NewStreamPipesClient returns an instance of * StreamPipesClient + //Temporarily does not support HTTPS connections, nor does it support connecting to port 443 + + if Config.Credential == (config.StreamPipesApiKeyCredentials{}) { + log.Fatal("No credential entered") Review Comment: We should return the error. ########## streampipes-client-go/streampipes/endpoint.go: ########## @@ -0,0 +1,72 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package streampipes + +import ( + "errors" + "github.com/apache/streampipes/streampipes-client-go/streampipes/config" + headers "github.com/apache/streampipes/streampipes-client-go/streampipes/internal/http_headers" + "net/http" +) + +type endpoint struct { + config config.StreamPipesClientConfig +} + +func (e *endpoint) makeHeaderAndHttpClient(method string, endPointUrl string) (*http.Response, error) { + req, err := http.NewRequest(method, endPointUrl, nil) + if err != nil { + return nil, err + } + + header := headers.NewHeaders(req) + header.SetApiUserAndApiKey(e.config.Credential.UserName, e.config.Credential.ApiKey) + header.SetAcceptJson() + header.SetContentTypeJson() + + client := &http.Client{} + response, err := client.Do(header.GetReq()) + if err != nil { + return nil, err + } + return response, nil +} + +func (e *endpoint) handleErrorCode(resp *http.Response) error { + + switch resp.StatusCode { + case http.StatusUnauthorized: + return errors.New("The streamPipes Backend returned an unauthorized error.\nplease check your ApiUser and/or Apikey to be correct.") + case http.StatusForbidden: + return errors.New("There seems to be an issue with the access rights of the given user and the resource you queried.\n" + + "Apparently, this user is not allowed to query the resource.\n" + + "Please check the user's permissions or contact your StreamPipes admin.") + case http.StatusNotFound: + return errors.New("There seems to be an issue with the Python Client calling the API inappropriately.\n" + Review Comment: ```suggestion return errors.New("There seems to be an issue with the Go Client calling the API inappropriately.\n" + ``` ########## streampipes-client-go/streampipes/data_lake_measure_api.go: ########## @@ -0,0 +1,194 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package streampipes + +import ( + "errors" + "github.com/apache/streampipes/streampipes-client-go/streampipes/config" + "github.com/apache/streampipes/streampipes-client-go/streampipes/internal/serializer" + "github.com/apache/streampipes/streampipes-client-go/streampipes/internal/util" + "github.com/apache/streampipes/streampipes-client-go/streampipes/model/data_lake" + "io" + "log" + "net/http" +) + +/* + DataLakeMeasure connects to the DataLakeMeasure endpoint of streamPipes. + DataLakeMeasure supports GET and DELETE to delete or obtain resources + The specific interaction behavior is provided by the method bound to the DataLakeMeasure struct. +*/ + +type DataLakeMeasure struct { + endpoint +} + +func NewDataLakeMeasures(clientConfig config.StreamPipesClientConfig) *DataLakeMeasure { + // NewDataLakeMeasure is used to return an instance of *DataLakeMeasure, + + return &DataLakeMeasure{ + endpoint{config: clientConfig}, + } +} + +func (d *DataLakeMeasure) AllDataLakeMeasure() ([]data_lake.DataLakeMeasure, error) { + // Get a list of all measure + + endPointUrl := util.NewStreamPipesApiPath([]string{d.config.Url}).FromStreamPipesBasePath().AddToPath([]string{"api", "v4", "datalake", "measurements"}).String() Review Comment: The design of this API appears overly complex. We might consider simplifying it as follows: ``` util.NewStreamPipesApiPath(d.config.Url, "api/v4/datalake/measurements"). ``` ########## streampipes-client-go/streampipes/data_lake_measure_api.go: ########## @@ -0,0 +1,194 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package streampipes + +import ( + "errors" + "github.com/apache/streampipes/streampipes-client-go/streampipes/config" + "github.com/apache/streampipes/streampipes-client-go/streampipes/internal/serializer" + "github.com/apache/streampipes/streampipes-client-go/streampipes/internal/util" + "github.com/apache/streampipes/streampipes-client-go/streampipes/model/data_lake" + "io" + "log" + "net/http" +) + +/* + DataLakeMeasure connects to the DataLakeMeasure endpoint of streamPipes. + DataLakeMeasure supports GET and DELETE to delete or obtain resources + The specific interaction behavior is provided by the method bound to the DataLakeMeasure struct. +*/ + +type DataLakeMeasure struct { + endpoint +} + +func NewDataLakeMeasures(clientConfig config.StreamPipesClientConfig) *DataLakeMeasure { + // NewDataLakeMeasure is used to return an instance of *DataLakeMeasure, + + return &DataLakeMeasure{ + endpoint{config: clientConfig}, + } +} + +func (d *DataLakeMeasure) AllDataLakeMeasure() ([]data_lake.DataLakeMeasure, error) { + // Get a list of all measure + + endPointUrl := util.NewStreamPipesApiPath([]string{d.config.Url}).FromStreamPipesBasePath().AddToPath([]string{"api", "v4", "datalake", "measurements"}).String() + log.Println(endPointUrl) + response, err := d.makeHeaderAndHttpClient("GET", endPointUrl) + if err != nil { + return nil, err + } + + if response.StatusCode == http.StatusOK { + body, err := io.ReadAll(response.Body) + if err != nil { + return nil, err + } + unmarshalData, err := serializer.NewUnmarshalDataLakeMeasures().GetUnmarshal(body) + if err != nil { + return nil, err + } + dataLakeMeasures := unmarshalData.([]data_lake.DataLakeMeasure) + return dataLakeMeasures, nil + } else { + err = d.handleStatusCode(response, "") + if err != nil { + return nil, err + } + } + return nil, nil +} + +func (d *DataLakeMeasure) GetSingleDataLakeMeasure(elementId string) (data_lake.DataLakeMeasure, error) { + // Get a measure + + endPointUrl := util.NewStreamPipesApiPath([]string{d.config.Url}).FromStreamPipesBasePath().AddToPath([]string{"api", "v4", "datalake", "measure", elementId}).String() + log.Println(endPointUrl) + response, err := d.makeHeaderAndHttpClient("GET", endPointUrl) + if err != nil { + return data_lake.DataLakeMeasure{}, err + } + + if response.StatusCode == http.StatusOK { + body, err := io.ReadAll(response.Body) + if err != nil { + return data_lake.DataLakeMeasure{}, err + } + unmarshalData, err := serializer.NewUnmarshalDataLakeMeasure().GetUnmarshal(body) + if err != nil { + return data_lake.DataLakeMeasure{}, err + } + dataLakeMeasure := unmarshalData.(data_lake.DataLakeMeasure) + return dataLakeMeasure, nil + } else { + err := d.handleStatusCode(response, "") + if err != nil { + return data_lake.DataLakeMeasure{}, err + } + } + return data_lake.DataLakeMeasure{}, nil +} + +func (d *DataLakeMeasure) GetSingleDataSeries(measureName string) (*data_lake.DataSeries, error) { + + // Get data from a single measurement series by a given id + // Currently not supporting parameter queries + + endPointUrl := util.NewStreamPipesApiPath([]string{d.config.Url}).FromStreamPipesBasePath().AddToPath([]string{"api", "v4", "datalake", "measurements", measureName}).String() + log.Println(endPointUrl) + response, err := d.makeHeaderAndHttpClient("GET", endPointUrl) + if err != nil { + return nil, err + } + + if response.StatusCode == http.StatusOK { + body, err := io.ReadAll(response.Body) + if err != nil { + return nil, err + } + unmarshalData, err := serializer.NewUnmarshalDataSeries().GetUnmarshal(body) + if err != nil { + return nil, err + } + dataSeries := unmarshalData.(data_lake.DataSeries) + return &dataSeries, nil + } else { + err := d.handleStatusCode(response, "Measurement series with given id and requested query specification not found") + if err != nil { + return nil, err + } + } + return nil, nil +} + +func (d *DataLakeMeasure) ClearDataLakeMeasureData(measureName string) error { + // Remove data from a single measurement series with given id + + endPointUrl := util.NewStreamPipesApiPath([]string{d.config.Url}).FromStreamPipesBasePath().AddToPath([]string{"api", "v4", "datalake", "measurements", measureName}).String() + log.Println(endPointUrl) + response, err := d.makeHeaderAndHttpClient("DELETE", endPointUrl) + if err != nil { + return err + } + if response.StatusCode == http.StatusOK { + log.Printf("Successfully deleted data from a single measurement sequence of %s", measureName) + return nil + } else { + err = d.handleStatusCode(response, "Measurement series with given id not found") + if err != nil { + return err + } + } + return nil +} + +func (d *DataLakeMeasure) DeleteDataLakeMeasure(measureName string) error { + // Drop a single measurement series with given id from Data Lake and remove related event property + + endPointUrl := util.NewStreamPipesApiPath([]string{d.config.Url}).FromStreamPipesBasePath().AddToPath([]string{"api", "v4", "datalake", "measurements", measureName, "drop"}).String() + response, err := d.makeHeaderAndHttpClient("DELETE", endPointUrl) + if err != nil { + return err + } + if response.StatusCode == http.StatusOK { + log.Printf("Successfully dropped a single measurement series for %s from DataLake and remove related event property", measureName) + return nil + } else { + err = d.handleStatusCode(response, "Measurement series with given id or related event property not found") + if err != nil { + return err + } + } + return nil +} + +func (d *DataLakeMeasure) handleStatusCode(resp *http.Response, message string) error { + err := d.handleErrorCode(resp) + if err != nil { + return err + } else { + switch resp.StatusCode { + case http.StatusBadRequest: + return errors.New(message) + default: + return errors.New(resp.Status) + } + } +} Review Comment: This could be abstracted to the `endpoint` struct, right? ########## streampipes-client-go/streampipes/data_lake_measure_api.go: ########## @@ -0,0 +1,194 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package streampipes + +import ( + "errors" + "github.com/apache/streampipes/streampipes-client-go/streampipes/config" + "github.com/apache/streampipes/streampipes-client-go/streampipes/internal/serializer" + "github.com/apache/streampipes/streampipes-client-go/streampipes/internal/util" + "github.com/apache/streampipes/streampipes-client-go/streampipes/model/data_lake" + "io" + "log" + "net/http" +) + +/* + DataLakeMeasure connects to the DataLakeMeasure endpoint of streamPipes. + DataLakeMeasure supports GET and DELETE to delete or obtain resources + The specific interaction behavior is provided by the method bound to the DataLakeMeasure struct. +*/ + +type DataLakeMeasure struct { + endpoint +} + +func NewDataLakeMeasures(clientConfig config.StreamPipesClientConfig) *DataLakeMeasure { + // NewDataLakeMeasure is used to return an instance of *DataLakeMeasure, + + return &DataLakeMeasure{ + endpoint{config: clientConfig}, + } +} + +func (d *DataLakeMeasure) AllDataLakeMeasure() ([]data_lake.DataLakeMeasure, error) { + // Get a list of all measure + + endPointUrl := util.NewStreamPipesApiPath([]string{d.config.Url}).FromStreamPipesBasePath().AddToPath([]string{"api", "v4", "datalake", "measurements"}).String() + log.Println(endPointUrl) + response, err := d.makeHeaderAndHttpClient("GET", endPointUrl) + if err != nil { + return nil, err + } + + if response.StatusCode == http.StatusOK { + body, err := io.ReadAll(response.Body) + if err != nil { + return nil, err + } + unmarshalData, err := serializer.NewUnmarshalDataLakeMeasures().GetUnmarshal(body) + if err != nil { + return nil, err + } + dataLakeMeasures := unmarshalData.([]data_lake.DataLakeMeasure) + return dataLakeMeasures, nil + } else { + err = d.handleStatusCode(response, "") + if err != nil { + return nil, err + } + } Review Comment: ```suggestion if response.StatusCode != http.StatusOK { err = d.handleStatusCode(response, "") if err != nil { return nil, err } } body, err := io.ReadAll(response.Body) if err != nil { return nil, err } unmarshalData, err := serializer.NewUnmarshalDataLakeMeasures().GetUnmarshal(body) if err != nil { return nil, err } dataLakeMeasures := unmarshalData.([]data_lake.DataLakeMeasure) return dataLakeMeasures, nil ``` ########## streampipes-client-go/streampipes/endpoint.go: ########## @@ -0,0 +1,72 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package streampipes + +import ( + "errors" + "github.com/apache/streampipes/streampipes-client-go/streampipes/config" + headers "github.com/apache/streampipes/streampipes-client-go/streampipes/internal/http_headers" + "net/http" +) + +type endpoint struct { + config config.StreamPipesClientConfig +} + +func (e *endpoint) makeHeaderAndHttpClient(method string, endPointUrl string) (*http.Response, error) { + req, err := http.NewRequest(method, endPointUrl, nil) + if err != nil { + return nil, err + } + + header := headers.NewHeaders(req) + header.SetApiUserAndApiKey(e.config.Credential.UserName, e.config.Credential.ApiKey) + header.SetAcceptJson() + header.SetContentTypeJson() + + client := &http.Client{} + response, err := client.Do(header.GetReq()) + if err != nil { + return nil, err + } + return response, nil +} + +func (e *endpoint) handleErrorCode(resp *http.Response) error { + + switch resp.StatusCode { + case http.StatusUnauthorized: + return errors.New("The streamPipes Backend returned an unauthorized error.\nplease check your ApiUser and/or Apikey to be correct.") + case http.StatusForbidden: + return errors.New("There seems to be an issue with the access rights of the given user and the resource you queried.\n" + + "Apparently, this user is not allowed to query the resource.\n" + + "Please check the user's permissions or contact your StreamPipes admin.") + case http.StatusNotFound: + return errors.New("There seems to be an issue with the Python Client calling the API inappropriately.\n" + + "This should not happen, but unfortunately did.\n" + + "If you don't mind, it would be awesome to let us know by creating an issue at https://github.com/apache/streampipes.\n") + case http.StatusMethodNotAllowed: + return errors.New("There seems to be an issue with the Python Client calling the API inappropriately.\n" + Review Comment: ```suggestion return errors.New("There seems to be an issue with the Go Client calling the API inappropriately.\n" + ``` ########## streampipes-client-go/streampipes/streampipes_client.go: ########## @@ -0,0 +1,73 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package streampipes + +import ( + "errors" + "github.com/apache/streampipes/streampipes-client-go/streampipes/config" + "github.com/apache/streampipes/streampipes-client-go/streampipes/utils" + "log" + "net/url" + "strings" +) + +/* + This is the central point of contact with StreamPipes and provides all the functionalities to interact with it. + The client provides so-called "API", each of which refers to the endpoint of the StreamPipes API. + e.g. `DataLakeMeasure` provides the actual methods to interact with StreamPipes API. +*/ + +type StreamPipesClient struct { + Config config.StreamPipesClientConfig +} + +func NewStreamPipesClient(Config config.StreamPipesClientConfig) (*StreamPipesClient, error) { + + //NewStreamPipesClient returns an instance of * StreamPipesClient Review Comment: ```suggestion //NewStreamPipesClient returns an instance of *StreamPipesClient ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
