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

Adding bitbucket datacenter resources #1

Merged
merged 82 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
64c6575
Adding user resource
mchavez Apr 29, 2024
420f6d5
Update user resource
mchavez Apr 30, 2024
76b6cf2
Adding pagination
mchavez Apr 30, 2024
0eba0c3
Listing projects
mchavez May 1, 2024
e9b79d3
Listing Repositories
mchavez May 1, 2024
809f3c3
Listing groups
mchavez May 1, 2024
5f2e69c
Refactoring code
mchavez May 1, 2024
5a4c1e1
Quick change
mchavez May 1, 2024
d0acd68
Adding entitlements
mchavez May 1, 2024
b5135e4
Update comments
mchavez May 1, 2024
2385a17
Refactoring code
mchavez May 1, 2024
b3f87b6
Adding group grants
mchavez May 1, 2024
1821aff
Adding global permissions
mchavez May 2, 2024
fdbdcad
Adding repo grants
mchavez May 2, 2024
55c196e
Adding projects grants
mchavez May 2, 2024
b90f9ff
Fix linter issues
mchavez May 2, 2024
8a27150
Refactoring code
mchavez May 2, 2024
b702d01
Adding groups with permission to repository
mchavez May 3, 2024
19789fa
Adding groups with permission to repository
mchavez May 3, 2024
9d07695
Adding provisioning - groups
mchavez May 3, 2024
6d32466
Update readme
mchavez May 3, 2024
f598eb5
Update readme
mchavez May 3, 2024
56b0124
Restore readme
mchavez May 3, 2024
b1fcce8
Add readme content
mchavez May 3, 2024
c5822d9
Adding deprovisioning - groups
mchavez May 3, 2024
17edc19
Adding repository permissions
mchavez May 4, 2024
8459def
Fix linter issues
mchavez May 4, 2024
3657d57
Adding provisioning - repository
mchavez May 6, 2024
c863182
Update lint version
mchavez May 6, 2024
79b96d2
Update lint version
mchavez May 6, 2024
ffcde2e
Remove deprecated linter
mchavez May 6, 2024
7a14003
Revoking repository permission
mchavez May 6, 2024
9ea3401
Refactoring code
mchavez May 6, 2024
bca9c49
Refactoring code
mchavez May 6, 2024
d0181c9
Refactoring code - groups
mchavez May 7, 2024
d8390bf
Refactoring code - groups
mchavez May 7, 2024
c84bd30
Refactoring code - groups
mchavez May 7, 2024
6e5100a
Refactoring code
mchavez May 7, 2024
4f5bcc5
Code refactor
mchavez May 7, 2024
1f1e696
Refactoring code
mchavez May 7, 2024
a549caf
Adding grants - projects
mchavez May 8, 2024
e139cb0
Adding projects permissions
mchavez May 8, 2024
a55403f
Adding project grant
mchavez May 8, 2024
b38146f
Revoking projects permissions
mchavez May 8, 2024
9c0c407
Update comments
mchavez May 8, 2024
7231a86
Refactoring code
mchavez May 8, 2024
aa59cda
Refactoring code
mchavez May 9, 2024
ae93c74
Refactoring code
mchavez May 9, 2024
c46e4a2
Updating integration tests
mchavez May 9, 2024
90f49ce
Updating integration tests
mchavez May 9, 2024
9a18ec1
Fix capabilities
mchavez May 9, 2024
d5bbf98
Add sql file
mchavez May 9, 2024
fbd1bf2
Add sql file
mchavez May 9, 2024
b695d1b
Add sql file
mchavez May 9, 2024
cfc32a7
Updating integration tests
mchavez May 9, 2024
3e49840
Updating integration tests
mchavez May 9, 2024
10eda6c
Updating integration tests
mchavez May 10, 2024
e41e8b2
Updating integration tests
mchavez May 10, 2024
d25846f
Updating integration tests
mchavez May 10, 2024
d0788eb
Updating integration tests
mchavez May 10, 2024
898407b
Updating integration tests
mchavez May 10, 2024
7b842d8
Updating integration tests
mchavez May 10, 2024
4c8c664
Updating integration tests
mchavez May 10, 2024
d6b1bd4
Updating integration tests
mchavez May 10, 2024
ab9c7f8
Updating integration tests
mchavez May 10, 2024
0b115a8
Update ci yaml
mchavez May 10, 2024
2acb6aa
Update ci yaml
mchavez May 10, 2024
1569d9c
Update ci yaml
mchavez May 10, 2024
eac24ca
Update ci yaml
mchavez May 10, 2024
1d3247a
Update ci yaml
mchavez May 10, 2024
5f95f34
Update ci yaml
mchavez May 10, 2024
c121be9
Update ci yaml
mchavez May 10, 2024
7270301
Update ci yaml
mchavez May 10, 2024
f318588
Update ci yaml
mchavez May 10, 2024
d4a0f5a
Update ci yaml
mchavez May 10, 2024
34c2ffd
Update ci yaml
mchavez May 10, 2024
fe67bf6
Update readme
mchavez May 11, 2024
e0a84ee
Update readme
mchavez May 11, 2024
d1cc555
Update readme
mchavez May 11, 2024
842e1c4
Update readme
mchavez May 11, 2024
fd68e0c
Update readme
mchavez May 11, 2024
3f5b71d
Quick change
mchavez May 11, 2024
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
96 changes: 47 additions & 49 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: ci
on: pull_request
on:
pull_request:
jobs:
go-lint:
runs-on: ubuntu-latest
Expand All @@ -11,7 +12,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Run linters
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v5
with:
version: latest
args: --timeout=3m
Expand Down Expand Up @@ -40,65 +41,62 @@ jobs:
test:
runs-on: ubuntu-latest
# Define any services needed for the test suite (or delete this section)
# services:
# postgres:
# image: postgres:16
# ports:
# - "5432:5432"
# env:
# POSTGRES_PASSWORD: secretpassword
services:
postgres:
image: postgres:15
# Maps tcp port 5432 on service container to the host
ports:
- "5432:5432"
env:
POSTGRES_USER: bitbucket
POSTGRES_PASSWORD: ${{ secrets.DB_PASSWORD }}
POSTGRES_DB: bitbucket
# needed because the postgres container does not provide a healthcheck
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 3
--health-start-period 90s

bitbucket:
image: atlassian/bitbucket-server:8.9.4
env:
JVM_MINIMUM_MEMORY: 2g
JVM_MAXIMUM_MEMORY: 4g
JDBC_DRIVER: org.postgresql.Driver
JDBC_USER: bitbucket
JDBC_PASSWORD: ${{ secrets.DB_PASSWORD }}
JDBC_URL: jdbc:postgresql://postgres:5432/bitbucket
ports:
- '7990:7990'
options: >-
--health-cmd "curl -f http://localhost:7990/"
--health-interval 10s
--health-timeout 5s
--health-retries 3
--health-start-period 90s

env:
BATON_LOG_LEVEL: debug
# Add any environment variables needed to run baton-bitbucket-datacenter
# BATON_BASE_URL: 'http://localhost:8080'
BATON_BASE_URL: 'http://localhost:7990'
BATON_USERNAME: ${{ secrets.BATON_BITBUCKETDC_PASSWORD }}
BATON_PASSWORD: ${{ secrets.BATON_BITBUCKETDC_USERNAME }}
# BATON_ACCESS_TOKEN: 'secret_token'
# The following parameters are passed to grant/revoke commands
# Change these to the correct IDs for your test data
CONNECTOR_GRANT: 'grant:entitlement:group:1234:member:user:9876'
CONNECTOR_ENTITLEMENT: 'entitlement:group:1234:member'
CONNECTOR_PRINCIPAL: 'user:9876'
CONNECTOR_GRANT: 'group:local-group:ADMIN:user:62'
CONNECTOR_ENTITLEMENT: 'group:local-group:ADMIN'
CONNECTOR_PRINCIPAL_TYPE: 'user'
CONNECTOR_PRINCIPAL: '62'
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.22.x
- name: Checkout code
uses: actions/checkout@v4
# Install any dependencies here (or delete this)
# - name: Install postgres client
# run: sudo apt install postgresql-client
# Run any fixture setup here (or delete this)
# - name: Import sql into postgres
# run: psql -h localhost --user postgres -f environment.sql
# env:
# PGPASSWORD: secretpassword
- name: Build baton-bitbucket-datacenter
run: go build ./cmd/baton-bitbucket-datacenter
- name: Run baton-bitbucket-datacenter
run: ./baton-bitbucket-datacenter

- name: Install baton
run: ./scripts/get-baton.sh && mv baton /usr/local/bin

- name: Check for grant before revoking

run:
baton grants --entitlement="${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status ".grants[].principal.id.resource == \"${{ env.CONNECTOR_PRINCIPAL }}\""


- name: Revoke grants
run: ./baton-bitbucket-datacenter --revoke-grant="${{ env.CONNECTOR_GRANT }}"

- name: Check grant was revoked
run: ./baton-bitbucket-datacenter && baton grants --entitlement="${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status "if .grants then .grants[]?.principal.id.resource != \"${{ env.CONNECTOR_PRINCIPAL }}\" else . end"

- name: Grant entitlement
# Change the grant arguments to the correct IDs for your test data
run: ./baton-bitbucket-datacenter --grant-entitlement="${{ env.CONNECTOR_ENTITLEMENT }}" --grant-principal="${{ env.CONNECTOR_PRINCIPAL }}" --grant-principal-type="${{ env.CONNECTOR_PRINCIPAL_TYPE }}"

- name: Check grant was re-granted

run:
baton grants --entitlement="${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status ".grants[].principal.id.resource == \"${{ env.CONNECTOR_PRINCIPAL }}\""

- name: Build baton-bitbucket-datacenter
run: go build ./cmd/baton-bitbucket-datacenter
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ linters-settings:
linters:
disable-all: true
enable:
- deadcode # Finds unused code
# - deadcode # Finds unused code
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
- gosimple # Linter for Go source code that specializes in simplifying a code
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # Detects when assignments to existing variables are not used
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
- unused # Checks Go code for unused constants, variables, functions and types
- varcheck # Finds unused global variables and constants
# - varcheck # Finds unused global variables and constants
- asasalint # Check for pass []any as any in variadic func(...any)
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
- bidichk # Checks for dangerous unicode character sequences
- 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
# - 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
Expand Down
88 changes: 85 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,85 @@
# baton-bitbucket-datacenter
Welcome to your new connector! To start out, you will want to update the dependencies.
Do this by running `make update-deps`.

# `baton-bitbucket-datacenter` [![Go Reference](https://pkg.go.dev/badge/github.com/conductorone/baton-bitbucket.svg)](https://pkg.go.dev/github.com/conductorone/baton-bitbucket) ![main ci](https://github.com/conductorone/baton-zendesk/actions/workflows/main.yaml/badge.svg)

`baton-bitbucket-datacenter` is a connector for Bitbucket built using the [Baton SDK](https://github.com/conductorone/baton-sdk). It communicates with the Bitbucket User provisioning API to sync data about user groups, users, projects and their repositories.

Check out [Baton](https://github.com/conductorone/baton) to learn more about the project in general.

# Prerequisites

To work with the connector, you can use basic authentication, with a username and password.

Each one of these methods are configurable with permissions (Read, Write, Admin) to access the Bitbucket API. The permissions required for this connector are:
- Read: `Group`, `User`, `Project`, `Repository`
- Admin: `Project`, `Repository`

# Getting Started

## brew

```
brew install conductorone/baton/baton conductorone/baton/baton-bitbucket-datacenter
BATON_BITBUCKETDC_USERNAME=bitbucketdc-username BATON_BITBUCKETDC_PASSWORD=bitbucketdc-password BATON_BITBUCKETDC_BASE_URL=bitbucketdc-baseurl baton-bitbucket-datacenter
baton resources
```

## docker

```
docker run --rm -v $(pwd):/out -e BATON_BITBUCKETDC_USERNAME=bitbucketdc-username BATON_BITBUCKETDC_PASSWORD=bitbucketdc-password BATON_BITBUCKETDC_BASE_URL=bitbucketdc-baseurl ghcr.io/conductorone/baton-bitbucket-datacenter:latest -f "/out/sync.c1z"
docker run --rm -v $(pwd):/out ghcr.io/conductorone/baton:latest -f "/out/sync.c1z" resources
```

## source

```
go install github.com/conductorone/baton/cmd/baton@main
go install github.com/conductorone/baton-bitbucket-datacenter/cmd/baton-bitbucket-datacenter@main
BATON_BITBUCKETDC_USERNAME=bitbucketdc-username BATON_BITBUCKETDC_PASSWORD=bitbucketdc-password BATON_BITBUCKETDC_BASE_URL=bitbucketdc-baseurl baton-bitbucket-datacenter
baton resources
```

# Data Model

`baton-bitbucket-datacenter` will pull down information about the following Bitbucket resources:

- Groups
- Users
- Projects
- Repositories

# Contributing, Support and Issues

We started Baton because we were tired of taking screenshots and manually building spreadsheets. We welcome contributions, and ideas, no matter how small -- our goal is to make identity and permissions sprawl less painful for everyone. If you have questions, problems, or ideas: Please open a Github Issue!

See [CONTRIBUTING.md](https://github.com/ConductorOne/baton/blob/main/CONTRIBUTING.md) for more details.

# `baton-bitbucket-datacenter` Command Line Usage

```
baton-bitbucket-datacenter

Usage:
baton-bitbucket-datacenter [flags]
baton-bitbucket-datacenter [command]

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

Flags:
--bitbucketdc-baseurl string Bitbucket Data Center server. example http://localhost:7990. ($BATON_BITBUCKETDC_BASE_URL)
--bitbucketdc-password string Application password used to connect to the BitBucket(dc) API. ($BATON_BITBUCKETDC_PASSWORD)
--bitbucketdc-username string Username of administrator used to connect to the BitBucket(dc) API. ($BATON_BITBUCKETDC_USERNAME)
--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)
-f, --file string The path to the c1z file to sync with ($BATON_FILE) (default "sync.c1z")
-h, --help help for baton-bitbucket-datacenter
--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")
-p, --provisioning This must be set in order for provisioning actions to be enabled. ($BATON_PROVISIONING)
-v, --version version for baton-bitbucket-datacenter

Use "baton-bitbucket-datacenter [command] --help" for more information about a command.
```
41 changes: 41 additions & 0 deletions baton_capabilities.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
{
"@type": "type.googleapis.com/c1.connector.v2.ConnectorCapabilities",
"resourceTypeCapabilities": [
{
"resourceType": {
"id": "group",
"displayName": "Group",
"traits": [
"TRAIT_GROUP"
]
},
"capabilities": [
"CAPABILITY_SYNC",
"CAPABILITY_PROVISION"
]
},
{
"resourceType": {
"id": "project",
"displayName": "Project",
"traits": [
"TRAIT_GROUP"
]
},
"capabilities": [
"CAPABILITY_SYNC",
"CAPABILITY_PROVISION"
]
},
{
"resourceType": {
"id": "repository",
"displayName": "Repository"
},
"capabilities": [
"CAPABILITY_SYNC",
"CAPABILITY_PROVISION"
]
},
{
"resourceType": {
"id": "user",
"displayName": "User",
"traits": [
"TRAIT_USER"
],
"annotations": [
{
"@type": "type.googleapis.com/c1.connector.v2.SkipEntitlementsAndGrants"
}
]
},
"capabilities": [
Expand Down
22 changes: 21 additions & 1 deletion cmd/baton-bitbucket-datacenter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,36 @@ package main

import (
"context"
"fmt"

"github.com/conductorone/baton-sdk/pkg/cli"
"github.com/spf13/cobra"
)

// config defines the external configuration required for the connector to run.
type config struct {
cli.BaseConfig `mapstructure:",squash"` // Puts the base config options in the same place as the connector options
cli.BaseConfig `mapstructure:",squash"` // Puts the base config options in the same place as the connector options
BitbucketUsername string `mapstructure:"bitbucketdc-username"`
BitbucketPassword string `mapstructure:"bitbucketdc-password"`
BitbucketBaseUrl string `mapstructure:"bitbucketdc-baseurl"`
}

// validateConfig is run after the configuration is loaded, and should return an error if it isn't valid.
func validateConfig(ctx context.Context, cfg *config) error {
if cfg.BitbucketBaseUrl == "" {
return fmt.Errorf("bitbucketdc-baseurl must be provided")
}

if cfg.BitbucketUsername == "" && cfg.BitbucketPassword == "" {
return fmt.Errorf("either bitbucketdc-username or bitbucketdc-password must be provided")
}

return nil
}

// cmdFlags sets the cmdFlags required for the connector.
func cmdFlags(cmd *cobra.Command) {
cmd.PersistentFlags().String("bitbucketdc-username", "", "Username of administrator used to connect to the BitBucket(dc) API. ($BATON_BITBUCKETDC_USERNAME)")
cmd.PersistentFlags().String("bitbucketdc-password", "", "Application password used to connect to the BitBucket(dc) API. ($BATON_BITBUCKETDC_PASSWORD)")
cmd.PersistentFlags().String("bitbucketdc-baseurl", "", "Bitbucket Data Center server. example http://localhost:7990. ($BATON_BITBUCKETDC_BASE_URL)")
}
8 changes: 6 additions & 2 deletions cmd/baton-bitbucket-datacenter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func main() {
}

cmd.Version = version
cmdFlags(cmd)

err = cmd.Execute()
if err != nil {
Expand All @@ -37,8 +38,11 @@ func main() {

func getConnector(ctx context.Context, cfg *config) (types.ConnectorServer, error) {
l := ctxzap.Extract(ctx)

cb, err := connector.New(ctx)
cb, err := connector.New(ctx,
cfg.BitbucketUsername,
cfg.BitbucketPassword,
cfg.BitbucketBaseUrl,
)
if err != nil {
l.Error("error creating connector", zap.Error(err))
return nil, err
Expand Down
Loading
Loading