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

Listing Users and Adding Resources #1

Merged
merged 43 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f3870a0
Adding configuration options
mchavez Feb 2, 2024
d2619bf
Adding functionality for listing users
mchavez Feb 2, 2024
0d8ac44
Adding user pagination
mchavez Feb 2, 2024
9c9213e
Adding resources
mchavez Feb 3, 2024
66d122b
Fixed golangci-lint issue
mchavez Feb 3, 2024
6498c04
Code Refactor and Updating config.go
mchavez Feb 4, 2024
063ea25
Code Refactor and Adding Groups
mchavez Feb 5, 2024
51d130f
Added go.work and vendor dependencies
mchavez Feb 5, 2024
48ead8b
Remove go.work file
mchavez Feb 5, 2024
d633bdb
Adding Functionality for getting Resources, Resources-Types, Entitlem…
mchavez Feb 6, 2024
8d2d0c7
Updating dependencies
mchavez Feb 6, 2024
5f8e07c
Including nextPageToken and Adding Comments
mchavez Feb 6, 2024
64705f3
Fixied lint issue and typo
mchavez Feb 6, 2024
d7cfaeb
Adding Roles
mchavez Feb 7, 2024
365700a
Code Refactor
mchavez Feb 7, 2024
d0bd89b
Add Config Validation
mchavez Feb 7, 2024
3a0017b
Code Refactor
mchavez Feb 7, 2024
81aebc4
Fixed MISSING ENTITLEMENT
mchavez Feb 7, 2024
b77b788
Adding Provisioning and Refactoring Code
mchavez Feb 12, 2024
24d5315
Formatting output
mchavez Feb 12, 2024
1902fbc
Remove hard code
mchavez Feb 12, 2024
cabe427
Removing unnecessary code
mchavez Feb 12, 2024
8f68640
Revoking and Deleting group Membership
mchavez Feb 12, 2024
437dae8
Adding provisioning for organizations
mchavez Feb 13, 2024
94e742d
Code Refactor
mchavez Feb 13, 2024
938fb8b
Refactog code, Removing Users and Fixing Roles
mchavez Feb 13, 2024
462fd60
Adding Provisioning for Roles
mchavez Feb 14, 2024
300c28b
Updating entitlements and grants for roles
mchavez Feb 15, 2024
d0b378e
Updating readme file
mchavez Feb 15, 2024
9f6c243
Code refactor
mchavez Feb 19, 2024
1310942
Minor Change
mchavez Feb 19, 2024
6b098e9
Minor Change
mchavez Feb 19, 2024
88f89e2
Refactoring Code and Speeding Up Groups
mchavez Feb 21, 2024
e2a70a7
Refactoring Code and Speeding Up Organizations
mchavez Feb 21, 2024
dee67df
Refactoring Code
mchavez Feb 22, 2024
12ee0f6
Refactoring Code
mchavez Feb 22, 2024
f5e4919
Refactoring Code
mchavez Feb 22, 2024
5c9c8c5
Update readme file
mchavez Feb 28, 2024
cb83aa9
Adding Github Actions tests
mchavez Feb 28, 2024
0a522c4
Update readme
mchavez Feb 28, 2024
1448059
Update readme file
mchavez Feb 28, 2024
870e389
Update README.md
mchavez Feb 28, 2024
d62a2cc
Code Review Changes
mchavez Feb 28, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
go-test:
strategy:
matrix:
go-version: [1.20.x]
go-version: [1.22.0]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
go-version: 1.22.0
- name: Checkout code
uses: actions/checkout@v3
- name: Run linters
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
go-version: 1.22.0
- name: Set up Gon
run: brew tap mitchellh/gon && brew install mitchellh/gon/gon
- name: Import Keychain Certs
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: tests
on:
workflow_dispatch:
push:
jobs:
test:
runs-on: ubuntu-latest
env:
BATON_API_TOKEN: ${{ secrets.BATON_API_TOKEN }}
BATON_SUBDOMAIN: ${{ secrets.BATON_SUBDOMAIN }}
BATON_EMAIL: ${{ secrets.BATON_EMAIL }}
BATON_LOG_LEVEL: 'debug'
# Revoke grants variable
REVOKE_GRANT: 'group:22940582375835:member:team_member:22940899051931'
# Grant entitlements variables
GRANT_ENTITLEMENT: 'group:22940582375835:member'
GRANT_PRINCIPAL: '22940899051931'
GRANT_PRINCIPAL_TYPE: 'team_member'

steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 1.22.0
- name: Checkout code
uses: actions/checkout@v3
- name: Build baton-zendesk
run: go build ./cmd/baton-zendesk
- name: Run baton-zendesk-cmd
run: ./baton-zendesk
- name: Revoke grants
if: ${{ env.REVOKE_GRANT }} != ''
run: |
echo "Syncing resources..."
./baton-zendesk
echo "Testing revoking"
./baton-zendesk --log-level=debug --revoke-grant ${{ env.REVOKE_GRANT }}
- name: Grant entitlements
if: ${{ env.GRANT_ENTITLEMENT }} != '' && ${{ env.GRANT_PRINCIPAL }} != '' && ${{ env.GRANT_PRINCIPAL_TYPE }} != ''
run: |
echo "Syncing resources..."
./baton-zendesk
echo "Testing provisioning"
./baton-zendesk --log-level=debug --grant-entitlement ${{ env.GRANT_ENTITLEMENT }} --grant-principal ${{ env.GRANT_PRINCIPAL }} --grant-principal-type ${{ env.GRANT_PRINCIPAL_TYPE }}
- name: List Resources
run: docker run --rm -v $(pwd):/out ghcr.io/conductorone/baton:latest -f "/out/sync.c1z" resources
97 changes: 94 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,94 @@
# baton-zendesk
Welcome to your new connector! To start out, you will want to update the dependencies.
Do this by running `make update-deps`.
# `baton-zendesk` [![Go Reference](https://pkg.go.dev/badge/github.com/conductorone/baton-zendesk.svg)](https://pkg.go.dev/github.com/conductorone/baton-zendesk) ![main ci](https://github.com/conductorone/baton-zendesk/actions/workflows/main.yaml/badge.svg)
`baton-zendesk` is a connector for Zendesk built using the [Baton SDK](https://github.com/conductorone/baton-sdk). It communicates with the Zendesk API to sync data about users, groups and enterprise.

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

# Getting Started
You can try out the Zendesk platform with a free, 14-day trial account. If you're interested in becoming a Zendesk developer partner, you can convert your trial account into a sponsored Zendesk Support account.

As part of becoming a Zendesk developer partner, Zendesk sponsors an instance for up to 5 agents that you can use for developing, and troubleshooting your app or integration.

Unlike a trial account, a sponsored account does not expire after 14 days.
## Prerequisites

1. Zendesk `trial account` sign up for a free Zendesk Support trial [developer site](https://www.zendesk.com/register/)
2. Authentication method set to `Token access`
3. Application Scopes:
- manage team members
- manage groups
- manage organizations
- grant resources
- revoke resources

## Requesting a sponsored test account
For a trial Support account, see
https://developer.zendesk.com/documentation/api-basics/getting-started/getting-a-trial-or-sponsored-account-for-development/#requesting-a-sponsored-test-account

## brew

```
brew install conductorone/baton/baton conductorone/baton/baton-zendesk
baton-zendesk
baton resources
```

## docker

```
docker run --rm -v $(pwd):/out -e BATON_SUBDOMAIN=clientSubdomain BATON_EMAIL=clientEmail BATON_API_TOKEN=apiToken ghcr.io/conductorone/baton-zendesk: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-zendesk/cmd/baton-zendesk@main

BATON_SUBDOMAIN=clientSubdomain BATON_EMAIL=clientEmail BATON_API_TOKEN=apiToken
baton resources
```

# Data Model

`baton-zendesk` pulls down information about the following Zendesk resources:
- Team Members
- Groups
- Organizations
- Roles

# 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, concerns, or ideas: Please open a Github Issue!

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

# `baton-zendesk` Command Line Usage

```
baton-zendesk

Usage:
baton-zendesk [flags]
baton-zendesk [command]

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

Flags:
--api-token string The Zendesk apitoken. ($BATON_API_TOKEN)
--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)
--email string The Zendesk email. ($BATON_EMAIL)
-f, --file string The path to the c1z file to sync with ($BATON_FILE) (default "sync.c1z")
-h, --help help for baton-zendesk
--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)
--subdomain string The Zendesk subdomain. ($BATON_SUBDOMAIN)
-v, --version version for baton-zendesk

Use "baton-zendesk [command] --help" for more information about a command.
```
24 changes: 24 additions & 0 deletions cmd/baton-zendesk/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,40 @@ package main

import (
"context"
"errors"

"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
Subdomain string `mapstructure:"subdomain"`
ApiToken string `mapstructure:"api-token"`
Email string `mapstructure:"email"`
Orgs []string `mapstructure:"orgs"`
}

// 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.Subdomain == "" {
return errors.New("subdomain is required")
}
if cfg.ApiToken == "" {
return errors.New("api-Token is required")
}
if cfg.Email == "" {
return errors.New("email is required")
}

mchavez marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

// cmdFlags sets the cmdFlags required for the connector.
func cmdFlags(cmd *cobra.Command) {
cmd.PersistentFlags().String("subdomain", "", "The Zendesk subdomain. ($BATON_SUBDOMAIN)")
cmd.PersistentFlags().String("api-token", "", "The Zendesk apitoken. ($BATON_API_TOKEN)")
cmd.PersistentFlags().String("email", "", "The Zendesk email. ($BATON_EMAIL)")
cmd.PersistentFlags().StringSlice("orgs", []string{}, "Limit syncing to specific organizations. ($BATON_ORGS)")
}
3 changes: 2 additions & 1 deletion cmd/baton-zendesk/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 @@ -38,7 +39,7 @@ 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.Orgs, cfg.Subdomain, cfg.Email, cfg.ApiToken)
if err != nil {
l.Error("error creating connector", zap.Error(err))
return nil, err
Expand Down
21 changes: 12 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module github.com/conductorone/baton-zendesk
go 1.20

require (
github.com/conductorone/baton-sdk v0.1.19
github.com/conductorone/baton-sdk v0.1.21
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
go.uber.org/zap v1.26.0
)

require github.com/google/go-querystring v1.1.0 // indirect

require (
filippo.io/age v1.1.1 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
Expand Down Expand Up @@ -43,12 +45,13 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.17.5 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/lufia/plan9stats v0.0.0-20231016141302-07b5767bb0ed // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/nukosuke/go-zendesk v0.18.0
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/pquerna/xjwt v0.2.0 // indirect
Expand All @@ -61,7 +64,7 @@ require (
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
Expand All @@ -70,22 +73,22 @@ require (
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/ratelimit v0.3.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240205150955-31a09d347014 // indirect
google.golang.org/grpc v1.61.0 // indirect
google.golang.org/protobuf v1.32.0 // 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
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.40.13 // indirect
modernc.org/libc v1.41.0 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/sqlite v1.28.0 // indirect
Expand Down
Loading
Loading