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

Added PR workflow & addressed Format / Linter issues. #30

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/pr-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: PR Workflow
on:
pull_request:
types: [ synchronize, opened, reopened]
branches: [ 'main' ]

jobs:
linter:
name: Linter
runs-on: ubuntu-latest
timeout-minutes: 10 # Sets a timeout of 10 minutes for this job (default is 1 minute)
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '^1.23'
cache: false

- name: Check Go Formatting
run: |
files=$(gofmt -l .) && echo $files && [ -z "$files" ]

- name: Golang CI Lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61.0 # Specify the golangci-lint version, so we are stable
args: --timeout 10m # Increase the timeout to 10 minutes

- name: Run make generate-help
run: |
make generate-help

- name: Ensure that make generate-help did not result in changes
uses: CatChen/check-git-status-action@v1
with:
fail-if-not-clean: true
39 changes: 39 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
run:
timeout: 10m
issues:
exclude-files:
- "generated.*\\.go$"
linters:
enable:
- gci
- goconst
- gofmt
- goimports
- unparam
- importas
- bodyclose
- containedctx
- contextcheck
- errorlint
- nilerr
- promlinter
- sloglint
- testifylint
- unparam
- usestdlibvars
- revive
- godot
linters-settings:
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/qdrant) # Custom section: groups all imports with the specified Prefix (our company, but our own component).
- prefix(github.com/qdrant/terraform-provider-qdrant-cloud/) # Custom section: groups all imports with the specified Prefix (this component).
importas:
alias:
- pkg: ^k8s\.io/apimachinery/pkg/apis/(\w+)/(v[\w\d]+)$
alias: $1$2
revive:
rules:
- name: exported
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This is a Terraform provider for Qdrant Cloud, which is the DBaaS solution for Q
## Requirements

- [Terraform](https://www.terraform.io/downloads.html) 1.7.x+
- [Go](https://golang.org/doc/install) 1.21+ (to build the provider plugin)
- [Go](https://golang.org/doc/install) 1.22+ (to build the provider plugin)
- [`swagger-codegen`](https://swagger.io/tools/swagger-codegen/)
`brew install swagger-codegen`

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module terraform-provider-qdrant-cloud/v1
module github.com/qdrant/terraform-provider-qdrant-cloud/v1

go 1.21
go 1.22

require (
github.com/google/uuid v1.6.0
Expand Down
53 changes: 53 additions & 0 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions internal/client/client.test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ func Test_qdrant_cloud_programmatic_access_ClustersAPIService(t *testing.T) {
t.Skip("skip test") // remove to run test

accountGuid, err := uuid.Parse(accountId)
require.Nil(t, err)
require.NoError(t, err)

ctx := context.Background()
resp, err := apiClient.ListClustersWithResponse(ctx, accountGuid, &ListClustersParams{})

require.Nil(t, err)
require.NoError(t, err)
require.NotNil(t, resp)
require.NotNil(t, resp.JSON200)
for _, c := range *resp.JSON200 {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"

"terraform-provider-qdrant-cloud/v1/qdrant"
"github.com/qdrant/terraform-provider-qdrant-cloud/v1/qdrant"
)

// Examples folder formatting
Expand Down
8 changes: 4 additions & 4 deletions qdrant/data_source_accounts_auth_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ func dataAccountsAuthKeysRead(ctx context.Context, d *schema.ResourceData, m int
// Get The account ID as UUID
accountUUID, err := getAccountUUID(d, m)
if err != nil {
return diag.FromErr(fmt.Errorf("%s: %v", errorPrefix, err))
return diag.FromErr(fmt.Errorf("%s: %w", errorPrefix, err))
}
// List the API Keys for the provided account
resp, err := apiClient.ListApiKeysWithResponse(ctx, accountUUID, nil)
// Handle the response in case of error
if err != nil {
d := diag.FromErr(fmt.Errorf("%s: %v", errorPrefix, err))
d := diag.FromErr(fmt.Errorf("%s: %w", errorPrefix, err))
if d.HasError() {
return d
}
Expand All @@ -49,7 +49,7 @@ func dataAccountsAuthKeysRead(ctx context.Context, d *schema.ResourceData, m int
return diag.FromErr(fmt.Errorf("%s: %s", errorPrefix, getError(resp.JSON422)))
}
if resp.StatusCode() != 200 {
return diag.FromErr(fmt.Errorf(getErrorMessage(errorPrefix, resp.HTTPResponse)))
return diag.FromErr(fmt.Errorf("%s", getErrorMessage(errorPrefix, resp.HTTPResponse)))
}
// Get the actual response
apiKeys := resp.JSON200
Expand All @@ -58,7 +58,7 @@ func dataAccountsAuthKeysRead(ctx context.Context, d *schema.ResourceData, m int
}
// Flatten cluster and store in Terraform state
if err := d.Set(authKeysKeysFieldName, flattenAuthKeys(*apiKeys)); err != nil {
return diag.FromErr(fmt.Errorf("%s: %v", errorPrefix, err))
return diag.FromErr(fmt.Errorf("%s: %w", errorPrefix, err))
}
d.SetId(time.Now().Format(time.RFC3339))
return nil
Expand Down
1 change: 1 addition & 0 deletions qdrant/data_source_accounts_auth_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ data "qdrant-cloud_accounts_auth_keys" "test" {

resource.Test(t, resource.TestCase{
ProviderFactories: map[string]func() (*schema.Provider, error){
//nolint:unparam // Ignoring unparam as we know error will always be nil
"qdrant-cloud": func() (*schema.Provider, error) {
return Provider(), nil
},
Expand Down
20 changes: 10 additions & 10 deletions qdrant/data_source_accounts_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

qc "terraform-provider-qdrant-cloud/v1/internal/client"
qc "github.com/qdrant/terraform-provider-qdrant-cloud/v1/internal/client"
)

// dataSourceAccountsClusters constructs a Terraform resource for
Expand Down Expand Up @@ -47,12 +47,12 @@ func dataSourceAccountsClustersRead(ctx context.Context, d *schema.ResourceData,
// Get The account ID as UUID
accountUUID, err := getAccountUUID(d, m)
if err != nil {
return diag.FromErr(fmt.Errorf("%s: %v", errorPrefix, err))
return diag.FromErr(fmt.Errorf("%s: %w", errorPrefix, err))
}
// List all clusters for the provided account
resp, err := apiClient.ListClustersWithResponse(ctx, accountUUID, &qc.ListClustersParams{})
if err != nil {
d := diag.FromErr(fmt.Errorf("%s: %v", errorPrefix, err))
d := diag.FromErr(fmt.Errorf("%s: %w", errorPrefix, err))
if d.HasError() {
return d
}
Expand All @@ -62,15 +62,15 @@ func dataSourceAccountsClustersRead(ctx context.Context, d *schema.ResourceData,
return diag.FromErr(fmt.Errorf("%s: %s", errorPrefix, getError(resp.JSON422)))
}
if resp.StatusCode() != 200 {
return diag.FromErr(fmt.Errorf(getErrorMessage(errorPrefix, resp.HTTPResponse)))
return diag.FromErr(fmt.Errorf("%s", getErrorMessage(errorPrefix, resp.HTTPResponse)))
}
clustersOut := resp.JSON200
if clustersOut == nil {
return diag.FromErr(fmt.Errorf("%s: ListCluster didn't return clusters", errorPrefix))
}
// Update the Terraform state
if err := d.Set("clusters", flattenClusters(*clustersOut)); err != nil {
return diag.FromErr(fmt.Errorf("%s: %v", errorPrefix, err))
return diag.FromErr(fmt.Errorf("%s: %w", errorPrefix, err))
}

d.SetId(time.Now().UTC().String())
Expand All @@ -92,25 +92,25 @@ func dataSourceAccountsClusterRead(ctx context.Context, d *schema.ResourceData,
// Get The account ID as UUID
accountUUID, err := getAccountUUID(d, m)
if err != nil {
return diag.FromErr(fmt.Errorf("%s: %v", errorPrefix, err))
return diag.FromErr(fmt.Errorf("%s: %w", errorPrefix, err))
}
// Get the cluster ID as UUID
clusterID := d.Get("id").(string)
clusterUUID, err := uuid.Parse(clusterID)
if err != nil {
return diag.FromErr(fmt.Errorf("%s: error parsing cluster ID: %v", errorPrefix, err))
return diag.FromErr(fmt.Errorf("%s: error parsing cluster ID: %w", errorPrefix, err))
}
// Fetch the cluster
resp, err := apiClient.GetClusterWithResponse(ctx, accountUUID, clusterUUID)
if err != nil {
return diag.FromErr(fmt.Errorf("%s: %v", errorPrefix, err))
return diag.FromErr(fmt.Errorf("%s: %w", errorPrefix, err))
}
// Inspect result and get the resulting cluster
if resp.JSON422 != nil {
return diag.FromErr(fmt.Errorf("%s: %s", errorPrefix, getError(resp.JSON422)))
}
if resp.StatusCode() != 200 {
return diag.FromErr(fmt.Errorf(getErrorMessage(errorPrefix, resp.HTTPResponse)))
return diag.FromErr(fmt.Errorf("%s", getErrorMessage(errorPrefix, resp.HTTPResponse)))
}
clusterOut := resp.JSON200
if clusterOut == nil {
Expand All @@ -119,7 +119,7 @@ func dataSourceAccountsClusterRead(ctx context.Context, d *schema.ResourceData,
// Flatten cluster and store in Terraform state
for k, v := range flattenCluster(clusterOut) {
if err := d.Set(k, v); err != nil {
return diag.FromErr(fmt.Errorf("%s: %v", errorPrefix, err))
return diag.FromErr(fmt.Errorf("%s: %w", errorPrefix, err))
}
}
d.SetId(clusterID)
Expand Down
1 change: 1 addition & 0 deletions qdrant/data_source_accounts_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ data "qdrant-cloud_accounts_clusters" "test" {

resource.Test(t, resource.TestCase{
ProviderFactories: map[string]func() (*schema.Provider, error){
//nolint:unparam // Ignoring unparam as we know error will always be nil
"qdrant-cloud": func() (*schema.Provider, error) {
return Provider(), nil
},
Expand Down
8 changes: 4 additions & 4 deletions qdrant/data_source_booking_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

qc "terraform-provider-qdrant-cloud/v1/internal/client"
qc "github.com/qdrant/terraform-provider-qdrant-cloud/v1/internal/client"
)

// dataSourceBookingPackages returns the schema for the data source qdrant_booking_packages.
Expand Down Expand Up @@ -39,20 +39,20 @@ func dataBookingPackagesRead(ctx context.Context, d *schema.ResourceData, m inte
// Get all packages
resp, err := apiClient.GetPackagesWithResponse(ctx, &params)
if err != nil {
return diag.FromErr(fmt.Errorf("%s: %v", errorPrefix, err))
return diag.FromErr(fmt.Errorf("%s: %w", errorPrefix, err))
}
if resp.JSON422 != nil {
return diag.FromErr(fmt.Errorf("%s: %v", errorPrefix, getError(resp.JSON422)))
}
if resp.StatusCode() != 200 {
return diag.FromErr(fmt.Errorf(getErrorMessage(errorPrefix, resp.HTTPResponse)))
return diag.FromErr(fmt.Errorf("%s", getErrorMessage(errorPrefix, resp.HTTPResponse)))
}
// Flatten packages
packages := flattenPackages(*resp.JSON200)

// Set the packages in the Terraform state.
if err := d.Set("packages", packages); err != nil {
return diag.FromErr(fmt.Errorf("%s: %v", errorPrefix, err))
return diag.FromErr(fmt.Errorf("%s: %w", errorPrefix, err))
}
d.SetId(time.Now().Format(time.RFC3339))
return nil
Expand Down
1 change: 1 addition & 0 deletions qdrant/data_source_booking_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ output "first_free_tariff" {

resource.Test(t, resource.TestCase{
ProviderFactories: map[string]func() (*schema.Provider, error){
//nolint:unparam // Ignoring unparam as we know error will always be nil
"qdrant-cloud": func() (*schema.Provider, error) {
return Provider(), nil
},
Expand Down
2 changes: 1 addition & 1 deletion qdrant/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}

// ProviderConfig holds the configuration details for creating HTTP requests to the Qdrant Cloud API.
// It encapsulates the API key, the base URL, and the HTTP client configured for API communication.
// As well as the (optional) default account ID
// As well as the (optional) default account ID.
type ProviderConfig struct {
ApiKey string // ApiKey represents the authentication token used for Qdrant Cloud API access.
BaseURL string // BaseURL is the root URL for all API requests, typically pointing to the Qdrant Cloud API endpoint.
Expand Down
15 changes: 2 additions & 13 deletions qdrant/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

// Test the provider configuration with variables set
// Test the provider configuration with variables set.
func TestProvider(t *testing.T) {
resource.Test(t, resource.TestCase{
ProviderFactories: map[string]func() (*schema.Provider, error){
//nolint:unparam // Ignoring unparam as we know error will always be nil
"qdrant-cloud": func() (*schema.Provider, error) {
return Provider(), nil
},
Expand All @@ -40,14 +40,3 @@ provider "qdrant-cloud" {

`, apiKey, apiURL)
}

// Custom check function to validate that the provider's client is configured
func testAccCheckProviderConfigured(providerName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
_, ok := s.RootModule().Resources[providerName]
if !ok {
return fmt.Errorf("provider %q is not configured", providerName)
}
return nil
}
}
6 changes: 3 additions & 3 deletions qdrant/ref_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"github.com/google/uuid"
)

// Generic function to create a pointer to any type
// Generic function to create a pointer to any type.
func newPointer[T any](value T) *T {
return &value
}

// Generic function to dereference a pointer with a default-value fallback
// Generic function to dereference a pointer with a default-value fallback.
func derefPointer[T any](ptr *T, defaults ...T) T {
if ptr != nil {
return *ptr
Expand All @@ -21,7 +21,7 @@ func derefPointer[T any](ptr *T, defaults ...T) T {
return empty
}

// uuidArrayAsStringArray converts an array of UUID to an array of strings
// uuidArrayAsStringArray converts an array of UUID to an array of strings.
func uuidArrayAsStringArray(ptr []uuid.UUID) []string {
result := []string{}
for _, uuid := range ptr {
Expand Down
Loading
Loading