Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

feat: YAML config support #182

Merged
merged 2 commits into from
Jun 22, 2022
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
28 changes: 26 additions & 2 deletions client/config.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
package client

import "github.com/cloudquery/cq-provider-sdk/cqproto"

type Config struct {
Contexts []string `hcl:"contexts,optional"`

requestedFormat cqproto.ConfigFormat
}

func NewConfig(f cqproto.ConfigFormat) *Config {
return &Config{
requestedFormat: f,
}
}

func (Config) Example() string {
return `configuration {
func (c Config) Example() string {
switch c.requestedFormat {
case cqproto.ConfigHCL:
return `configuration {
// Optional. Set contexts that you want to fetch. If it is not given then all contexts from config are iterated over.
// contexts = ["YOUR_CONTEXT_NAME1", "YOUR_CONTEXT_NAME2"]
}`
default:
return `
Optional. Set contexts that you want to fetch. If it is not given then all contexts from config are iterated over.
contexts:
- YOUR_CONTEXT_NAME1
- YOUR_CONTEXT_NAME2
`
}
}

func (c Config) Format() cqproto.ConfigFormat {
return c.requestedFormat
}
9 changes: 5 additions & 4 deletions client/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"testing"

"github.com/cloudquery/cq-provider-sdk/cqproto"
"github.com/cloudquery/cq-provider-sdk/provider"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
Expand All @@ -22,8 +23,8 @@ func K8sTestHelper(t *testing.T, table *schema.Table, snapshotDirPath string) {
Name: "k8s_mock_test_provider",
Version: "development",
Configure: Configure,
Config: func() provider.Config {
return &Config{}
Config: func(f cqproto.ConfigFormat) provider.Config {
return NewConfig(f)
},
ResourceMap: map[string]*schema.Table{
"test_resource": table,
Expand Down Expand Up @@ -54,8 +55,8 @@ func K8sMockTestHelper(t *testing.T, table *schema.Table, builder func(*testing.
ResourceMap: map[string]*schema.Table{
"test_resource": table,
},
Config: func() provider.Config {
return &Config{}
Config: func(f cqproto.ConfigFormat) provider.Config {
return NewConfig(f)
},
},
Config: cfg,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/cloudquery/cq-provider-k8s
go 1.17

require (
github.com/cloudquery/cq-provider-sdk v0.11.4
github.com/cloudquery/cq-provider-sdk v0.12.1
github.com/cloudquery/faker/v3 v3.7.5
github.com/golang/mock v1.6.0
github.com/hashicorp/go-hclog v1.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudquery/cq-provider-sdk v0.11.4 h1:/y/AB+/mKRGFoc0rLin3KRtfqc5eAooYjqdltrsGi8I=
github.com/cloudquery/cq-provider-sdk v0.11.4/go.mod h1:q6hYy9S+XtKG8cyOiLG5gqSIkXEJ72MHQ316zW6DMiA=
github.com/cloudquery/cq-provider-sdk v0.12.1 h1:Y4/VWjb/HLRX1pUoA7H82JoEu5mizNCDlfIeLGXOXSA=
github.com/cloudquery/cq-provider-sdk v0.12.1/go.mod h1:o5czsmX3MeP8cY/KtabkqavkS7asF8HwFAO1n5+CvoQ=
github.com/cloudquery/faker/v3 v3.7.5 h1:G7ANdEEcm8TvAAjIwNWSLrYK36CFCiSlrCqOTGCccL0=
github.com/cloudquery/faker/v3 v3.7.5/go.mod h1:1b8WVG9Gh0T2hVo1a8dWeXfu0AhqSB6J/mmJaesqOeo=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
Expand Down
5 changes: 3 additions & 2 deletions resources/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cloudquery/cq-provider-k8s/resources/services/core"
"github.com/cloudquery/cq-provider-k8s/resources/services/networking"
"github.com/cloudquery/cq-provider-k8s/resources/services/rbac"
"github.com/cloudquery/cq-provider-sdk/cqproto"
"github.com/cloudquery/cq-provider-sdk/provider"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)
Expand All @@ -23,8 +24,8 @@ func Provider() *provider.Provider {
Name: ProviderName,
Configure: client.Configure,
ErrorClassifier: client.ErrorClassifier,
Config: func() provider.Config {
return &client.Config{}
Config: func(f cqproto.ConfigFormat) provider.Config {
return client.NewConfig(f)
},
ResourceMap: map[string]*schema.Table{
"apps.daemon_sets": apps.DaemonSets(),
Expand Down