Skip to content
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
42 changes: 23 additions & 19 deletions plugins/source/okta/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,54 @@ package client
import (
"context"
"errors"
"fmt"
"os"

"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
"github.com/hashicorp/go-hclog"
"github.com/cloudquery/plugin-sdk/schema"
"github.com/cloudquery/plugin-sdk/specs"
"github.com/okta/okta-sdk-golang/v2/okta"
"github.com/rs/zerolog"
)

type Client struct {
// This is a client that you need to create and initialize in Configure
// It will be passed for each resource fetcher.
logger hclog.Logger
logger zerolog.Logger
Okta *okta.Client
}

const exampleDomain = "https://<CHANGE_THIS_TO_YOUR_OKTA_DOMAIN>.okta.com"

func (c *Client) Logger() hclog.Logger {
return c.logger
func (c *Client) Logger() *zerolog.Logger {
return &c.logger
}

func Configure(logger hclog.Logger, config interface{}) (schema.ClientMeta, diag.Diagnostics) {
providerConfig := config.(*Config)
func Configure(ctx context.Context, logger zerolog.Logger, s specs.Source) (schema.ClientMeta, error) {
oktaSpec := &Spec{}
if err := s.UnmarshalSpec(oktaSpec); err != nil {
return nil, fmt.Errorf("failed to unmarshal okta spec: %w", err)
}

oktaToken, ok := os.LookupEnv("OKTA_API_TOKEN")
if !ok {
if providerConfig.Token == "" {
return nil, diag.FromError(errors.New("missing OKTA_API_TOKEN, either set it as an environment variable or pass it in the configuration"), diag.USER)
if oktaSpec.Token == "" {
return nil, errors.New("missing OKTA_API_TOKEN, either set it as an environment variable or pass it in the configuration")
}

oktaToken = providerConfig.Token
oktaToken = oktaSpec.Token
}

if providerConfig.Domain == "" || providerConfig.Domain == exampleDomain {
return nil, diag.FromError(errors.New(`failed to configure provider, please set your okta "domain" in cloudquery.yml`), diag.USER)
if oktaSpec.Domain == "" || oktaSpec.Domain == exampleDomain {
return nil, errors.New(`failed to configure provider, please set your okta "domain" in okta.yml`)
}

_, c, err := okta.NewClient(context.Background(), okta.WithOrgUrl(providerConfig.Domain), okta.WithToken(oktaToken), okta.WithCache(true))
_, c, err := okta.NewClient(context.Background(), okta.WithOrgUrl(oktaSpec.Domain), okta.WithToken(oktaToken), okta.WithCache(true))
if err != nil {
return nil, classifyError(err, diag.INTERNAL)
return nil, err
}
client := Client{

return &Client{
logger: logger,
Okta: c,
}
// Return the initialized client and it will be passed to your resources
return &client, nil
}, nil
}
17 changes: 0 additions & 17 deletions plugins/source/okta/client/config.go

This file was deleted.

30 changes: 0 additions & 30 deletions plugins/source/okta/client/error.go

This file was deleted.

7 changes: 0 additions & 7 deletions plugins/source/okta/client/filter.go

This file was deleted.

6 changes: 6 additions & 0 deletions plugins/source/okta/client/spec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package client

type Spec struct {
Token string `json:"token,omitempty"`
Domain string `json:"domain"`
}
15 changes: 0 additions & 15 deletions plugins/source/okta/docs/docs.go

This file was deleted.

19 changes: 7 additions & 12 deletions plugins/source/okta/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The CloudQuery Okta plugin extracts Okta resources configurations.
## Install

```bash
cloudquery init okta
cloudquery generate okta
```

## Authentication
Expand All @@ -14,19 +14,14 @@ To [authenticate](https://developer.okta.com/docs/guides/create-an-api-token/ove

## Configuration

The following configuration section can be automatically generated by `cloudquery init okta`:
The following configuration section can be automatically generated by `cloudquery generate okta`:

```yaml
providers:
- name: okta
configuration:
# Optional. Okta Token to access API, you can set this with OKTA_API_TOKEN environment variable
# ⚠️ Warning - Your token should be kept secret and not committed to source control
# token: "<YOUR_OKTA_TOKEN>"
# Required. You okta domain name
# domain: "https://<CHANGE_THIS_TO_YOUR_OKTA_DOMAIN>.okta.com"
#
# list of resources to fetch
# Optional. Okta Token to access API, you can set this with OKTA_API_TOKEN environment variable
# ⚠️ Warning - Your token should be kept secret and not committed to source control
# token: "<YOUR_OKTA_TOKEN>"
# Required. You okta domain name
# domain: "https://<CHANGE_THIS_TO_YOUR_OKTA_DOMAIN>.okta.com"
```

- `domain` (Required) - Specify the Okta domain you are fetching from. [Visit this link](https://developer.okta.com/docs/guides/find-your-domain/findorg/) to find your Okta domain
Expand Down
67 changes: 20 additions & 47 deletions plugins/source/okta/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,48 @@ module github.com/cloudquery/cloudquery/plugins/source/okta
go 1.19

require (
github.com/cloudquery/cq-provider-sdk v0.14.7
github.com/hashicorp/go-hclog v1.2.2
github.com/cloudquery/plugin-sdk v0.5.2
github.com/okta/okta-sdk-golang/v2 v2.13.0
github.com/rs/zerolog v1.28.0
)

require (
github.com/BurntSushi/toml v1.2.0 // indirect
github.com/Masterminds/squirrel v1.5.3 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/creasty/defaults v1.6.0 // indirect
github.com/doug-martin/goqu/v9 v9.18.0 // indirect
github.com/elliotchance/orderedmap v1.4.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/georgysavva/scany v1.1.0 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/cloudquery/faker/v3 v3.7.7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/getsentry/sentry-go v0.13.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gofrs/uuid v4.3.0+incompatible // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-plugin v1.4.4 // indirect
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/providers/zerolog/v2 v2.0.0-rc.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.12.1 // indirect
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.11.0 // indirect
github.com/jackc/pgx/v4 v4.16.1 // indirect
github.com/jackc/puddle v1.2.1 // indirect
github.com/jhump/protoreflect v1.8.2 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kelseyhightower/envconfig v1.4.0 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/lorenzosaino/go-sysctl v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/patrickmn/go-cache v0.0.0-20180815053127-5633e0862627 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/segmentio/stats/v4 v4.6.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.0 // indirect
github.com/thoas/go-funk v0.9.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xo/dburl v0.11.0 // indirect
github.com/zclconf/go-cty v1.10.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/exp/typeparams v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220728211354-c7608f3a8462 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sync v0.0.0-20220907140024-f12130a52804 // indirect
golang.org/x/sys v0.0.0-20220731174439-a90be440212d // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/genproto v0.0.0-20220801145646-83ce21fca29f // indirect
google.golang.org/grpc v1.48.0 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/tools v0.3.3 // indirect
)
Loading