Skip to content

Commit 50cc4b8

Browse files
authored
Merge pull request #338 from slashdevops/fix-issue-322
Fix issue 322
2 parents fefb6f0 + fbbda22 commit 50cc4b8

File tree

4 files changed

+176
-164
lines changed

4 files changed

+176
-164
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"amzn",
44
"awsconf",
55
"AWSS",
6+
"AWSSCIM",
67
"Babs",
78
"bjensen",
89
"christiangda",
@@ -30,6 +31,7 @@
3031
"GOMODCACHE",
3132
"googleapi",
3233
"GOPATH",
34+
"gopkg",
3335
"goroot",
3436
"GOROOT",
3537
"gosec",
@@ -38,6 +40,7 @@
3840
"hashcode",
3941
"hashicorp",
4042
"idpid",
43+
"idpscim",
4144
"idpscimcli",
4245
"ietf",
4346
"Infof",
@@ -56,10 +59,12 @@
5659
"repositoryname",
5760
"Retryable",
5861
"retryablehttp",
62+
"SCIM",
5963
"scimid",
6064
"secretmanager",
6165
"securego",
6266
"sirupsen",
67+
"slashdevops",
6368
"softprops",
6469
"stackset",
6570
"stretchr",

cmd/idpscim/cmd/root.go

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import (
2727
)
2828

2929
var (
30-
cfg config.Config
30+
cfg config.Config
31+
3132
logHandler slog.Handler
3233
logHandlerOptions *slog.HandlerOptions
3334
logger *slog.Logger
@@ -111,10 +112,6 @@ func init() {
111112

112113
// initConfig reads in config file and ENV variables if set.
113114
func initConfig() {
114-
// Set the default logger
115-
logger = slog.New(logHandler)
116-
slog.SetDefault(logger)
117-
118115
viper.SetEnvPrefix("idpscim") // allow to read in from environment
119116

120117
envVars := []string{
@@ -175,6 +172,10 @@ func initConfig() {
175172
slog.Error("cannot unmarshal config", "error", err)
176173
}
177174

175+
if cfg.Debug {
176+
cfg.LogLevel = "debug"
177+
}
178+
178179
switch strings.ToLower(cfg.LogFormat) {
179180
case "json":
180181
logHandler = slog.NewJSONHandler(os.Stdout, logHandlerOptions)
@@ -198,12 +199,15 @@ func initConfig() {
198199
slog.Warn("unknown log level, setting it to info", "level", cfg.LogLevel)
199200
}
200201

201-
if cfg.Debug {
202-
cfg.LogLevel = "debug"
203-
}
202+
// Set the default logger
203+
logger = slog.New(logHandler)
204+
slog.SetDefault(logger)
204205

205206
if cfg.IsLambda || cfg.UseSecretsManager {
206-
getSecrets()
207+
if err := getSecrets(); err != nil {
208+
slog.Error("cannot get secrets", "error", err)
209+
os.Exit(1)
210+
}
207211
}
208212

209213
// not implemented yet block
@@ -213,65 +217,64 @@ func initConfig() {
213217
}
214218
}
215219

216-
func getSecrets() {
220+
func getSecrets() error {
217221
slog.Info("reading secrets from AWS Secrets Manager")
218222

219223
awsConf, err := aws.NewDefaultConf(context.Background())
220224
if err != nil {
221-
slog.Error("cannot load aws config", "error", err)
222-
os.Exit(1)
225+
return errors.Wrap(err, "cannot load aws config")
223226
}
224227

225228
svc := secretsmanager.NewFromConfig(awsConf)
226229

227230
secrets, err := aws.NewSecretsManagerService(svc)
228231
if err != nil {
229-
slog.Error("cannot create aws secrets manager service", "error", err)
230-
os.Exit(1)
232+
return errors.Wrap(err, "cannot create aws secrets manager service")
231233
}
232234

233235
slog.Debug("reading secret", "name", cfg.GWSUserEmailSecretName)
234236
unwrap, err := secrets.GetSecretValue(context.Background(), cfg.GWSUserEmailSecretName)
235237
if err != nil {
236-
slog.Error("cannot get secretmanager value", "error", err)
237-
os.Exit(1)
238+
return errors.Wrap(err, "cannot get secretmanager value")
238239
}
239240
cfg.GWSUserEmail = unwrap
240241

241242
slog.Debug("reading secret", "name", cfg.GWSServiceAccountFileSecretName)
242243
unwrap, err = secrets.GetSecretValue(context.Background(), cfg.GWSServiceAccountFileSecretName)
243244
if err != nil {
244-
slog.Error("cannot get secretmanager value", "error", err)
245-
os.Exit(1)
245+
return errors.Wrap(err, "cannot get secretmanager value")
246246
}
247247
cfg.GWSServiceAccountFile = unwrap
248248

249249
slog.Debug("reading secret", "name", cfg.AWSSCIMAccessTokenSecretName)
250250
unwrap, err = secrets.GetSecretValue(context.Background(), cfg.AWSSCIMAccessTokenSecretName)
251251
if err != nil {
252-
slog.Error("cannot get secretmanager value", "error", err)
253-
os.Exit(1)
252+
return errors.Wrap(err, "cannot get secretmanager value")
254253
}
255254
cfg.AWSSCIMAccessToken = unwrap
256255

257256
slog.Debug("reading secret", "name", cfg.AWSSCIMEndpointSecretName)
258257
unwrap, err = secrets.GetSecretValue(context.Background(), cfg.AWSSCIMEndpointSecretName)
259258
if err != nil {
260-
slog.Error("cannot get secretmanager value", "error", err)
261-
os.Exit(1)
259+
return errors.Wrap(err, "cannot get secretmanager value")
262260
}
263261
cfg.AWSSCIMEndpoint = unwrap
262+
263+
return nil
264264
}
265265

266266
func sync() error {
267267
slog.Debug("viper config", "config", viper.AllSettings())
268268

269269
if cfg.SyncMethod != "groups" {
270-
slog.Error("only 'sync-method=groups' are implemented")
271-
return fmt.Errorf("unknown sync method: %s", cfg.SyncMethod)
270+
return fmt.Errorf("unknown sync method: %s, only 'groups' are implemented", cfg.SyncMethod)
271+
}
272+
273+
if err := syncGroups(); err != nil {
274+
return errors.Wrap(err, "cannot sync groups")
272275
}
273276

274-
return syncGroups()
277+
return nil
275278
}
276279

277280
func syncGroups() error {
@@ -284,7 +287,7 @@ func syncGroups() error {
284287
if !cfg.IsLambda {
285288
gwsServiceAccount, err := os.ReadFile(cfg.GWSServiceAccountFile)
286289
if err != nil {
287-
slog.Error("cannot read service account file", "error", err)
290+
return errors.Wrap(err, "cannot read google workspace service account file")
288291
}
289292
gwsServiceAccountContent = gwsServiceAccount
290293
}
@@ -343,15 +346,13 @@ func syncGroups() error {
343346

344347
awsConf, err := aws.NewDefaultConf(context.Background())
345348
if err != nil {
346-
slog.Error("cannot load aws config", "error", err)
347-
os.Exit(1)
349+
return errors.Wrap(err, "cannot load aws config")
348350
}
349351

350352
s3Client := s3.NewFromConfig(awsConf)
351353
repo, err := repository.NewS3Repository(s3Client, repository.WithBucket(cfg.AWSS3BucketName), repository.WithKey(cfg.AWSS3BucketKey))
352354
if err != nil {
353-
slog.Error("cannot create s3 repository", "error", err)
354-
os.Exit(1)
355+
return errors.Wrap(err, "cannot create s3 repository")
355356
}
356357

357358
ss, err := core.NewSyncService(idpService, scimService, repo, core.WithIdentityProviderGroupsFilter(cfg.GWSGroupsFilter))

go.mod

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,80 @@
11
module github.com/slashdevops/idp-scim-sync
22

3-
go 1.23.4
3+
go 1.23.5
44

55
require (
66
github.com/aws/aws-lambda-go v1.47.0
7-
github.com/aws/aws-sdk-go-v2 v1.32.6
8-
github.com/aws/aws-sdk-go-v2/config v1.28.6
9-
github.com/aws/aws-sdk-go-v2/credentials v1.17.47
10-
github.com/aws/aws-sdk-go-v2/service/s3 v1.71.0
11-
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.34.7
7+
github.com/aws/aws-sdk-go-v2 v1.36.1
8+
github.com/aws/aws-sdk-go-v2/config v1.29.6
9+
github.com/aws/aws-sdk-go-v2/credentials v1.17.59
10+
github.com/aws/aws-sdk-go-v2/service/s3 v1.76.0
11+
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.34.18
1212
github.com/google/go-cmp v0.6.0
1313
github.com/hashicorp/go-retryablehttp v0.7.7
1414
github.com/pkg/errors v0.9.1
1515
github.com/spf13/cobra v1.8.1
1616
github.com/spf13/viper v1.19.0
1717
github.com/stretchr/testify v1.10.0
1818
go.uber.org/mock v0.5.0
19-
golang.org/x/oauth2 v0.24.0
20-
google.golang.org/api v0.212.0
19+
golang.org/x/oauth2 v0.26.0
20+
google.golang.org/api v0.220.0
2121
gopkg.in/yaml.v3 v3.0.1
2222
)
2323

2424
require (
25-
cloud.google.com/go/auth v0.13.0 // indirect
26-
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
25+
cloud.google.com/go/auth v0.14.1 // indirect
26+
cloud.google.com/go/auth/oauth2adapt v0.2.7 // indirect
2727
cloud.google.com/go/compute/metadata v0.6.0 // indirect
28-
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 // indirect
29-
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.21 // indirect
30-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.25 // indirect
31-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.25 // indirect
32-
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
33-
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.25 // indirect
34-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 // indirect
35-
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.6 // indirect
36-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.6 // indirect
37-
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.6 // indirect
38-
github.com/aws/aws-sdk-go-v2/service/sso v1.24.7 // indirect
39-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6 // indirect
40-
github.com/aws/aws-sdk-go-v2/service/sts v1.33.2 // indirect
41-
github.com/aws/smithy-go v1.22.1 // indirect
28+
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.8 // indirect
29+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.28 // indirect
30+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.32 // indirect
31+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.32 // indirect
32+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.2 // indirect
33+
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.32 // indirect
34+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.2 // indirect
35+
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.5.6 // indirect
36+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.13 // indirect
37+
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.13 // indirect
38+
github.com/aws/aws-sdk-go-v2/service/sso v1.24.15 // indirect
39+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.14 // indirect
40+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.14 // indirect
41+
github.com/aws/smithy-go v1.22.2 // indirect
4242
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
4343
github.com/felixge/httpsnoop v1.0.4 // indirect
4444
github.com/fsnotify/fsnotify v1.8.0 // indirect
4545
github.com/go-logr/logr v1.4.2 // indirect
4646
github.com/go-logr/stdr v1.2.2 // indirect
47-
github.com/google/s2a-go v0.1.8 // indirect
47+
github.com/google/s2a-go v0.1.9 // indirect
4848
github.com/google/uuid v1.6.0 // indirect
4949
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
50-
github.com/googleapis/gax-go/v2 v2.14.0 // indirect
50+
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
5151
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
5252
github.com/hashicorp/hcl v1.0.0 // indirect
5353
github.com/inconshreveable/mousetrap v1.1.0 // indirect
5454
github.com/magiconair/properties v1.8.9 // indirect
5555
github.com/mitchellh/mapstructure v1.5.0 // indirect
5656
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
5757
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
58-
github.com/sagikazarmark/locafero v0.6.0 // indirect
58+
github.com/sagikazarmark/locafero v0.7.0 // indirect
5959
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
6060
github.com/sourcegraph/conc v0.3.0 // indirect
61-
github.com/spf13/afero v1.11.0 // indirect
62-
github.com/spf13/cast v1.7.0 // indirect
63-
github.com/spf13/pflag v1.0.5 // indirect
61+
github.com/spf13/afero v1.12.0 // indirect
62+
github.com/spf13/cast v1.7.1 // indirect
63+
github.com/spf13/pflag v1.0.6 // indirect
6464
github.com/subosito/gotenv v1.6.0 // indirect
65-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
66-
go.opentelemetry.io/otel v1.29.0 // indirect
67-
go.opentelemetry.io/otel/metric v1.29.0 // indirect
68-
go.opentelemetry.io/otel/trace v1.29.0 // indirect
65+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
66+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
67+
go.opentelemetry.io/otel v1.34.0 // indirect
68+
go.opentelemetry.io/otel/metric v1.34.0 // indirect
69+
go.opentelemetry.io/otel/trace v1.34.0 // indirect
6970
go.uber.org/multierr v1.11.0 // indirect
70-
golang.org/x/crypto v0.31.0 // indirect
71-
golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // indirect
72-
golang.org/x/net v0.32.0 // indirect
73-
golang.org/x/sys v0.28.0 // indirect
74-
golang.org/x/text v0.21.0 // indirect
75-
google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 // indirect
76-
google.golang.org/grpc v1.67.1 // indirect
77-
google.golang.org/protobuf v1.35.2 // indirect
78-
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
71+
golang.org/x/crypto v0.33.0 // indirect
72+
golang.org/x/exp v0.0.0-20250207012021-f9890c6ad9f3 // indirect
73+
golang.org/x/net v0.34.0 // indirect
74+
golang.org/x/sys v0.30.0 // indirect
75+
golang.org/x/text v0.22.0 // indirect
76+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250207221924-e9438ea467c6 // indirect
77+
google.golang.org/grpc v1.70.0 // indirect
78+
google.golang.org/protobuf v1.36.5 // indirect
7979
gopkg.in/ini.v1 v1.67.0 // indirect
8080
)

0 commit comments

Comments
 (0)