Skip to content

Commit

Permalink
Merge pull request #32 from ConductorOne/marcos/ref/config-schema-0
Browse files Browse the repository at this point in the history
feat: Config Schema
  • Loading branch information
ggreer authored Oct 17, 2024
2 parents 784224d + a70df15 commit d3a3013
Show file tree
Hide file tree
Showing 689 changed files with 664,144 additions and 77,690 deletions.
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@v3
- name: Run linters
uses: golangci/golangci-lint-action@v3
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@v3
- 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@v3
- name: Run linters
uses: golangci/golangci-lint-action@v3
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@v3
- 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
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Check out [Baton](https://github.com/conductorone/baton) to learn more the proje

## Prerequisites

1. Create a Slack app. You can follow [this guide](https://api.slack.com/authentication/basics).
1. Create a Slack app. You can follow [this Slack quickstart guide](https://api.slack.com/authentication/basics).
2. Set needed Bot Token Scopes for the app:
- channels:join
- channels:read
Expand All @@ -19,16 +19,24 @@ Check out [Baton](https://github.com/conductorone/baton) to learn more the proje
3. Install the app to your workspace.
4. Use Bot User OAuth Token as token in `baton-slack`.

For the enterprise grid plan the same rules apply for creating an app. There is a difference in setting scopes, for applications that will be installed on organization level, User Token Scopes should be set as well as bot scopes. User Token is used for Admin API needed to sync additional resources in the enterprise.
For the enterprise grid plan the same rules apply for creating an app. There is
a difference in setting scopes, for applications that will be installed on
organization level, User Token Scopes should be set as well as bot scopes. User
Token is used for Admin API needed to sync additional resources in the enterprise.
Additional scopes for User Token are:
- admin
- admin.roles:read
- admin.teams:read
- admin.usergroups:read
- admin.users:read

Other difference is in the way the application is installed, on enterprise grid app should be installed on the Organization level and on all the Workspaces from which you want to sync the resources. The installation has to be done by Admin or Owner of an Enterprise Grid organization. More info with an example [here](https://api.slack.com/methods/admin.teams.list#markdown).
To work with Enterprise Grid APIs use User OAuth Token passed as `--enterprise-token` along with the Bot User OAuth Token passed via `--token` flag.
Other difference is in the way the application is installed, on enterprise grid
app should be installed on the Organization level and on all the Workspaces from
which you want to sync the resources. The installation has to be done by Admin
or Owner of an Enterprise Grid organization. More info with an example is
available in the [Slack API Docs](https://api.slack.com/methods/admin.teams.list#markdown).
To work with Enterprise Grid APIs use User OAuth Token passed as
`--enterprise-token` along with the Bot User OAuth Token passed via `--token` flag.


## brew
Expand Down Expand Up @@ -71,11 +79,15 @@ Enterprise grid additional resources:
With SSO configured (enterprise grid):
- IDP groups

If you have SSO configured for your enterprise grid organization you can also sync IDP groups and provision them. Just pass the --sso-enabled=true flag.
If you have SSO configured for your enterprise grid organization you can also
sync IDP groups and provision them. Just pass the `--sso-enabled=true` flag.

# 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!
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.

Expand All @@ -96,14 +108,16 @@ Available Commands:
Flags:
--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)
--enterprise-token string The Slack user oauth token used to connect to the Slack Enterprise Grid Admin API. ($BATON_ENTERPRISE_TOKEN)
--enterprise-token string The Slack user oauth token used to connect to the Slack Enterprise Grid Admin API ($BATON_ENTERPRISE_TOKEN)
-f, --file string The path to the c1z file to sync with ($BATON_FILE) (default "sync.c1z")
-h, --help help for baton-slack
--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)
--sso-enabled string Flag indicating that the SSO has been configured for Enterprise Grid Organization. Enables usage of SCIM API. ($BATON_SSO_ENABLED)
--token string The Slack bot user oauth token used to connect to the Slack API. ($BATON_TOKEN)
-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)
--sso-enabled Flag indicating that the SSO has been configured for Enterprise Grid Organization. Enables usage of SCIM API ($BATON_SSO_ENABLED)
--ticketing This must be set to enable ticketing support ($BATON_TICKETING)
--token string required: The Slack bot user oauth token used to connect to the Slack API ($BATON_TOKEN)
-v, --version version for baton-slack
Use "baton-slack [command] --help" for more information about a command.
Expand Down
49 changes: 22 additions & 27 deletions cmd/baton-slack/config.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
package main

import (
"context"
"fmt"

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

// 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
AccessToken string `mapstructure:"token"`
EnterpriseToken string `mapstructure:"enterprise-token"`
SSOEnabled bool `mapstructure:"sso-enabled"`
}

// 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.AccessToken == "" {
return fmt.Errorf("access token is missing")
}
var (
AccessTokenField = field.StringField(
"token",
field.WithDescription("The Slack bot user oauth token used to connect to the Slack API"),
field.WithRequired(true),
)
EnterpriseTokenField = field.StringField(
"enterprise-token",
field.WithDescription("The Slack user oauth token used to connect to the Slack Enterprise Grid Admin API"),
)
SSOEnabledField = field.BoolField(
"sso-enabled",
field.WithDescription("Flag indicating that the SSO has been configured for Enterprise Grid Organization. Enables usage of SCIM API"),
field.WithDefaultValue(false),
)

return nil
}

// cmdFlags sets the cmdFlags required for the connector.
func cmdFlags(cmd *cobra.Command) {
cmd.PersistentFlags().String("token", "", "The Slack bot user oauth token used to connect to the Slack API. ($BATON_TOKEN)")
cmd.PersistentFlags().String("enterprise-token", "", "The Slack user oauth token used to connect to the Slack Enterprise Grid Admin API. ($BATON_ENTERPRISE_TOKEN)")
cmd.PersistentFlags().String("sso-enabled", "", "Flag indicating that the SSO has been configured for Enterprise Grid Organization. Enables usage of SCIM API. ($BATON_SSO_ENABLED)")
}
Configuration = field.NewConfiguration([]field.SchemaField{
AccessTokenField,
EnterpriseTokenField,
SSOEnabledField,
})
)
26 changes: 19 additions & 7 deletions cmd/baton-slack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,35 @@ import (
"fmt"
"os"

"github.com/conductorone/baton-sdk/pkg/cli"
"github.com/conductorone/baton-sdk/pkg/config"
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
"github.com/conductorone/baton-sdk/pkg/types"
"github.com/conductorone/baton-slack/pkg/connector"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"github.com/spf13/viper"
"go.uber.org/zap"
)

var version = "dev"
var (
connectorName = "baton-slack"
version = "dev"
)

func main() {
ctx := context.Background()

cfg := &config{}
cmd, err := cli.NewCmd(ctx, "baton-slack", cfg, validateConfig, getConnector)
_, cmd, err := config.DefineConfiguration(
ctx,
connectorName,
getConnector,
Configuration,
)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}

cmd.Version = version
cmdFlags(cmd)

err = cmd.Execute()
if err != nil {
Expand All @@ -35,9 +42,14 @@ func main() {
}
}

func getConnector(ctx context.Context, cfg *config) (types.ConnectorServer, error) {
func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, error) {
l := ctxzap.Extract(ctx)
cb, err := connector.New(ctx, cfg.AccessToken, cfg.EnterpriseToken, cfg.SSOEnabled)
cb, err := connector.New(
ctx,
v.GetString(AccessTokenField.FieldName),
v.GetString(EnterpriseTokenField.FieldName),
v.GetBool(SSOEnabledField.FieldName),
)
if err != nil {
l.Error("error creating connector", zap.Error(err))
return nil, err
Expand Down
91 changes: 48 additions & 43 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,94 +1,99 @@
module github.com/conductorone/baton-slack

go 1.20
go 1.21

toolchain go1.23.0

require (
github.com/conductorone/baton-sdk v0.1.21
github.com/conductorone/baton-sdk v0.2.28
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/slack-go/slack v0.13.1
github.com/spf13/cobra v1.8.0
go.uber.org/zap v1.26.0
google.golang.org/protobuf v1.32.0
github.com/slack-go/slack v0.14.0
github.com/spf13/viper v1.18.2
go.uber.org/zap v1.27.0
google.golang.org/protobuf v1.34.2
)

require (
filippo.io/age v1.1.1 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.25.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.0 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.0 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.0 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.0 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.0 // indirect
github.com/allegro/bigcache/v3 v3.1.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.26.1 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.11 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.11 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.1 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.15 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.5 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.0 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.49.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.19.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.22.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.27.0 // indirect
github.com/aws/smithy-go v1.20.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.5 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect
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/deckarep/golang-set/v2 v2.6.0 // indirect
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/fsnotify/fsnotify v1.7.0 // indirect
github.com/glebarez/go-sqlite v1.22.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.1 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
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.6 // indirect
github.com/lufia/plan9stats v0.0.0-20231016141302-07b5767bb0ed // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/lufia/plan9stats v0.0.0-20240408141607-282e7b5d6b74 // 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/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/pquerna/xjwt v0.2.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/segmentio/ksuid v1.0.4 // indirect
github.com/shirou/gopsutil/v3 v3.24.1 // indirect
github.com/shirou/gopsutil/v3 v3.24.4 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
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.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.13 // indirect
github.com/tklauser/numcpus v0.7.0 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/ratelimit v0.3.0 // indirect
go.uber.org/ratelimit v0.3.1 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/grpc v1.61.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240506185236-b8a5c65736ae // indirect
google.golang.org/grpc v1.63.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
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.41.0 // indirect
modernc.org/libc v1.50.5 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/sqlite v1.29.1 // indirect
modernc.org/memory v1.8.0 // indirect
modernc.org/sqlite v1.29.9 // indirect
)
Loading

0 comments on commit d3a3013

Please sign in to comment.