RobertIndie commented on code in PR #2437: URL: https://github.com/apache/streampipes/pull/2437#discussion_r1493775732
########## streampipes-client-go/streampipes/internal/util/streampipes_apiPath.go: ########## Review Comment: The file name should be `streampipes_api_path` ########## streampipes-client-go/streampipes/config/client_connection_config.go: ########## @@ -0,0 +1,45 @@ +// +// 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 config + +import ( + "streampipes-client-go/streampipes/internal/credential" + Path "streampipes-client-go/streampipes/internal/util" Review Comment: ```suggestion util "streampipes-client-go/streampipes/internal/util" ``` ########## streampipes-client-go/streampipes/api/data_stream_api.go: ########## @@ -0,0 +1,36 @@ +// +// 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 api + +import ( + "streampipes-client-go/streampipes/config" + "streampipes-client-go/streampipes/internal/streampipes_http" +) + +type DataStreamApi struct { + config config.StreamPipesClientConnectionConfig + httpRequest streampipes_http.HttpRequest +} Review Comment: It seems that this API doesn't do anything. ########## streampipes-client-go/streampipes/api/data_lake_measure_api.go: ########## @@ -0,0 +1,121 @@ +// +// 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 api + +import ( + "fmt" + "streampipes-client-go/streampipes/config" + "streampipes-client-go/streampipes/internal/serializer" + "streampipes-client-go/streampipes/internal/streampipes_http" + "streampipes-client-go/streampipes/model/data_lake" +) + +/* +DataLakeMeasureApi connects to the DataLakeMeasure endpoint of Streampipes. +DataLakeMeasureApi supports GET, POST, Delete, and PUT methods for obtaining, deleting, submitting, and updating resources. +The specific interaction behavior is provided by the method bound to the DataLakeMeasureApi struct. +Currently, only some GET and Delete methods have been implemented. +*/ +type DataLakeMeasureApi struct { + config config.StreamPipesClientConnectionConfig + httpRequest streampipes_http.HttpRequest +} + +func NewDataLakeMeasureApi(clientConfig config.StreamPipesClientConnectionConfig) *DataLakeMeasureApi { + //NewDataLakeMeasureApi is used to return an instance of *DataLakeMeasureApi, + + return &DataLakeMeasureApi{ + config: clientConfig, + httpRequest: nil, + } +} + +func (d *DataLakeMeasureApi) All() []data_lake.DataLakeMeasure { + //Get a list of all measurement series + //Deserializes the data into the corresponding DataLakeMeasure data model. + + UnSerializer := serializer.NewBaseUnSerializer(serializer.WithUnSerializerDataLakeMeasures()) + d.httpRequest = &streampipes_http.GetRequest{ + HttpRequest: streampipes_http.NewHttpRequest(d.config), + UnSerializer: UnSerializer, + } + d.ResourcePath(nil) + interfaces := d.httpRequest.ExecuteRequest(nil) + UnBaseSerializer := interfaces.(*serializer.UnBaseSerializer) + return *UnBaseSerializer.UnSerializerDataLakeMeasures +} + +func (d *DataLakeMeasureApi) GetSingle(id string) data_lake.DataSeries { + + //Get data from a single measurement series by a given id + + UnSerializer := serializer.NewBaseUnSerializer(serializer.WithUnSerializerDataSeries()) + d.httpRequest = &streampipes_http.GetRequest{ + HttpRequest: streampipes_http.NewHttpRequest(d.config), + UnSerializer: UnSerializer, + } + d.ResourcePath([]string{id}) + interfaces := d.httpRequest.ExecuteRequest(nil) + UnBaseSerializer := interfaces.(*serializer.UnBaseSerializer) + return *UnBaseSerializer.UnSerializerDataLakeSeries +} + +func (d *DataLakeMeasureApi) DeleteMeasurementInternalData(elementId string) string { + //Remove data from a single measurement series with given id + + d.httpRequest = &streampipes_http.DeleteRequest{ + HttpRequest: streampipes_http.NewHttpRequest(d.config), + UnSerializer: nil, + } + d.ResourcePath([]string{elementId}) + interfaces := d.httpRequest.ExecuteRequest(nil) + return interfaces.(string) +} + +func (d *DataLakeMeasureApi) DeleteMeasurementSeries(elementId string) string { + //Drop a single measurement series with given id from Data Lake and remove related event property + + d.httpRequest = &streampipes_http.DeleteRequest{ + HttpRequest: streampipes_http.NewHttpRequest(d.config), + UnSerializer: nil, + } + d.ResourcePath([]string{elementId, "drop"}) + interfaces := d.httpRequest.ExecuteRequest(nil) + return interfaces.(string) +} + +func (d *DataLakeMeasureApi) Create(element data_lake.DataLakeMeasure) error { + + return fmt.Errorf("Not yet implemented") +} + +func (d *DataLakeMeasureApi) Update(measure data_lake.DataLakeMeasure) error { + return fmt.Errorf("Not yet implemented") + +} + +func (d *DataLakeMeasureApi) ResourcePath(parameter []string) { Review Comment: Why do we expose this method to the user? ########## streampipes-client-go/streampipes/config/client_connection_config.go: ########## @@ -0,0 +1,45 @@ +// +// 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 config + +import ( + "streampipes-client-go/streampipes/internal/credential" + Path "streampipes-client-go/streampipes/internal/util" +) + +type ClientConnectionConfigResolver interface { + getBaseUrl() *Path.StreamPipesApiPath Review Comment: ```suggestion GetBaseUrl() *Path.StreamPipesApiPath ``` ########## streampipes-client-go/streampipes/streampipes_client.go: ########## @@ -0,0 +1,80 @@ +// +// 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" + "log" + "net/url" + "regexp" + "streampipes-client-go/streampipes/api" + "streampipes-client-go/streampipes/config" + "streampipes-client-go/streampipes/internal/credential" + "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. `DataLakeMeasureApi` provides the actual methods to interact with StreamPipes API. +*/ + +type StreamPipesClient struct { + Config config.StreamPipesClientConnectionConfig +} + +func NewStreamPipesClient(config config.StreamPipesClientConnectionConfig) (*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 == (credential.StreamPipesApiKeyCredentials{}) { + log.Fatal("No credential entered") + } + + re := regexp.MustCompile(`(?i)^(http|https):\/\/[^\s\/:]+:\d+$`) + ok := re.MatchString(config.Url) + if !ok { + log.Fatal("Please check if the URL is correct,Must be in the form of A://B:C," + + "where A is either HTTP or HTTPS, not case sensitive.B must be the host and C must be the port.") + } Review Comment: Seems `url.Parse` already checks the URL format. ########## streampipes-client-go/streampipes/streampipes_client.go: ########## @@ -0,0 +1,80 @@ +// +// 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" + "log" + "net/url" + "regexp" + "streampipes-client-go/streampipes/api" + "streampipes-client-go/streampipes/config" + "streampipes-client-go/streampipes/internal/credential" + "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. `DataLakeMeasureApi` provides the actual methods to interact with StreamPipes API. +*/ + +type StreamPipesClient struct { + Config config.StreamPipesClientConnectionConfig +} + +func NewStreamPipesClient(config config.StreamPipesClientConnectionConfig) (*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 == (credential.StreamPipesApiKeyCredentials{}) { + log.Fatal("No credential entered") + } + + re := regexp.MustCompile(`(?i)^(http|https):\/\/[^\s\/:]+:\d+$`) + ok := re.MatchString(config.Url) + if !ok { + log.Fatal("Please check if the URL is correct,Must be in the form of A://B:C," + + "where A is either HTTP or HTTPS, 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( + "Invalid configuration passed! The given client configuration has " + + "`https_disabled` set to `True` and `port` set to `443`.\n " + Review Comment: Now there is no t `https_disabled` and `port` configuration. Right? ########## streampipes-client-go/streampipes/internal/util/streampipes_apiPath.go: ########## @@ -0,0 +1,71 @@ +// +// 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 util + +import ( + "strings" +) + +// PathItems stores URL fragments +// QueryParameters stores query parameters Review Comment: Please move these comments to their corresponding fields. ########## streampipes-client-go/streampipes/api/data_lake_measure_api.go: ########## @@ -0,0 +1,121 @@ +// +// 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 api + +import ( + "fmt" + "streampipes-client-go/streampipes/config" + "streampipes-client-go/streampipes/internal/serializer" + "streampipes-client-go/streampipes/internal/streampipes_http" + "streampipes-client-go/streampipes/model/data_lake" +) + +/* +DataLakeMeasureApi connects to the DataLakeMeasure endpoint of Streampipes. +DataLakeMeasureApi supports GET, POST, Delete, and PUT methods for obtaining, deleting, submitting, and updating resources. +The specific interaction behavior is provided by the method bound to the DataLakeMeasureApi struct. +Currently, only some GET and Delete methods have been implemented. +*/ +type DataLakeMeasureApi struct { + config config.StreamPipesClientConnectionConfig + httpRequest streampipes_http.HttpRequest +} + +func NewDataLakeMeasureApi(clientConfig config.StreamPipesClientConnectionConfig) *DataLakeMeasureApi { + //NewDataLakeMeasureApi is used to return an instance of *DataLakeMeasureApi, + + return &DataLakeMeasureApi{ + config: clientConfig, + httpRequest: nil, + } +} + +func (d *DataLakeMeasureApi) All() []data_lake.DataLakeMeasure { + //Get a list of all measurement series + //Deserializes the data into the corresponding DataLakeMeasure data model. + + UnSerializer := serializer.NewBaseUnSerializer(serializer.WithUnSerializerDataLakeMeasures()) Review Comment: What's the meaning of `UnSerializer`? Do you mean Deserializer? ########## streampipes-client-go/streampipes/api/data_lake_measure_api.go: ########## @@ -0,0 +1,121 @@ +// +// 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 api + +import ( + "fmt" + "streampipes-client-go/streampipes/config" + "streampipes-client-go/streampipes/internal/serializer" + "streampipes-client-go/streampipes/internal/streampipes_http" + "streampipes-client-go/streampipes/model/data_lake" +) + +/* +DataLakeMeasureApi connects to the DataLakeMeasure endpoint of Streampipes. +DataLakeMeasureApi supports GET, POST, Delete, and PUT methods for obtaining, deleting, submitting, and updating resources. +The specific interaction behavior is provided by the method bound to the DataLakeMeasureApi struct. +Currently, only some GET and Delete methods have been implemented. +*/ +type DataLakeMeasureApi struct { + config config.StreamPipesClientConnectionConfig + httpRequest streampipes_http.HttpRequest Review Comment: Why do we need to store the httpRequest in the struct? Seems like it's only used when querying the API. ########## streampipes-client-go/streampipes/api/data_lake_measure_api.go: ########## @@ -0,0 +1,121 @@ +// +// 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 api + +import ( + "fmt" + "streampipes-client-go/streampipes/config" + "streampipes-client-go/streampipes/internal/serializer" + "streampipes-client-go/streampipes/internal/streampipes_http" + "streampipes-client-go/streampipes/model/data_lake" +) + +/* +DataLakeMeasureApi connects to the DataLakeMeasure endpoint of Streampipes. +DataLakeMeasureApi supports GET, POST, Delete, and PUT methods for obtaining, deleting, submitting, and updating resources. +The specific interaction behavior is provided by the method bound to the DataLakeMeasureApi struct. +Currently, only some GET and Delete methods have been implemented. +*/ +type DataLakeMeasureApi struct { Review Comment: ```suggestion type DataLakeMeasure struct { ``` Perhaps we don't need to include 'API' in the struct names. ########## streampipes-client-go/streampipes/api/data_lake_measure_api.go: ########## @@ -0,0 +1,121 @@ +// +// 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 api + +import ( + "fmt" + "streampipes-client-go/streampipes/config" + "streampipes-client-go/streampipes/internal/serializer" + "streampipes-client-go/streampipes/internal/streampipes_http" + "streampipes-client-go/streampipes/model/data_lake" +) + +/* +DataLakeMeasureApi connects to the DataLakeMeasure endpoint of Streampipes. +DataLakeMeasureApi supports GET, POST, Delete, and PUT methods for obtaining, deleting, submitting, and updating resources. +The specific interaction behavior is provided by the method bound to the DataLakeMeasureApi struct. +Currently, only some GET and Delete methods have been implemented. +*/ +type DataLakeMeasureApi struct { + config config.StreamPipesClientConnectionConfig + httpRequest streampipes_http.HttpRequest +} + +func NewDataLakeMeasureApi(clientConfig config.StreamPipesClientConnectionConfig) *DataLakeMeasureApi { + //NewDataLakeMeasureApi is used to return an instance of *DataLakeMeasureApi, + + return &DataLakeMeasureApi{ + config: clientConfig, + httpRequest: nil, + } +} + +func (d *DataLakeMeasureApi) All() []data_lake.DataLakeMeasure { + //Get a list of all measurement series + //Deserializes the data into the corresponding DataLakeMeasure data model. + + UnSerializer := serializer.NewBaseUnSerializer(serializer.WithUnSerializerDataLakeMeasures()) + d.httpRequest = &streampipes_http.GetRequest{ + HttpRequest: streampipes_http.NewHttpRequest(d.config), + UnSerializer: UnSerializer, + } + d.ResourcePath(nil) + interfaces := d.httpRequest.ExecuteRequest(nil) + UnBaseSerializer := interfaces.(*serializer.UnBaseSerializer) + return *UnBaseSerializer.UnSerializerDataLakeMeasures +} + +func (d *DataLakeMeasureApi) GetSingle(id string) data_lake.DataSeries { + + //Get data from a single measurement series by a given id + + UnSerializer := serializer.NewBaseUnSerializer(serializer.WithUnSerializerDataSeries()) + d.httpRequest = &streampipes_http.GetRequest{ + HttpRequest: streampipes_http.NewHttpRequest(d.config), + UnSerializer: UnSerializer, + } + d.ResourcePath([]string{id}) + interfaces := d.httpRequest.ExecuteRequest(nil) + UnBaseSerializer := interfaces.(*serializer.UnBaseSerializer) + return *UnBaseSerializer.UnSerializerDataLakeSeries +} + +func (d *DataLakeMeasureApi) DeleteMeasurementInternalData(elementId string) string { + //Remove data from a single measurement series with given id + + d.httpRequest = &streampipes_http.DeleteRequest{ + HttpRequest: streampipes_http.NewHttpRequest(d.config), + UnSerializer: nil, + } + d.ResourcePath([]string{elementId}) + interfaces := d.httpRequest.ExecuteRequest(nil) + return interfaces.(string) +} + +func (d *DataLakeMeasureApi) DeleteMeasurementSeries(elementId string) string { + //Drop a single measurement series with given id from Data Lake and remove related event property + + d.httpRequest = &streampipes_http.DeleteRequest{ + HttpRequest: streampipes_http.NewHttpRequest(d.config), + UnSerializer: nil, + } + d.ResourcePath([]string{elementId, "drop"}) + interfaces := d.httpRequest.ExecuteRequest(nil) + return interfaces.(string) +} + +func (d *DataLakeMeasureApi) Create(element data_lake.DataLakeMeasure) error { + + return fmt.Errorf("Not yet implemented") +} + +func (d *DataLakeMeasureApi) Update(measure data_lake.DataLakeMeasure) error { + return fmt.Errorf("Not yet implemented") + +} Review Comment: We don't need to provide these unimplemented methods to the user. You could create an issue to track it. But we don't need to track it in the code. -- 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]
