Skip to content

Commit 3adbb42

Browse files
authored
Merge pull request #14 from ConductorOne/add_account_provisioning
[BB-921] add working account provisioning
1 parent 9277b2c commit 3adbb42

File tree

2,359 files changed

+4822372
-2010916
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,359 files changed

+4822372
-2010916
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Checkout code
1212
uses: actions/checkout@v3
1313
- name: Run linters
14-
uses: golangci/golangci-lint-action@v3
14+
uses: golangci/golangci-lint-action@v8
1515
with:
1616
version: latest
1717
args: --timeout=3m
@@ -35,4 +35,4 @@ jobs:
3535
if: always()
3636
uses: guyarb/golang-test-annotations@v0.5.1
3737
with:
38-
test-results: test.json
38+
test-results: test.json

.golangci.yml

Lines changed: 113 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,117 @@
1-
linters-settings:
2-
exhaustive:
3-
default-signifies-exhaustive: true
4-
5-
gocritic:
6-
# The list of supported checkers can be find in https://go-critic.github.io/overview.
7-
settings:
8-
underef:
9-
# Whether to skip (*x).method() calls where x is a pointer receiver.
10-
skipRecvDeref: false
11-
12-
govet:
13-
enable-all: true
14-
disable:
15-
- fieldalignment # too strict
16-
- shadow # complains too much about shadowing errors. All research points to this being fine.
17-
18-
nakedret:
19-
max-func-lines: 0
20-
21-
nolintlint:
22-
allow-no-explanation: [ forbidigo, tracecheck, gomnd, gochecknoinits, makezero ]
23-
require-explanation: true
24-
require-specific: true
25-
26-
revive:
27-
ignore-generated-header: true
28-
severity: error
29-
rules:
30-
- name: atomic
31-
- name: line-length-limit
32-
arguments: [ 200 ]
33-
# These are functions that we use without checking the errors often. Most of these can't return an error even
34-
# though they implement an interface that can.
35-
- name: unhandled-error
36-
arguments:
37-
- fmt.Printf
38-
- fmt.Println
39-
- fmt.Fprintf
40-
- fmt.Fprintln
41-
- os.Stderr.Sync
42-
- sb.WriteString
43-
- buf.WriteString
44-
- hasher.Write
45-
- os.Setenv
46-
- os.RemoveAll
47-
- name: var-naming
48-
arguments: [["ID", "URL", "HTTP", "API"], []]
49-
50-
tenv:
51-
all: true
52-
53-
varcheck:
54-
exported-fields: false # this appears to improperly detect exported variables as unused when they are used from a package with the same name
55-
56-
1+
version: "2"
572
linters:
58-
disable-all: true
3+
default: none
594
enable:
60-
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
61-
- gosimple # Linter for Go source code that specializes in simplifying a code
62-
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
63-
- ineffassign # Detects when assignments to existing variables are not used
64-
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
65-
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
66-
- unused # Checks Go code for unused constants, variables, functions and types
67-
- asasalint # Check for pass []any as any in variadic func(...any)
68-
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
69-
- bidichk # Checks for dangerous unicode character sequences
70-
- bodyclose # checks whether HTTP response body is closed successfully
71-
- durationcheck # check for two durations multiplied together
72-
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
73-
- execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds
74-
- exhaustive # check exhaustiveness of enum switch statements
75-
- exportloopref # checks for pointers to enclosing loop variables
76-
- forbidigo # Forbids identifiers
77-
- gochecknoinits # Checks that no init functions are present in Go code
78-
- goconst # Finds repeated strings that could be replaced by a constant
79-
- gocritic # Provides diagnostics that check for bugs, performance and style issues.
80-
- godot # Check if comments end in a period
81-
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt.
82-
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
83-
- goprintffuncname # Checks that printf-like functions are named with f at the end
84-
- gosec # Inspects source code for security problems
85-
- nakedret # Finds naked returns in functions greater than a specified function length
86-
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
87-
- noctx # noctx finds sending http request without context.Context
88-
- nolintlint # Reports ill-formed or insufficient nolint directives
89-
- nonamedreturns # Reports all named returns
90-
- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL.
91-
- predeclared # find code that shadows one of Go's predeclared identifiers
92-
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
93-
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
94-
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
95-
- unconvert # Remove unnecessary type conversions
96-
- usestdlibvars # detect the possibility to use variables/constants from the Go standard library
97-
- whitespace # Tool for detection of leading and trailing whitespace
98-
5+
- asasalint
6+
- asciicheck
7+
- bidichk
8+
- bodyclose
9+
- durationcheck
10+
- errcheck
11+
- errorlint
12+
- exhaustive
13+
- forbidigo
14+
- gochecknoinits
15+
- goconst
16+
- gocritic
17+
- godot
18+
- gomoddirectives
19+
- goprintffuncname
20+
- gosec
21+
- govet
22+
- ineffassign
23+
- nakedret
24+
- nilerr
25+
- noctx
26+
- nolintlint
27+
- nonamedreturns
28+
- nosprintfhostport
29+
- predeclared
30+
- revive
31+
- staticcheck
32+
- tparallel
33+
- unconvert
34+
- unused
35+
- usestdlibvars
36+
- usetesting
37+
- whitespace
38+
settings:
39+
exhaustive:
40+
default-signifies-exhaustive: true
41+
gocritic:
42+
enabled-checks:
43+
- ruleguard
44+
settings:
45+
ruleguard:
46+
rules: ${base-path}/tools/rules.go
47+
underef:
48+
skipRecvDeref: false
49+
govet:
50+
disable:
51+
- fieldalignment
52+
- shadow
53+
enable-all: true
54+
nakedret:
55+
max-func-lines: 0
56+
nolintlint:
57+
require-explanation: true
58+
require-specific: true
59+
allow-no-explanation:
60+
- forbidigo
61+
- tracecheck
62+
- gomnd
63+
- gochecknoinits
64+
- makezero
65+
revive:
66+
severity: error
67+
rules:
68+
- name: atomic
69+
- name: line-length-limit
70+
arguments:
71+
- 200
72+
- name: unhandled-error
73+
arguments:
74+
- fmt.Printf
75+
- fmt.Println
76+
- fmt.Fprint
77+
- fmt.Fprintf
78+
- fmt.Fprintln
79+
- os.Stderr.Sync
80+
- sb.WriteString
81+
- buf.WriteString
82+
- hasher.Write
83+
- os.Setenv
84+
- os.RemoveAll
85+
- name: var-naming
86+
arguments:
87+
- - ID
88+
- URL
89+
- HTTP
90+
- API
91+
- []
92+
exclusions:
93+
generated: lax
94+
presets:
95+
- comments
96+
- common-false-positives
97+
- legacy
98+
- std-error-handling
99+
rules:
100+
- linters:
101+
- godot
102+
source: (TODO)
103+
paths:
104+
- third_party$
105+
- builtin$
106+
- examples$
99107
issues:
100108
max-same-issues: 50
101-
102-
exclude-rules:
103-
# Don't require TODO comments to end in a period
104-
- source: "(TODO)"
105-
linters: [ godot ]
109+
formatters:
110+
enable:
111+
- goimports
112+
exclusions:
113+
generated: lax
114+
paths:
115+
- third_party$
116+
- builtin$
117+
- examples$

Makefile

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
GOOS = $(shell go env GOOS)
22
GOARCH = $(shell go env GOARCH)
33
BUILD_DIR = dist/${GOOS}_${GOARCH}
4+
GENERATED_CONF := pkg/config/conf.gen.go
45

56
ifeq ($(GOOS),windows)
67
OUTPUT_PATH = ${BUILD_DIR}/baton-tableau.exe
78
else
89
OUTPUT_PATH = ${BUILD_DIR}/baton-tableau
910
endif
1011

12+
# Set the build tag conditionally based on ENABLE_LAMBDA
13+
ifdef BATON_LAMBDA_SUPPORT
14+
BUILD_TAGS=-tags baton_lambda_support
15+
else
16+
BUILD_TAGS=
17+
endif
18+
1119
.PHONY: build
12-
build:
13-
go build -o ${OUTPUT_PATH} ./cmd/baton-tableau
20+
build: ${GENERATED_CONF}
21+
go build ${BUILD_TAGS} -o ${OUTPUT_PATH} ./cmd/baton-tableau
22+
23+
$(GENERATED_CONF): pkg/config/config.go go.mod
24+
@echo "Generating $(GENERATED_CONF)..."
25+
go generate -tags=generate ./pkg/config
26+
27+
generate: $(GENERATED_CONF)
1428

1529
.PHONY: update-deps
1630
update-deps:
@@ -25,4 +39,4 @@ add-dep:
2539

2640
.PHONY: lint
2741
lint:
28-
golangci-lint run
42+
golangci-lint run --out-format=colored-line-number --timeout=3m

cmd/baton-tableau/config.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

cmd/baton-tableau/main.go

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import (
66
"net/url"
77
"os"
88

9-
"github.com/conductorone/baton-sdk/pkg/cli"
109
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
10+
"github.com/conductorone/baton-sdk/pkg/field"
1111
"github.com/conductorone/baton-sdk/pkg/types"
12+
13+
"github.com/conductorone/baton-sdk/pkg/config"
14+
cfg "github.com/conductorone/baton-tableau/pkg/config"
1215
"github.com/conductorone/baton-tableau/pkg/connector"
1316
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
1417
"go.uber.org/zap"
@@ -19,15 +22,18 @@ var version = "dev"
1922
func main() {
2023
ctx := context.Background()
2124

22-
cfg := &config{}
23-
cmd, err := cli.NewCmd(ctx, "baton-tableau", cfg, validateConfig, getConnector)
25+
_, cmd, err := config.DefineConfiguration(
26+
ctx,
27+
"baton-tableau",
28+
getConnector[*cfg.Tableau],
29+
cfg.Config,
30+
)
2431
if err != nil {
2532
fmt.Fprintln(os.Stderr, err.Error())
2633
os.Exit(1)
2734
}
2835

2936
cmd.Version = version
30-
cmdFlags(cmd)
3137

3238
err = cmd.Execute()
3339
if err != nil {
@@ -36,19 +42,30 @@ func main() {
3642
}
3743
}
3844

39-
func getConnector(ctx context.Context, cfg *config) (types.ConnectorServer, error) {
45+
func getConnector[T field.Configurable](ctx context.Context, config T) (types.ConnectorServer, error) {
4046
l := ctxzap.Extract(ctx)
47+
if err := field.Validate(cfg.Config, config); err != nil {
48+
return nil, err
49+
}
4150

42-
apiVersion := "3.17"
43-
if cfg.APIVersion != "" {
44-
apiVersion = cfg.APIVersion
51+
apiVersion := config.GetString(cfg.APIVersion.FieldName)
52+
if apiVersion == "" {
53+
apiVersion = "3.17"
4554
}
46-
baseUrl, err := url.JoinPath("https://", cfg.ServerPath, "api", apiVersion)
55+
56+
serverPath := config.GetString(cfg.ServerPath.FieldName)
57+
baseUrl, err := url.JoinPath("https://", serverPath, "api", apiVersion)
4758
if err != nil {
4859
l.Error("error creating base url", zap.Error(err))
4960
}
5061

51-
cb, err := connector.New(ctx, baseUrl, cfg.SiteID, cfg.AccessTokenName, cfg.AccessTokenSecret)
62+
cb, err := connector.New(
63+
ctx,
64+
baseUrl,
65+
config.GetString(cfg.SiteID.FieldName),
66+
config.GetString(cfg.AccessTokenName.FieldName),
67+
config.GetString(cfg.AccessTokenSecret.FieldName),
68+
)
5269
if err != nil {
5370
l.Error("error creating connector", zap.Error(err))
5471
return nil, err

0 commit comments

Comments
 (0)