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

Data Integration Resource #178

Merged
merged 9 commits into from
Apr 18, 2022
51 changes: 51 additions & 0 deletions examples/service/dataintegration/providers/aws/create/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"context"
"github.com/spotinst/spotinst-sdk-go/service/dataintegration"
"github.com/spotinst/spotinst-sdk-go/service/dataintegration/providers/aws"
"github.com/spotinst/spotinst-sdk-go/spotinst"
"github.com/spotinst/spotinst-sdk-go/spotinst/session"
"github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil"
"log"
)

func main() {
// All clients require a Session. The Session provides the client with
// shared configuration such as account and credentials.
// A Session should be shared where possible to take advantage of
// configuration and credential caching. See the session package for
// more information.
sess := session.New()

// Create a new instance of the service's client with a Session.
// Optional spotinst.Config values can also be provided as variadic
// arguments to the New function. This option allows you to provide
// service specific configuration.
svc := dataintegration.New(sess)

// Create a new context.
ctx := context.Background()

// Create a new Data Integration.
out, err := svc.CloudProviderAWS().CreateDataIntegration(ctx, &aws.CreateDataIntegrationInput{
DataIntegration: &aws.DataIntegration{
Name: spotinst.String("my-s3-integration-check"),
Vendor: spotinst.String("s3"),
Config: &aws.Config{
BucketName: spotinst.String("foo"),
SubDir: spotinst.String("foo"),
},
},
})
if err != nil {
log.Fatalf("spotinst: failed to create data integration: %v", err)
}

// Output.
if out.DataIntegration != nil {
log.Printf("Data Integration %q: %s",
spotinst.StringValue(out.DataIntegration.ID),
stringutil.Stringify(out.DataIntegration))
}
}
36 changes: 36 additions & 0 deletions examples/service/dataintegration/providers/aws/delete/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"context"
"github.com/spotinst/spotinst-sdk-go/service/dataintegration"
"github.com/spotinst/spotinst-sdk-go/service/dataintegration/providers/aws"
"github.com/spotinst/spotinst-sdk-go/spotinst"
"github.com/spotinst/spotinst-sdk-go/spotinst/session"
"log"
)

func main() {
// All clients require a Session. The Session provides the client with
// shared configuration such as account and credentials.
// A Session should be shared where possible to take advantage of
// configuration and credential caching. See the session package for
// more information.
sess := session.New()

// Create a new instance of the service's client with a Session.
// Optional spotinst.Config values can also be provided as variadic
// arguments to the New function. This option allows you to provide
// service specific configuration.
svc := dataintegration.New(sess)

// Create a new context.
ctx := context.Background()

// Delete an existing data integration.
_, err := svc.CloudProviderAWS().DeleteDataIntegration(ctx, &aws.DeleteDataIntegrationInput{
DataIntegrationId: spotinst.String("di-12345"),
})
if err != nil {
log.Fatalf("spotinst: failed to delete data integration: %v", err)
}
}
44 changes: 44 additions & 0 deletions examples/service/dataintegration/providers/aws/list/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"context"
"github.com/spotinst/spotinst-sdk-go/service/dataintegration"
"github.com/spotinst/spotinst-sdk-go/service/dataintegration/providers/aws"
"github.com/spotinst/spotinst-sdk-go/spotinst"
"github.com/spotinst/spotinst-sdk-go/spotinst/session"
"github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil"
"log"
)

func main() {
// All clients require a Session. The Session provides the client with
// shared configuration such as account and credentials.
// A Session should be shared where possible to take advantage of
// configuration and credential caching. See the session package for
// more information.
sess := session.New()

// Create a new instance of the service's client with a Session.
// Optional spotinst.Config values can also be provided as variadic
// arguments to the New function. This option allows you to provide
// service specific configuration.
svc := dataintegration.New(sess)

// Create a new context.
ctx := context.Background()

// List all data integrations.
out, err := svc.CloudProviderAWS().ListDataIntegration(ctx, &aws.ListDataIntegrationsInput{})
if err != nil {
log.Fatalf("spotinst: failed to list data integrations: %v", err)
}

// Output all data integrations, if any.
if len(out.DataIntegrations) > 0 {
for _, dataIntegration := range out.DataIntegrations {
log.Printf("Data Integration %q: %s",
spotinst.StringValue(dataIntegration.ID),
stringutil.Stringify(dataIntegration))
}
}
}
44 changes: 44 additions & 0 deletions examples/service/dataintegration/providers/aws/read/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"context"
"github.com/spotinst/spotinst-sdk-go/service/dataintegration"
"github.com/spotinst/spotinst-sdk-go/service/dataintegration/providers/aws"
"github.com/spotinst/spotinst-sdk-go/spotinst"
"github.com/spotinst/spotinst-sdk-go/spotinst/session"
"github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil"
"log"
)

func main() {
// All clients require a Session. The Session provides the client with
// shared configuration such as account and credentials.
// A Session should be shared where possible to take advantage of
// configuration and credential caching. See the session package for
// more information.
sess := session.New()

// Create a new instance of the service's client with a Session.
// Optional spotinst.Config values can also be provided as variadic
// arguments to the New function. This option allows you to provide
// service specific configuration.
svc := dataintegration.New(sess)

// Create a new context.
ctx := context.Background()

// Read data integration configuration.
out, err := svc.CloudProviderAWS().ReadDataIntegration(ctx, &aws.ReadDataIntegrationInput{
DataIntegrationId: spotinst.String("di-12345"),
})
if err != nil {
log.Fatalf("spotinst: failed to read data integration: %v", err)
}

// Output.
if out.DataIntegration != nil {
log.Printf("Data Integration %q: %s",
spotinst.StringValue(out.DataIntegration.ID),
stringutil.Stringify(out.DataIntegration))
}
}
50 changes: 50 additions & 0 deletions examples/service/dataintegration/providers/aws/update/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"context"
"github.com/spotinst/spotinst-sdk-go/service/dataintegration"
"github.com/spotinst/spotinst-sdk-go/service/dataintegration/providers/aws"
"github.com/spotinst/spotinst-sdk-go/spotinst"
"github.com/spotinst/spotinst-sdk-go/spotinst/session"
"github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil"
"log"
)

func main() {
// All clients require a Session. The Session provides the client with
// shared configuration such as account and credentials.
// A Session should be shared where possible to take advantage of
// configuration and credential caching. See the session package for
// more information.
sess := session.New()

// Create a new instance of the service's client with a Session.
// Optional spotinst.Config values can also be provided as variadic
// arguments to the New function. This option allows you to provide
// service specific configuration.
svc := dataintegration.New(sess)

// Create a new context.
ctx := context.Background()

// Update data integration configuration.
out, err := svc.CloudProviderAWS().UpdateDataIntegration(ctx, &aws.UpdateDataIntegrationInput{
DataIntegration: &aws.DataIntegration{
ID: spotinst.String("di-12345"),
Vendor: spotinst.String("s3"),
Config: &aws.Config{
SubDir: spotinst.String("foo"),
},
},
})
if err != nil {
log.Fatalf("spotinst: failed to update data integration: %v", err)
}

// Output.
if out.DataIntegration != nil {
log.Printf("Data Integration %q: %s",
spotinst.StringValue(out.DataIntegration.ID),
stringutil.Stringify(out.DataIntegration))
}
}
37 changes: 37 additions & 0 deletions service/dataintegration/dataintegration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dataintegration

import (
"github.com/spotinst/spotinst-sdk-go/service/dataintegration/providers/aws"
"github.com/spotinst/spotinst-sdk-go/spotinst"
"github.com/spotinst/spotinst-sdk-go/spotinst/client"
"github.com/spotinst/spotinst-sdk-go/spotinst/session"
)

// Service provides the API operation methods for making requests to endpoints
// of the Spotinst API. See this package's package overview docs for details on
// the service.
type Service interface {
CloudProviderAWS() aws.Service
}

type ServiceOp struct {
Client *client.Client
}

var _ Service = &ServiceOp{}

func New(sess *session.Session, cfgs ...*spotinst.Config) *ServiceOp {
cfg := &spotinst.Config{}
cfg.Merge(sess.Config)
cfg.Merge(cfgs...)

return &ServiceOp{
Client: client.New(cfg),
}
}

func (s *ServiceOp) CloudProviderAWS() aws.Service {
return &aws.ServiceOp{
Client: s.Client,
}
}
Loading