Skip to content

Commit 2c4c475

Browse files
authored
Add capabilities generation and CI to github workflows. (#13)
Upgrade baton-sdk.
1 parent fe659cd commit 2c4c475

File tree

25 files changed

+761
-111
lines changed

25 files changed

+761
-111
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Generate connector capabilities
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
calculate-capabilities:
10+
env:
11+
BATON_DSN: server=127.0.0.1;user id=sa;password=devP@ssw0rd;port=1433
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
token: ${{ secrets.RELENG_GITHUB_TOKEN }}
19+
20+
- name: Setup Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version-file: 'go.mod'
24+
25+
- name: Build
26+
run: go build -o connector ./cmd/baton-sql-server
27+
28+
- name: Run Docker Compose as a Daemon (to start sql server)
29+
run: docker-compose -f ./docker-compose.yml up --detach
30+
31+
- name: Run and save output
32+
run: ./connector capabilities > baton_capabilities.json
33+
34+
- name: Commit changes
35+
uses: EndBug/add-and-commit@v9
36+
with:
37+
default_author: github_actions
38+
message: 'Updating baton capabilities.'
39+
add: 'baton_capabilities.json'

.github/workflows/ci.yaml

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ jobs:
55
runs-on: ubuntu-latest
66
steps:
77
- name: Install Go
8-
uses: actions/setup-go@v4
8+
uses: actions/setup-go@v5
99
with:
1010
go-version: 1.22.x
1111
- name: Checkout code
12-
uses: actions/checkout@v3
12+
uses: actions/checkout@v4
1313
- name: Run linters
1414
uses: golangci/golangci-lint-action@v3
1515
with:
@@ -24,15 +24,61 @@ jobs:
2424
steps:
2525
- name: Install Go
2626
if: success()
27-
uses: actions/setup-go@v4
27+
uses: actions/setup-go@v5
2828
with:
2929
go-version: ${{ matrix.go-version }}
3030
- name: Checkout code
31-
uses: actions/checkout@v3
31+
uses: actions/checkout@v4
3232
- name: go tests
3333
run: go test -v -covermode=count -json ./... > test.json
3434
- name: annotate go tests
3535
if: always()
3636
uses: guyarb/[email protected]
3737
with:
38-
test-results: test.json
38+
test-results: test.json
39+
test:
40+
runs-on: ubuntu-latest
41+
env:
42+
BATON_LOG_LEVEL: debug
43+
# Add any environment variables needed to run baton-sql-server
44+
BATON_DSN: server=127.0.0.1;user id=sa;password=devP@ssw0rd;port=1433
45+
# The following parameters are passed to grant/revoke commands
46+
CONNECTOR_GRANT: 'database-role:msdb:6:member:user:257'
47+
CONNECTOR_ENTITLEMENT: 'database-role:msdb:6:member'
48+
CONNECTOR_PRINCIPAL_TYPE: 'user'
49+
CONNECTOR_PRINCIPAL: '257'
50+
steps:
51+
- name: Install Go
52+
uses: actions/setup-go@v5
53+
with:
54+
go-version: 1.22.x
55+
- name: Checkout code
56+
uses: actions/checkout@v4
57+
- name: Run Docker Compose as a Daemon (to start sql server)
58+
run: docker-compose -f ./docker-compose.yml up --detach
59+
- name: Install baton
60+
run: ./scripts/get-baton.sh && mv baton /usr/local/bin
61+
- name: Build baton-sql-server
62+
run: go build ./cmd/baton-sql-server
63+
- name: Run baton-sql-server
64+
run: ./baton-sql-server
65+
- name: Check for grant before revoking
66+
run: |
67+
./baton-sql-server
68+
baton grants --entitlement="${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status ".grants[].principal.id.resource == \"${{ env.CONNECTOR_PRINCIPAL }}\""
69+
# - name: Revoke grants
70+
# run: |
71+
# ./baton-sql-server
72+
# ./baton-sql-server --revoke-grant ${{ env.CONNECTOR_GRANT }}
73+
# - name: Check grant was revoked
74+
# run: |
75+
# ./baton-sql-server
76+
# baton grants --entitlement="${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status "if .grants then .grants[]?.principal.id.resource != \"${{ env.CONNECTOR_PRINCIPAL }}\" else . end"
77+
# - name: Grant entitlement
78+
# run: |
79+
# ./baton-sql-server
80+
# ./baton-sql-server --grant-entitlement ${{ env.CONNECTOR_ENTITLEMENT }} --grant-principal-type ${{ env.CONNECTOR_PRINCIPAL_TYPE }} --grant-principal ${{ env.CONNECTOR_PRINCIPAL }} --provisioning
81+
# - name: Check grant was re-granted
82+
# run: |
83+
# ./baton-sql-server
84+
# baton grants --entitlement ${{ env.CONNECTOR_ENTITLEMENT }} --output-format=json | jq -e ".grants | any(.principal.id.resource ==\"${{ env.CONNECTOR_PRINCIPAL }}\")"

.github/workflows/main.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Install Go
11-
uses: actions/setup-go@v4
11+
uses: actions/setup-go@v5
1212
with:
1313
go-version: 1.22.x
1414
- name: Checkout code
@@ -27,7 +27,7 @@ jobs:
2727
steps:
2828
- name: Install Go
2929
if: success()
30-
uses: actions/setup-go@v4
30+
uses: actions/setup-go@v5
3131
with:
3232
go-version: ${{ matrix.go-version }}
3333
- name: Checkout code

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
with:
1515
fetch-depth: 0
1616
- name: Set up Go
17-
uses: actions/setup-go@v4
17+
uses: actions/setup-go@v5
1818
with:
1919
go-version: 1.22.x
2020
- name: Set up Gon
@@ -41,7 +41,7 @@ jobs:
4141
with:
4242
fetch-depth: 0
4343
- name: Set up Go
44-
uses: actions/setup-go@v4
44+
uses: actions/setup-go@v5
4545
with:
4646
go-version: 1.22.x
4747
- name: Docker Login

cmd/baton-sql-server/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ var (
1414
field.WithRequired(true))
1515
)
1616

17+
var cfg = field.Configuration{
18+
Fields: []field.SchemaField{dsn},
19+
}
20+
1721
// validateConfig is run after the configuration is loaded, and should return an error if it isn't valid.
1822
func validateConfig(_ context.Context, v *viper.Viper) error {
1923
if v.GetString(dsn.FieldName) == "" {

cmd/baton-sql-server/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
config "github.com/conductorone/baton-sdk/pkg/config"
99
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
10-
"github.com/conductorone/baton-sdk/pkg/field"
1110
"github.com/conductorone/baton-sdk/pkg/types"
1211
"github.com/conductorone/baton-sql-server/pkg/connector"
1312
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
@@ -20,7 +19,7 @@ var version = "dev"
2019
func main() {
2120
ctx := context.Background()
2221

23-
_, cmd, err := config.DefineConfiguration(ctx, "baton-sql-server", getConnector, []field.SchemaField{dsn}, nil)
22+
_, cmd, err := config.DefineConfiguration(ctx, "baton-sql-server", getConnector, cfg)
2423
if err != nil {
2524
fmt.Fprintln(os.Stderr, err.Error())
2625
os.Exit(1)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/conductorone/baton-sql-server
33
go 1.21
44

55
require (
6-
github.com/conductorone/baton-sdk v0.2.1
6+
github.com/conductorone/baton-sdk v0.2.7
77
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
88
github.com/jmoiron/sqlx v1.3.5
99
github.com/microsoft/go-mssqldb v1.3.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZx
5454
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
5555
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
5656
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
57-
github.com/conductorone/baton-sdk v0.2.1 h1:Ft46eoVFO3q3Op/G65dcqubZe2pw/44GcpD+KnaVyq8=
58-
github.com/conductorone/baton-sdk v0.2.1/go.mod h1:cg5FyUcJnD7xK5SPbHe/KNpwUVVlpHJ9rnmd3UwxSkU=
57+
github.com/conductorone/baton-sdk v0.2.7 h1:mzp7H0zVeZLMvdGj3Yx31mpzM6ytNKI6QmpzRuiPlVE=
58+
github.com/conductorone/baton-sdk v0.2.7/go.mod h1:cg5FyUcJnD7xK5SPbHe/KNpwUVVlpHJ9rnmd3UwxSkU=
5959
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
6060
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6161
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

scripts/get-baton.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
6+
ARCH=$(uname -m)
7+
if [ "${ARCH}" = "x86_64" ]; then
8+
ARCH="amd64"
9+
fi
10+
11+
RELEASES_URL="https://api.github.com/repos/conductorone/baton/releases/latest"
12+
BASE_URL="https://github.com/conductorone/baton/releases/download"
13+
14+
DOWNLOAD_URL=$(curl "${RELEASES_URL}" | jq --raw-output ".assets[].browser_download_url | match(\"${BASE_URL}/v[.0-9]+/baton-v[.0-9]+-${OS}-${ARCH}.*\"; \"i\").string")
15+
16+
FILENAME=$(basename ${DOWNLOAD_URL})
17+
18+
curl -LO ${DOWNLOAD_URL}
19+
tar xzf ${FILENAME}

vendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_external_ticket.pb.go

Lines changed: 148 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)