Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudQuery Source Plugin? #582

Open
yevgenypats opened this issue Jan 18, 2023 · 1 comment
Open

CloudQuery Source Plugin? #582

yevgenypats opened this issue Jan 18, 2023 · 1 comment

Comments

@yevgenypats
Copy link

Hi Team, hopefully this is right place to ask, if not, I'd appreciate if you can direct me.

I'm the founder of cloudquery.io, a high performance open source ELT framework.

Our users are interested in an Alibaba source plugin, but as we cannot maintain all the plugins ourselves, I was curious if this would be an interesting collaboration, where we would help implement an initial source plugin, and you will help maintain it.

This will give your users the ability to sync Alibaba Cloud data to any of their datalakes/data-warehouses/databases easily using any of the growing list of CQ destination plugins.

The first version is already developed as it was asked by number of users but we are usually looking for the official maintainers to maintain it.

Best,
Yevgeny

@ljluestc
Copy link

package main

import (
    "fmt"
    "cloudquery.io"
    "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
)

// Initialize Alibaba Cloud plugin
func initPlugin(config *cloudquery.Config) error {
    // Set up Alibaba Cloud SDK with credentials
    ecsClient, err := ecs.NewClientWithAccessKey(config.Region, config.AccessKey, config.SecretKey)
    if err != nil {
        return fmt.Errorf("failed to create Alibaba ECS client: %w", err)
    }

    // Set client globally or return it to be used in the fetch function
    cloudquery.SetClient(ecsClient)
    return nil
}

// Fetch data from Alibaba Cloud ECS
func fetchECSData() ([]cloudquery.Record, error) {
    // Use Alibaba Cloud SDK to fetch data, for example, ECS instances
    request := ecs.CreateDescribeInstancesRequest()
    response, err := cloudquery.Client.DescribeInstances(request)
    if err != nil {
        return nil, fmt.Errorf("failed to fetch ECS data: %w", err)
    }

    // Map response data to CloudQuery's format
    var records []cloudquery.Record
    for _, instance := range response.Instances.Instance {
        record := cloudquery.Record{
            // Map ECS data to CloudQuery format
            "instance_id": instance.InstanceId,
            "status":      instance.Status,
        }
        records = append(records, record)
    }
    return records, nil
}

// Main function to connect the plugin to CloudQuery
func main() {
    config := &cloudquery.Config{
        AccessKey: "your-access-key",
        SecretKey: "your-secret-key",
        Region:    "cn-hangzhou",
    }

    if err := initPlugin(config); err != nil {
        fmt.Println("Error initializing plugin:", err)
        return
    }

    records, err := fetchECSData()
    if err != nil {
        fmt.Println("Error fetching data:", err)
        return
    }

    fmt.Println("Fetched data:", records)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants