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

[BB-124] Use workspace slug #26

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Run linters
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout=3m
Expand All @@ -30,7 +30,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: go tests
run: go test -v -covermode=count -json ./... > test.json
run: (set -o pipefail && go test -v -covermode=count -json ./... | tee test.json)
- name: annotate go tests
if: always()
uses: guyarb/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Run linters
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout=3m
Expand All @@ -33,7 +33,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: go tests
run: go test -v -covermode=count -json ./... > test.json
run: (set -o pipefail && go test -v -covermode=count -json ./... | tee test.json)
- name: annotate go tests
if: always()
uses: guyarb/[email protected]
Expand Down
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ linters:
- bodyclose # checks whether HTTP response body is closed successfully
- durationcheck # check for two durations multiplied together
- 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.
- execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds
- exhaustive # check exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- forbidigo # Forbids identifiers
- gochecknoinits # Checks that no init functions are present in Go code
- goconst # Finds repeated strings that could be replaced by a constant
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,23 @@ Usage:
baton-bitbucket [command]

Available Commands:
capabilities Get connector capabilities
completion Generate the autocompletion script for the specified shell
help Help about any command

Flags:
--app-password string Application password used to connect to the BitBucket API. ($BATON_APP_PASSWORD)
--client-id string The client ID used to authenticate with ConductorOne ($BATON_CLIENT_ID)
--client-secret string The client secret used to authenticate with ConductorOne ($BATON_CLIENT_SECRET)
--consumer-key string OAuth consumer key used to connect to the BitBucket API via oauth. ($BATON_CONSUMER_ID)
--consumer-key string OAuth consumer key used to connect to the BitBucket API via oauth. ($BATON_CONSUMER_KEY)
--consumer-secret string The consumer secret used to connect to the BitBucket API via oauth. ($BATON_CONSUMER_SECRET)
-f, --file string The path to the c1z file to sync with ($BATON_FILE) (default "sync.c1z")
-h, --help help for baton-bitbucket
--log-format string The output format for logs: json, console ($BATON_LOG_FORMAT) (default "json")
--log-level string The log level: debug, info, warn, error ($BATON_LOG_LEVEL) (default "info")
--password string Application password used to connect to the BitBucket API. ($BATON_PASSWORD)
-p, --provisioning This must be set in order for provisioning actions to be enabled ($BATON_PROVISIONING)
--skip-full-sync This must be set to skip a full sync ($BATON_SKIP_FULL_SYNC)
--ticketing This must be set to enable ticketing support ($BATON_TICKETING)
--token string Access token (workspace or project scoped) used to connect to the BitBucket API. ($BATON_TOKEN)
--username string Username of administrator used to connect to the BitBucket API. ($BATON_USERNAME)
-v, --version version for baton-bitbucket
Expand Down
33 changes: 0 additions & 33 deletions cmd/baton-bitbucket/config.go

This file was deleted.

44 changes: 27 additions & 17 deletions cmd/baton-bitbucket/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"
"os"

"github.com/conductorone/baton-bitbucket/pkg/config"
"github.com/conductorone/baton-bitbucket/pkg/connector"
configschema "github.com/conductorone/baton-sdk/pkg/config"
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
Expand All @@ -17,8 +18,9 @@ import (
)

var (
version = "dev"
LoginURL = &url.URL{
version = "dev"
connectorName = "baton-bitbucket"
LoginURL = &url.URL{
Scheme: "https",
Host: "bitbucket.org",
Path: "/site/oauth2/access_token",
Expand All @@ -28,7 +30,12 @@ var (
func main() {
ctx := context.Background()

_, cmd, err := configschema.DefineConfiguration(ctx, "baton-bitbucket", getConnector, cfg)
_, cmd, err := configschema.DefineConfiguration(
ctx,
connectorName,
getConnector,
config.ConfigurationSchema,
)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
Expand All @@ -44,11 +51,11 @@ func main() {
}

func constructAuth(v *viper.Viper) (uhttp.AuthCredentials, error) {
accessToken := v.GetString(tokenField.FieldName)
username := v.GetString(usernameField.FieldName)
password := v.GetString(passwordField.FieldName)
consumerId := v.GetString(consumerKeyField.FieldName)
consumerSecret := v.GetString(consumerSecretField.FieldName)
accessToken := v.GetString(config.TokenField.FieldName)
username := v.GetString(config.UsernameField.FieldName)
password := v.GetString(config.PasswordField.FieldName)
consumerId := v.GetString(config.ConsumerKeyField.FieldName)
consumerSecret := v.GetString(config.ConsumerSecretField.FieldName)

if accessToken != "" {
return uhttp.NewBearerAuth(accessToken), nil
Expand All @@ -73,16 +80,15 @@ func constructAuth(v *viper.Viper) (uhttp.AuthCredentials, error) {
func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, error) {
l := ctxzap.Extract(ctx)

accessToken := v.GetString(tokenField.FieldName)
accessToken := v.GetString(config.TokenField.FieldName)
accessTokenNotSet := (accessToken == "")
username := v.GetString(usernameField.FieldName)
password := v.GetString(passwordField.FieldName)
consumerId := v.GetString(consumerKeyField.FieldName)
consumerSecret := v.GetString(consumerSecretField.FieldName)
workspaces := v.GetStringSlice(workspacesField.FieldName)
username := v.GetString(config.UsernameField.FieldName)
password := v.GetString(config.PasswordField.FieldName)
consumerId := v.GetString(config.ConsumerKeyField.FieldName)
consumerSecret := v.GetString(config.ConsumerSecretField.FieldName)

basicNotSet := (username == "" || password == "")
oauthNotSet := (consumerId == "" || consumerSecret == "")
basicNotSet := username == "" || password == ""
oauthNotSet := consumerId == "" || consumerSecret == ""

if accessTokenNotSet && basicNotSet && oauthNotSet {
return nil, fmt.Errorf("either an access token, username and password or consumer key and secret must be provided")
Expand All @@ -94,7 +100,11 @@ func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, e
return nil, err
}

bitbucketConnector, err := connector.New(ctx, workspaces, auth)
bitbucketConnector, err := connector.New(
ctx,
v.GetStringSlice(config.WorkspacesField.FieldName),
auth,
)
if err != nil {
l.Error("error creating connector", zap.Error(err))
return nil, err
Expand Down
33 changes: 19 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ module github.com/conductorone/baton-bitbucket
go 1.22

require (
github.com/conductorone/baton-sdk v0.2.17
github.com/conductorone/baton-sdk v0.2.31
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/spf13/viper v1.18.2
github.com/spf13/viper v1.19.0
go.uber.org/zap v1.27.0
golang.org/x/text v0.16.0
google.golang.org/grpc v1.63.2
golang.org/x/text v0.18.0
google.golang.org/grpc v1.67.0
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
)

require (
Expand All @@ -35,11 +41,10 @@ require (
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
github.com/deckarep/golang-set/v2 v2.6.0
github.com/doug-martin/goqu/v9 v9.19.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/glebarez/go-sqlite v1.22.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
Expand Down Expand Up @@ -77,14 +82,14 @@ require (
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/ratelimit v0.3.1 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240506185236-b8a5c65736ae // indirect
google.golang.org/protobuf v1.34.1 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading
Loading