You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/10/26 12:58:01 UTC

[GitHub] [incubator-seatunnel] skyoct commented on a diff in pull request #3185: [Feature][Connector-V2][GoogleSheets] Support GoogleSheets Source

skyoct commented on code in PR #3185:
URL: https://github.com/apache/incubator-seatunnel/pull/3185#discussion_r1005643770


##########
seatunnel-connectors-v2/connector-google-sheets/src/main/java/org/apache/seatunnel/connectors/seatunnel/google/sheets/source/SheetsSourceReader.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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 org.apache.seatunnel.connectors.seatunnel.google.sheets.source;
+
+import org.apache.seatunnel.api.serialization.DeserializationSchema;
+import org.apache.seatunnel.api.source.Collector;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.common.utils.JsonUtils;
+import org.apache.seatunnel.connectors.seatunnel.common.source.AbstractSingleSplitReader;
+import org.apache.seatunnel.connectors.seatunnel.common.source.SingleSplitReaderContext;
+import org.apache.seatunnel.connectors.seatunnel.google.sheets.config.SheetsParameters;
+
+import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
+import com.google.api.client.http.HttpRequestInitializer;
+import com.google.api.client.http.javanet.NetHttpTransport;
+import com.google.api.client.json.JsonFactory;
+import com.google.api.client.json.gson.GsonFactory;
+import com.google.api.services.sheets.v4.Sheets;
+import com.google.api.services.sheets.v4.SheetsScopes;
+import com.google.api.services.sheets.v4.model.ValueRange;
+import com.google.auth.http.HttpCredentialsAdapter;
+import com.google.auth.oauth2.ServiceAccountCredentials;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Base64;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SheetsSourceReader extends AbstractSingleSplitReader<SeaTunnelRow> {
+
+    private SheetsParameters sheetsParameters;
+
+    private HttpRequestInitializer requestInitializer;
+
+    private static final String APPLICATION_NAME = "SeaTunnel Google Sheets";
+
+    private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
+
+    private final SingleSplitReaderContext context;
+
+    private DeserializationSchema<SeaTunnelRow> deserializationSchema;
+
+    public SheetsSourceReader(SheetsParameters sheetsParameters, SingleSplitReaderContext context, DeserializationSchema<SeaTunnelRow> deserializationSchema) throws IOException {
+        this.sheetsParameters = sheetsParameters;
+        this.context = context;
+        this.deserializationSchema = deserializationSchema;
+    }
+
+    @Override
+    public void open() throws Exception {
+        byte[] keyBytes = Base64.getDecoder().decode(sheetsParameters.getServiceAccountKey());
+        ServiceAccountCredentials sourceCredentials = ServiceAccountCredentials
+            .fromStream(new ByteArrayInputStream(keyBytes));
+        sourceCredentials = (ServiceAccountCredentials) sourceCredentials
+            .createScoped(Collections.singletonList(SheetsScopes.SPREADSHEETS));
+        requestInitializer = new HttpCredentialsAdapter(sourceCredentials);
+
+    }
+
+    @Override
+    public void close() throws IOException {
+

Review Comment:
   The official document does not find that the service needs to be closed.



-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org