Skip to content

Commit dbec6de

Browse files
authored
Merge pull request #1 from ConductorOne/goldschmidt/workato-connector
Implement baton-workato Connector
2 parents de1b6e0 + cca67dc commit dbec6de

Some content is hidden

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

43 files changed

+3111
-149
lines changed

.github/workflows/ci.yaml

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818
go-test:
1919
strategy:
2020
matrix:
21-
go-version: [1.22.x]
22-
platform: [ubuntu-latest]
21+
go-version: [ 1.22.x ]
22+
platform: [ ubuntu-latest ]
2323
runs-on: ${{ matrix.platform }}
2424
steps:
2525
- name: Install Go
@@ -37,68 +37,41 @@ jobs:
3737
with:
3838
test-results: test.json
3939

40-
test:
40+
test-provisioning:
41+
needs:
42+
- go-lint
43+
- go-test
4144
runs-on: ubuntu-latest
42-
# Define any services needed for the test suite (or delete this section)
43-
# services:
44-
# postgres:
45-
# image: postgres:16
46-
# ports:
47-
# - "5432:5432"
48-
# env:
49-
# POSTGRES_PASSWORD: secretpassword
45+
strategy:
46+
fail-fast: true
47+
matrix:
48+
test-case: [ roles ]
49+
5050
env:
5151
BATON_LOG_LEVEL: debug
52-
# Add any environment variables needed to run baton-workato
53-
# BATON_BASE_URL: 'http://localhost:8080'
54-
# BATON_ACCESS_TOKEN: 'secret_token'
55-
# The following parameters are passed to grant/revoke commands
56-
# Change these to the correct IDs for your test data
57-
CONNECTOR_GRANT: 'grant:entitlement:group:1234:member:user:9876'
58-
CONNECTOR_ENTITLEMENT: 'entitlement:group:1234:member'
59-
CONNECTOR_PRINCIPAL: 'user:9876'
60-
CONNECTOR_PRINCIPAL_TYPE: 'user'
52+
CONNECTOR_PRINCIPAL: "${{ secrets.CONNECTOR_PRINCIPAL }}"
53+
BATON_WORKATO_API_KEY: ${{ secrets.BATON_WORKATO_API_KEY }}
54+
BATON_CONNECTOR: ./baton-workato
55+
BATON_WORKATO_ENV: dev
56+
6157
steps:
6258
- name: Install Go
6359
uses: actions/setup-go@v5
6460
with:
6561
go-version: 1.22.x
6662
- name: Checkout code
6763
uses: actions/checkout@v4
68-
# Install any dependencies here (or delete this)
69-
# - name: Install postgres client
70-
# run: sudo apt install postgresql-client
71-
# Run any fixture setup here (or delete this)
72-
# - name: Import sql into postgres
73-
# run: psql -h localhost --user postgres -f environment.sql
74-
# env:
75-
# PGPASSWORD: secretpassword
76-
- name: Build baton-workato
77-
run: go build ./cmd/baton-workato
78-
- name: Run baton-workato
79-
run: ./baton-workato
8064

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

84-
- name: Check for grant before revoking
85-
86-
run:
87-
baton grants --entitlement="${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status ".grants[].principal.id.resource == \"${{ env.CONNECTOR_PRINCIPAL }}\""
88-
89-
90-
- name: Revoke grants
91-
run: ./baton-workato --revoke-grant="${{ env.CONNECTOR_GRANT }}"
92-
93-
- name: Check grant was revoked
94-
run: ./baton-workato && baton grants --entitlement="${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status "if .grants then .grants[]?.principal.id.resource != \"${{ env.CONNECTOR_PRINCIPAL }}\" else . end"
95-
96-
- name: Grant entitlement
97-
# Change the grant arguments to the correct IDs for your test data
98-
run: ./baton-workato --grant-entitlement="${{ env.CONNECTOR_ENTITLEMENT }}" --grant-principal="${{ env.CONNECTOR_PRINCIPAL }}" --grant-principal-type="${{ env.CONNECTOR_PRINCIPAL_TYPE }}"
99-
100-
- name: Check grant was re-granted
101-
102-
run:
103-
baton grants --entitlement="${{ env.CONNECTOR_ENTITLEMENT }}" --output-format=json | jq --exit-status ".grants[].principal.id.resource == \"${{ env.CONNECTOR_PRINCIPAL }}\""
68+
- name: Build baton-workato
69+
run: go build ./cmd/baton-workato
10470

71+
- name: Run tests for ${{ matrix.test-case }}
72+
run: |
73+
case "${{ matrix.test-case }}" in
74+
"roles")
75+
BATON_SKIP_REVOKE=1 ./scripts/validate-grant.sh ${{ env.CONNECTOR_PRINCIPAL }} collaborator role:Operator:collaborator-has role:Operator:collaborator-has:collaborator:${{ env.CONNECTOR_PRINCIPAL }}
76+
;;
77+
esac

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ linters-settings:
2929
rules:
3030
- name: atomic
3131
- name: line-length-limit
32-
arguments: [ 200 ]
32+
arguments: [ 300 ]
3333
# These are functions that we use without checking the errors often. Most of these can't return an error even
3434
# though they implement an interface that can.
3535
- name: unhandled-error

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
![Baton Logo](./baton-logo.png)
22

3-
# `baton-workato` [![Go Reference](https://pkg.go.dev/badge/github.com/conductorone/baton-workato.svg)](https://pkg.go.dev/github.com/conductorone/baton-workato) ![main ci](https://github.com/conductorone/baton-workato/actions/workflows/main.yaml/badge.svg)
3+
#
4+
5+
`baton-workato` [![Go Reference](https://pkg.go.dev/badge/github.com/conductorone/baton-workato.svg)](https://pkg.go.dev/github.com/conductorone/baton-workato) ![main ci](https://github.com/conductorone/baton-workato/actions/workflows/main.yaml/badge.svg)
46

57
`baton-workato` is a connector for built using the [Baton SDK](https://github.com/conductorone/baton-sdk).
68

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

911
# Getting Started
1012

13+
## Prerequisites
14+
15+
You need to pass the workato-api-key:
16+
17+
1. Create an Workato Account.
18+
2. Create an API KEY https://app.workato.com/members/api/clients.
19+
3. Run it.
20+
21+
Obs: if you have a basic account, you can ignore the subusers using.
22+
1123
## brew
1224

1325
```
@@ -37,6 +49,7 @@ baton resources
3749
# Data Model
3850

3951
`baton-workato` will pull down information about the following resources:
52+
4053
- Users
4154

4255
# Contributing, Support and Issues
@@ -69,9 +82,10 @@ Flags:
6982
-h, --help help for baton-workato
7083
--log-format string The output format for logs: json, console ($BATON_LOG_FORMAT) (default "json")
7184
--log-level string The log level: debug, info, warn, error ($BATON_LOG_LEVEL) (default "info")
72-
-p, --provisioning If this connector supports provisioning, this must be set in order for provisioning actions to be enabled ($BATON_PROVISIONING)
85+
-p, --provisioning This must be set in order for provisioning actions to be enabled ($BATON_PROVISIONING)
86+
--skip-full-sync This must be set to skip a full sync ($BATON_SKIP_FULL_SYNC)
7387
--ticketing This must be set to enable ticketing support ($BATON_TICKETING)
7488
-v, --version version for baton-workato
75-
76-
Use "baton-workato [command] --help" for more information about a command.
89+
--workato-api-key string required: Your workato API key ($BATON_WORKATO_API_KEY)
90+
--workato-data-center string Your workato data center (us, eu, jp, sg, au) default is 'us' see more on https://docs.workato.com/workato-api.html#base-url ($BATON_WORKATO_DATA_CENTER) (default "us")
7791
```

baton_capabilities.json

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,60 @@
11
{
2-
"@type": "type.googleapis.com/c1.connector.v2.ConnectorCapabilities",
3-
"resourceTypeCapabilities": [
2+
"@type": "type.googleapis.com/c1.connector.v2.ConnectorCapabilities",
3+
"resourceTypeCapabilities": [
44
{
5-
"resourceType": {
6-
"id": "user",
7-
"displayName": "User",
8-
"traits": [
5+
"resourceType": {
6+
"id": "collaborator",
7+
"displayName": "Collaborator",
8+
"traits": [
99
"TRAIT_USER"
1010
]
1111
},
12-
"capabilities": [
12+
"capabilities": [
13+
"CAPABILITY_SYNC"
14+
]
15+
},
16+
{
17+
"resourceType": {
18+
"id": "folder",
19+
"displayName": "Folder"
20+
},
21+
"capabilities": [
22+
"CAPABILITY_SYNC"
23+
]
24+
},
25+
{
26+
"resourceType": {
27+
"id": "privilege",
28+
"displayName": "Privilege"
29+
},
30+
"capabilities": [
31+
"CAPABILITY_SYNC"
32+
]
33+
},
34+
{
35+
"resourceType": {
36+
"id": "project",
37+
"displayName": "Project"
38+
},
39+
"capabilities": [
40+
"CAPABILITY_SYNC"
41+
]
42+
},
43+
{
44+
"resourceType": {
45+
"id": "role",
46+
"displayName": "Roles",
47+
"traits": [
48+
"TRAIT_ROLE"
49+
]
50+
},
51+
"capabilities": [
1352
"CAPABILITY_SYNC"
1453
]
1554
}
1655
],
17-
"connectorCapabilities": [
56+
"connectorCapabilities": [
1857
"CAPABILITY_SYNC"
1958
],
20-
"credentialDetails": {}
59+
"credentialDetails": {}
2160
}

cmd/baton-workato/conf/config.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package conf
2+
3+
import (
4+
"errors"
5+
6+
"github.com/conductorone/baton-workato/pkg/connector/workato"
7+
8+
"github.com/conductorone/baton-sdk/pkg/field"
9+
"github.com/conductorone/baton-workato/pkg/connector/client"
10+
"github.com/spf13/viper"
11+
)
12+
13+
var (
14+
ApiKeyField = field.StringField(
15+
"workato-api-key",
16+
field.WithRequired(true),
17+
field.WithDescription("Your workato API key"),
18+
)
19+
20+
WorkatoDataCenterFiekd = field.StringField(
21+
"workato-data-center",
22+
field.WithDescription("Your workato data center (us, eu, jp, sg, au) default is 'us' see more on https://docs.workato.com/workato-api.html#base-url"),
23+
field.WithDefaultValue("us"),
24+
)
25+
26+
WorkatoEnv = field.StringField(
27+
"workato-env",
28+
field.WithDescription("Your workato environment (dev, test, prod) default is 'dev'"),
29+
field.WithDefaultValue("dev"),
30+
)
31+
32+
// ConfigurationFields defines the external configuration required for the
33+
// connector to run. Note: these fields can be marked as optional or
34+
// required.
35+
ConfigurationFields = []field.SchemaField{
36+
ApiKeyField,
37+
WorkatoDataCenterFiekd,
38+
WorkatoEnv,
39+
}
40+
41+
// FieldRelationships defines relationships between the fields listed in
42+
// ConfigurationFields that can be automatically validated. For example, a
43+
// username and password can be required together, or an access token can be
44+
// marked as mutually exclusive from the username password pair.
45+
FieldRelationships = []field.SchemaFieldRelationship{}
46+
)
47+
48+
// ValidateConfig is run after the configuration is loaded, and should return an
49+
// error if it isn't valid. Implementing this function is optional, it only
50+
// needs to perform extra validations that cannot be encoded with configuration
51+
// parameters.
52+
func ValidateConfig(v *viper.Viper) error {
53+
if _, ok := client.WorkatoDataCenters[v.GetString(WorkatoDataCenterFiekd.FieldName)]; !ok {
54+
return errors.New("invalid workato data center")
55+
}
56+
57+
_, err := workato.EnvFromString(v.GetString(WorkatoEnv.FieldName))
58+
if err != nil {
59+
return err
60+
}
61+
62+
return nil
63+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package conf
22

33
import (
44
"testing"

cmd/baton-workato/config.go

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

cmd/baton-workato/main.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ import (
55
"fmt"
66
"os"
77

8+
"github.com/conductorone/baton-workato/pkg/connector/workato"
9+
10+
"github.com/conductorone/baton-workato/cmd/baton-workato/conf"
11+
12+
"github.com/conductorone/baton-workato/pkg/connector/client"
13+
814
"github.com/conductorone/baton-sdk/pkg/config"
915
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
1016
"github.com/conductorone/baton-sdk/pkg/field"
1117
"github.com/conductorone/baton-sdk/pkg/types"
18+
"github.com/conductorone/baton-workato/pkg/connector"
1219
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
1320
"github.com/spf13/viper"
14-
"github.com/conductorone/baton-workato/pkg/connector"
1521
"go.uber.org/zap"
1622
)
1723

@@ -25,7 +31,7 @@ func main() {
2531
"baton-workato",
2632
getConnector,
2733
field.Configuration{
28-
Fields: ConfigurationFields,
34+
Fields: conf.ConfigurationFields,
2935
},
3036
)
3137
if err != nil {
@@ -44,11 +50,24 @@ func main() {
4450

4551
func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, error) {
4652
l := ctxzap.Extract(ctx)
47-
if err := ValidateConfig(v); err != nil {
53+
if err := conf.ValidateConfig(v); err != nil {
54+
return nil, err
55+
}
56+
57+
key := v.GetString(conf.ApiKeyField.FieldName)
58+
dataCenterUrl := client.WorkatoDataCenters[v.GetString(conf.WorkatoDataCenterFiekd.FieldName)]
59+
60+
env, err := workato.EnvFromString(v.GetString(conf.WorkatoEnv.FieldName))
61+
if err != nil {
62+
return nil, err
63+
}
64+
65+
workatoClient, err := client.NewWorkatoClient(ctx, key, dataCenterUrl)
66+
if err != nil {
4867
return nil, err
4968
}
5069

51-
cb, err := connector.New(ctx)
70+
cb, err := connector.New(ctx, workatoClient, env)
5271
if err != nil {
5372
l.Error("error creating connector", zap.Error(err))
5473
return nil, err

0 commit comments

Comments
 (0)