Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion plugins/source/okta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ gen-docs: build
cloudquery tables --format markdown --output-dir docs test/config.yml
mv docs/$(shell basename $(CURDIR)) docs/tables

.PHONY: gen-spec-schema
gen-spec-schema:
go run client/spec/gen/main.go

# All gen targets
.PHONY: gen
gen: gen-docs
gen: gen-spec-schema gen-docs
66 changes: 66 additions & 0 deletions plugins/source/okta/client/schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

import (
_ "embed"
"fmt"
"os"
"time"
Expand All @@ -10,22 +11,37 @@ import (

type (
Spec struct {
Token string `json:"token,omitempty"`
Domain string `json:"domain,omitempty"`
RateLimit *RateLimit `json:"rate_limit,omitempty"`
Debug bool `json:"debug,omitempty"`
Concurrency int `json:"concurrency,omitempty"`
// Token for Okta API access.
// You can set this with an `OKTA_API_TOKEN` environment variable.
Token string `json:"token" jsonschema:"required,minLength=1"`
Comment thread
disq marked this conversation as resolved.

// 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.
Domain string `json:"domain" jsonschema:"required,pattern=^https?://[^\n<>]+\\.okta\\.com$"`
RateLimit *RateLimit `json:"rate_limit"`

// Enables debug logs within the Okta SDK.
Debug bool `json:"debug,omitempty" jsonschema:"default=false"`

// Number of concurrent requests to be made to Okta API.
Concurrency int `json:"concurrency" jsonschema:"minimum=1,default=10000"`
}
RateLimit struct {
MaxBackoff time.Duration `json:"max_backoff,omitempty"`
MaxRetries int32 `json:"max_retries,omitempty"`
// Max backoff interval to be used.
MaxBackoff time.Duration `json:"max_backoff,omitempty" jsonschema:"minimum=30,default=30"`
Comment thread
disq marked this conversation as resolved.
Outdated

// Max retries to be performed.
MaxRetries int32 `json:"max_retries,omitempty" jsonschema:"minimum=2,default=2"`
}
)

const (
OktaAPIToken = "OKTA_API_TOKEN"
)

//go:embed schema.json
var JSONSchema string

func (s *Spec) SetDefaults(logger *zerolog.Logger) {
const (
minRetries = int32(2)
Expand Down
26 changes: 26 additions & 0 deletions plugins/source/okta/client/spec/gen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"
"log"
"path"
"runtime"

"github.com/cloudquery/cloudquery/plugins/source/okta/client"
cqjsonschema "github.com/cloudquery/codegen/jsonschema"
)

func main() {
fmt.Println("Generating JSON schema for plugin spec")
cqjsonschema.GenerateIntoFile(new(client.Spec), path.Join(currDir(), "../..", "schema.json"),
Comment thread
candiduslynx marked this conversation as resolved.
cqjsonschema.WithAddGoComments("github.com/cloudquery/cloudquery/plugins/source/okta/client", path.Join(currDir(), "../..")),
)
}

func currDir() string {
_, filename, _, ok := runtime.Caller(0)
if !ok {
log.Fatal("Failed to get caller information")
}
return path.Dir(filename)
}
82 changes: 82 additions & 0 deletions plugins/source/okta/client/spec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package client

import (
"testing"

"github.com/cloudquery/codegen/jsonschema"
)

func TestJSONSchema(t *testing.T) {
jsonschema.TestJSONSchema(t, JSONSchema, []jsonschema.TestCase{
{
Name: "empty spec",
Spec: `{}`,
Err: true,
},
{
Name: "spec with token",
Spec: `{"token": "tok"}`,
Err: true,
},
{
Name: "spec with token and domain",
Spec: `{"token": "tok", "domain": "https://domain.okta.com"}`,
},
{
Name: "spec with token and invalid domain",
Spec: `{"token": "tok", "domain": "https://<CHANGE_THIS_TO_YOUR_OKTA_DOMAIN>.okta.com"}`,
Err: true,
},
{
Name: "spec with token and domain and empty rate limit",
Spec: `{"token": "tok", "domain": "https://domain.okta.com", "rate_limit": {}}`,
},
{
Name: "spec with token and domain and null rate limit",
Spec: `{"token": "tok", "domain": "https://domain.okta.com", "rate_limit": null}`,
},
{
Name: "spec with token and domain and rate limit",
Spec: `{"token": "tok", "domain": "https://domain.okta.com", "rate_limit": {"max_backoff": 60}}`,
},
{
Name: "spec with token and domain and invalid rate limit",
Spec: `{"token": "tok", "domain": "https://domain.okta.com", "rate_limit": {"max_backoff": true}}`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove token from tests (only leave for the tests that are actually testing token)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or merge #16498 & reintroduce requirement for token (better IMO)

Err: true,
},
{
Name: "spec with token and domain and zero rate limit",
Spec: `{"token": "tok", "domain": "https://domain.okta.com", "rate_limit": {"max_backoff": 0}}`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in e8180cc

Err: true,
},
{
Name: "spec with bool concurrency",
Spec: `{"token": "tok", "domain": "https://domain.okta.com", "concurrency":false}`,
Err: true,
},
{
Name: "spec with null concurrency",
Spec: `{"token": "tok", "domain": "https://domain.okta.com", "concurrency":null}`,
Err: true,
},
{
Name: "spec with string concurrency",
Spec: `{"token": "tok", "domain": "https://domain.okta.com", "concurrency":"str"}`,
Err: true,
},
{
Name: "spec with proper concurrency",
Spec: `{"token": "tok", "domain": "https://domain.okta.com", "concurrency": 7}`,
},
{
Name: "spec with array concurrency",
Spec: `{"token": "tok", "domain": "https://domain.okta.com", "concurrency":["abc"]}`,
Err: true,
},
{
Name: "spec with unknown field",
Spec: `{"token": "tok", "domain": "https://domain.okta.com", "unknown": "test"}`,
Err: true,
},
})
}
4 changes: 2 additions & 2 deletions plugins/source/okta/docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ Make sure you use [environment variable expansion](/docs/advanced-topics/environ

### Rate limit spec

- `max_backoff` (`duration`, optional. Default: `5s`)
- `max_backoff` (`duration`, optional. Default: `30s`)

Max backoff interval to be used.
If the value specified is less than the default one, the default one is used.

- `max_retries` (`int32`, optional. Default: `3`)
- `max_retries` (`int32`, optional. Default: `2`)
Comment thread
disq marked this conversation as resolved.
Outdated

Max retries to be performed.
If the value specified is less than the default one, the default one is used.
Expand Down
4 changes: 4 additions & 0 deletions plugins/source/okta/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21.4

require (
github.com/apache/arrow/go/v15 v15.0.0-20240114144300-7e703aae55c1
github.com/cloudquery/codegen v0.3.12
github.com/cloudquery/plugin-sdk/v4 v4.29.1
github.com/gorilla/mux v1.8.0
github.com/okta/okta-sdk-golang/v3 v3.0.2
Expand Down Expand Up @@ -129,3 +130,6 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

// github.com/cloudquery/jsonschema @ cqmain
replace github.com/invopop/jsonschema => github.com/cloudquery/jsonschema v0.0.0-20240202134451-d771afde32fb
Comment thread
disq marked this conversation as resolved.
6 changes: 4 additions & 2 deletions plugins/source/okta/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudquery/cloudquery-api-go v1.7.2 h1:jpQfeZUxekbV7ASN5ONpGIkrtKIZvC/Y8fOj+tQxLm4=
github.com/cloudquery/cloudquery-api-go v1.7.2/go.mod h1:03fojQg0UpdgqXZ9tzZ5gF5CPad/F0sok66bsX6u4RA=
github.com/cloudquery/codegen v0.3.12 h1:9BaYdwbMJU1HVT/BHI+ykhOhBGeXt8AjpvBiXN1KhKE=
github.com/cloudquery/codegen v0.3.12/go.mod h1:utqjurr58U8uqcPJe0rZjh06i0Eq9uAPGOmyIjq/1w8=
github.com/cloudquery/jsonschema v0.0.0-20240202134451-d771afde32fb h1:/l8fbvLOCNlgkHp8VUKTTL+Tk9gs5y/K3Yx/bRfReNk=
github.com/cloudquery/jsonschema v0.0.0-20240202134451-d771afde32fb/go.mod h1:0SoZ/U7yJlNOR+fWsBSeTvTbGXB6DK01tzJ7m2Xfg34=
github.com/cloudquery/plugin-pb-go v1.16.7 h1:wLx5TFvS6gAvD1dcBZdv5YSskcNCnNpF1JNituka5jM=
github.com/cloudquery/plugin-pb-go v1.16.7/go.mod h1:Sd08P8HIjwi3gmfoE0X21qo6HL1NiVdNl/00JrK+DkM=
github.com/cloudquery/plugin-sdk/v2 v2.7.0 h1:hRXsdEiaOxJtsn/wZMFQC9/jPfU1MeMK3KF+gPGqm7U=
Expand Down Expand Up @@ -228,8 +232,6 @@ github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/C
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/iris-contrib/httpexpect/v2 v2.15.2 h1:T9THsdP1woyAqKHwjkEsbCnMefsAFvk8iJJKokcJ3Go=
github.com/iris-contrib/httpexpect/v2 v2.15.2/go.mod h1:JLDgIqnFy5loDSUv1OA2j0mb6p/rDhiCqigP22Uq9xE=
github.com/iris-contrib/schema v0.0.6 h1:CPSBLyx2e91H2yJzPuhGuifVRnZBBJ3pCOMbOvPZaTw=
Expand Down
2 changes: 2 additions & 0 deletions plugins/source/okta/resources/plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package plugin

import (
"github.com/cloudquery/cloudquery/plugins/source/okta/client"
"github.com/cloudquery/plugin-sdk/v4/plugin"
)

Expand All @@ -18,5 +19,6 @@ func Plugin() *plugin.Plugin {
Configure,
plugin.WithKind(Kind),
plugin.WithTeam(Team),
plugin.WithJSONSchema(client.JSONSchema),
)
}