-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Upgrade to SDK v4 * Update goreleaser variable ref * update README * linter: disable depguard * use internalPlugin, revert goreleaser variable ref * update golangci-lint version * .github test: install cloudquery before make gen * more .gitignore --------- Co-authored-by: Kemal Hadimli <[email protected]>
- Loading branch information
Showing
194 changed files
with
2,402 additions
and
1,865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,7 @@ dist/ | |
vendor/ | ||
bin/ | ||
cq-source-scaleway | ||
cloudquery | ||
cloudquery.log | ||
.DS_Store | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,6 @@ linters: | |
enable: | ||
- asciicheck | ||
- bodyclose | ||
- depguard | ||
- dupl | ||
- errcheck | ||
- gocritic | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
.PHONY: build | ||
build: | ||
go build | ||
|
||
.PHONY: test | ||
test: | ||
go test -timeout 3m ./... | ||
go test -race -timeout 3m ./... | ||
|
||
.PHONY: gen-docs | ||
gen-docs: build | ||
@command -v cloudquery >/dev/null 2>&1 || { \ | ||
echo "Error: 'cloudquery' command not found. Please install it before running gen-docs."; \ | ||
echo "You can install it by following the instructions at: https://www.cloudquery.io/docs/quickstart"; \ | ||
exit 1; \ | ||
} | ||
rm -rf docs/tables | ||
cloudquery tables --format markdown --output-dir docs/ test/config.yml | ||
mv -vf docs/scaleway docs/tables | ||
|
||
.PHONY: lint | ||
lint: | ||
@golangci-lint run --timeout 10m --verbose | ||
|
||
.PHONY: gen-docs | ||
gen-docs: | ||
rm -rf ./docs/tables/* | ||
go run main.go doc ./docs/tables | ||
|
||
# All gen targets | ||
.PHONY: gen | ||
gen: gen-docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,58 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/cloudquery/plugin-sdk/backend" | ||
"github.com/cloudquery/plugin-sdk/plugins/source" | ||
"github.com/cloudquery/plugin-sdk/schema" | ||
"github.com/cloudquery/plugin-sdk/specs" | ||
"github.com/cloudquery/plugin-sdk/v4/state" | ||
"github.com/rs/zerolog" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
) | ||
|
||
type Client struct { | ||
Logger zerolog.Logger | ||
Spec Spec | ||
SCWClient *scw.Client | ||
Backend backend.Backend | ||
OrgID string | ||
Region scw.Region | ||
Zone scw.Zone | ||
Backend state.Client | ||
|
||
OrgID string | ||
Region scw.Region | ||
Zone scw.Zone | ||
} | ||
|
||
Spec Spec | ||
sourceSpec specs.Source | ||
func New(logger zerolog.Logger, spec Spec, orgID string, services *scw.Client, bk state.Client) *Client { | ||
return &Client{ | ||
Logger: logger, | ||
Spec: spec, | ||
OrgID: orgID, | ||
SCWClient: services, | ||
Backend: bk, | ||
} | ||
} | ||
|
||
func (c *Client) ID() string { | ||
return c.sourceSpec.Name + ":" + string(c.Region) + ":" + string(c.Zone) | ||
return "scaleway:" + string(c.Region) + ":" + string(c.Zone) | ||
} | ||
|
||
func (c *Client) WithRegion(r scw.Region) *Client { | ||
return &Client{ | ||
Logger: c.Logger.With().Str("region", string(r)).Logger(), | ||
SCWClient: c.SCWClient, | ||
Backend: c.Backend, | ||
OrgID: c.OrgID, | ||
Region: r, | ||
Zone: c.Zone, | ||
Spec: c.Spec, | ||
sourceSpec: c.sourceSpec, | ||
Logger: c.Logger.With().Str("region", string(r)).Logger(), | ||
Spec: c.Spec, | ||
SCWClient: c.SCWClient, | ||
Backend: c.Backend, | ||
|
||
OrgID: c.OrgID, | ||
Region: r, | ||
Zone: c.Zone, | ||
} | ||
} | ||
|
||
func (c *Client) WithZone(z scw.Zone) *Client { | ||
return &Client{ | ||
Logger: c.Logger.With().Str("zone", string(z)).Logger(), | ||
SCWClient: c.SCWClient, | ||
Backend: c.Backend, | ||
OrgID: c.OrgID, | ||
Region: c.Region, | ||
Zone: z, | ||
Spec: c.Spec, | ||
sourceSpec: c.sourceSpec, | ||
} | ||
} | ||
Logger: c.Logger.With().Str("zone", string(z)).Logger(), | ||
Spec: c.Spec, | ||
SCWClient: c.SCWClient, | ||
Backend: c.Backend, | ||
|
||
func New(_ context.Context, logger zerolog.Logger, s specs.Source, opts source.Options) (schema.ClientMeta, error) { | ||
var pluginSpec Spec | ||
if err := s.UnmarshalSpec(&pluginSpec); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal plugin spec: %w", err) | ||
} | ||
err := pluginSpec.Validate() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to validate plugin spec: %w", err) | ||
OrgID: c.OrgID, | ||
Region: c.Region, | ||
Zone: z, | ||
} | ||
pluginSpec.SetDefaults() | ||
|
||
scwOpts := []scw.ClientOption{ | ||
scw.WithEnv(), // existing env variables may overwrite active profile | ||
|
||
scw.WithHTTPClient(&http.Client{ | ||
Timeout: time.Duration(pluginSpec.Timeout) * time.Second, | ||
}), | ||
scw.WithUserAgent("cq-plugin-scaleway/" + s.Version), | ||
} | ||
|
||
cf, err := scw.LoadConfig() | ||
if err != nil { | ||
var configNotFoundError *scw.ConfigFileNotFoundError | ||
if !errors.As(err, &configNotFoundError) { | ||
return nil, err | ||
} | ||
} | ||
if cf != nil { | ||
p, err := cf.GetActiveProfile() | ||
if err != nil { | ||
return nil, err | ||
} | ||
scwOpts = append([]scw.ClientOption{ | ||
scw.WithProfile(p), // active profile applies first | ||
}, scwOpts...) | ||
} | ||
|
||
// Create a Scaleway client | ||
scwClient, err := scw.NewClient(scwOpts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
orgID, ok := scwClient.GetDefaultOrganizationID() | ||
if !ok { | ||
return nil, fmt.Errorf("SCW_DEFAULT_ORGANIZATION_ID or default_organization_id not set, get yours from https://console.scaleway.com/organization/settings") | ||
} | ||
|
||
return &Client{ | ||
Logger: logger, | ||
Backend: opts.Backend, | ||
OrgID: orgID, | ||
Spec: pluginSpec, | ||
SCWClient: scwClient, | ||
sourceSpec: s, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.