Skip to content

Commit

Permalink
track cmd/gcp.go
Browse files Browse the repository at this point in the history
  • Loading branch information
codingkarthik committed Jul 31, 2024
1 parent 359f473 commit 1643bdc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
9 changes: 3 additions & 6 deletions registry-automation/cmd/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ func buildRegistryPayload(
}

func updateRegistryGQL(payload []ConnectorVersion) error {
client := graphql.NewClient("http://localhost:8081/v1/graphql")
var respData map[string]interface{}
client := graphql.NewClient(cmdArgs.ConnectorRegistryGQL)
ctx := context.Background()

req := graphql.NewRequest(`
Expand All @@ -440,12 +441,8 @@ mutation InsertConnectorVersion($connectorVersion: [hub_registry_connector_versi
// add the payload to the request
req.Var("connectorVersion", payload)

// add a new key value to req

var respData map[string]interface{}

req.Header.Set("x-hasura-role", "connector_publishing_automation")
req.Header.Set("x-connector-publication-key", "usnEu*pYp8wiUjbzv3g4iruemTzDgfi@") // TODO: The value of the header should be fetched from the environment variable CONNECTOR_PUBLICATION_KEY
req.Header.Set("x-connector-publication-key", cmdArgs.ConnectorPublicationKey)

// Execute the GraphQL query and check the response.
if err := client.Run(ctx, req, &respData); err != nil {
Expand Down
46 changes: 46 additions & 0 deletions registry-automation/cmd/gcp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Description: This file contains the functions to interact with Google Cloud Storage.
package cmd

import (
"cloud.google.com/go/storage"
"context"
"fmt"
"io"
"os"
)

// deleteFile deletes a file from Google Cloud Storage
func deleteFile(client *storage.Client, bucketName, objectName string) error {
bucket := client.Bucket(bucketName)
object := bucket.Object(objectName)

return object.Delete(context.Background())
}

// uploadFile uploads a file to Google Cloud Storage
// document this function with comments
func uploadFile(client *storage.Client, bucketName, objectName, filePath string) (string, error) {
bucket := client.Bucket(bucketName)
object := bucket.Object(objectName)
newCtx := context.Background()
wc := object.NewWriter(newCtx)

file, err := os.Open(filePath)
if err != nil {
return "", fmt.Errorf("failed to open file: %v", err)
}
defer file.Close()

if _, err := io.Copy(wc, file); err != nil {
return "", fmt.Errorf("failed to upload file: %w", err)
}
if err := wc.Close(); err != nil {
return "", fmt.Errorf("failed to close writer: %w", err)
}

// Return the public URL of the uploaded object.
publicURL := fmt.Sprintf("https://storage.googleapis.com/%s/%s", bucketName, objectName)

fmt.Printf("File %s uploaded to bucket %s as %s and is available at %s.\n", filePath, bucketName, objectName, publicURL)
return publicURL, nil
}

0 comments on commit 1643bdc

Please sign in to comment.