Skip to content

Commit f03011b

Browse files
committed
bind env
Signed-off-by: pxp928 <[email protected]>
1 parent 05ae3d7 commit f03011b

File tree

4 files changed

+59
-76
lines changed

4 files changed

+59
-76
lines changed

README.md

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ go get github.com/kusaridev/kusari-uploader
1919

2020
### Command-Line Flags
2121

22-
```bash
2322
# Upload a single file
2423
./kusari-uploader -f /path/to/file \
2524
-c CLIENT_ID \
@@ -39,38 +38,34 @@ go get github.com/kusaridev/kusari-uploader
3938
-d "image"
4039
```
4140

42-
### Environment Variables
43-
44-
You can also configure the uploader using environment variables:
45-
46-
```bash
47-
export UPLOADER_FILE_PATH=/path/to/files
48-
export UPLOADER_CLIENT_ID=your-client-id
49-
export UPLOADER_CLIENT_SECRET=your-client-secret
50-
export UPLOADER_TENANT_ENDPOINT=https://tenant-endpoint
51-
export UPLOADER_TOKEN_ENDPOINT=https://token-endpoint
52-
export UPLOADER_ALIAS="package alias"
53-
export UPLOADER_DOCUMENT-TYPE="image"
54-
55-
./kusari-uploader
56-
```
57-
5841
## Configuration Parameters
5942

60-
| Flag/Env Variable | Description | Required |
43+
| Short Flag/ Full Flag | Description | Required |
6144
|------------------|-------------|----------|
62-
| `-f` / `UPLOADER_FILE_PATH` | Path to file or directory to upload | Yes |
63-
| `-c` / `UPLOADER_CLIENT_ID` | OAuth2 Client ID | Yes |
64-
| `-s` / `UPLOADER_CLIENT_SECRET` | OAuth2 Client Secret | Yes |
65-
| `-t` / `UPLOADER_TENANT_ENDPOINT` | Kusari Tenant endpoint URL | Yes |
66-
| `-k` / `UPLOADER_TOKEN_ENDPOINT` | Token endpoint URL | Yes |
67-
| `--alias` / `UPLOADER_ALIAS` | Alias that supersedes the subject in Kusari platform (optional) | No |
68-
| `--document-type` / `UPLOADER_DOCUMENT-TYPE` | Type of the document (image or build) sbom (optional) | No |
45+
| `-f` / `--file-path` | Path to file or directory to upload | Yes |
46+
| `-c` / `--client-id` | OAuth2 Client ID | Yes |
47+
| `-s` / `--client-secret` | OAuth2 Client Secret | Yes |
48+
| `-t` / `--tenant-endpoint` | Kusari Tenant endpoint URL | Yes |
49+
| `-k` / `--token-endpoint` | Token endpoint URL | Yes |
50+
| `--alias` / `--alias` | Alias that supersedes the subject in Kusari platform (optional) | No |
51+
| `--document-type` / `--document-type` | Type of the document (image or build) sbom (optional) | No |
6952

7053
## Help
7154

7255
To see all available commands and flags:
7356

7457
```bash
7558
./kusari-uploader --help
59+
Usage:
60+
file-uploader [flags]
61+
62+
Flags:
63+
-a, --alias string Alias that supersedes the subject in Kusari platform (optional)
64+
-c, --client-id string OAuth client ID (required)
65+
-s, --client-secret string OAuth client secret (required)
66+
-d, --document-type string Type of the document (image or build) sbom (optional)
67+
-f, --file-path string Path to file or directory to upload (required)
68+
-h, --help help for file-uploader
69+
-t, --tenant-endpoint string Kusari Tenant endpoint URL (required)
70+
-k, --token-endpoint string Token endpoint URL (required)
7671
```

go.mod

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,24 @@ go 1.23.5
55
require (
66
github.com/guacsec/guac v0.13.2
77
github.com/spf13/cobra v1.8.1
8-
github.com/spf13/viper v1.19.0
8+
github.com/spf13/viper v1.20.0
99
golang.org/x/oauth2 v0.25.0
1010
)
1111

1212
require (
1313
github.com/fsnotify/fsnotify v1.8.0 // indirect
14-
github.com/hashicorp/hcl v1.0.0 // indirect
14+
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
1515
github.com/inconshreveable/mousetrap v1.1.0 // indirect
16-
github.com/magiconair/properties v1.8.7 // indirect
1716
github.com/mattn/go-colorable v0.1.13 // indirect
1817
github.com/mattn/go-isatty v0.0.20 // indirect
19-
github.com/mitchellh/mapstructure v1.5.0 // indirect
20-
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
21-
github.com/sagikazarmark/locafero v0.4.0 // indirect
22-
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
18+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
19+
github.com/sagikazarmark/locafero v0.7.0 // indirect
2320
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 // indirect
2421
github.com/sourcegraph/conc v0.3.0 // indirect
25-
github.com/spf13/afero v1.11.0 // indirect
26-
github.com/spf13/cast v1.6.0 // indirect
27-
github.com/spf13/pflag v1.0.5 // indirect
22+
github.com/spf13/afero v1.12.0 // indirect
23+
github.com/spf13/cast v1.7.1 // indirect
24+
github.com/spf13/pflag v1.0.6 // indirect
2825
github.com/subosito/gotenv v1.6.0 // indirect
29-
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
30-
gopkg.in/ini.v1 v1.67.0 // indirect
3126
gopkg.in/yaml.v3 v3.0.1 // indirect
3227
)
3328

go.sum

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
2424
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
2525
github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k=
2626
github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
27+
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
28+
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
2729
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
2830
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
2931
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
@@ -32,8 +34,6 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
3234
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
3335
github.com/guacsec/guac v0.13.2 h1:3z71jrSDxTTxHxSDoWlg+xu42b7IHH6YeIW2+5JAbLE=
3436
github.com/guacsec/guac v0.13.2/go.mod h1:emKoLrPPyri970ZNe10YCClQwcWF9PdJc6xDfBCLyI0=
35-
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
36-
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
3737
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3838
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
3939
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
@@ -44,16 +44,12 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
4444
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
4545
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
4646
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
47-
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
48-
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
4947
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
5048
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
5149
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
5250
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
5351
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
5452
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
55-
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
56-
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
5753
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
5854
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
5955
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -63,8 +59,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb
6359
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
6460
github.com/package-url/packageurl-go v0.1.3 h1:4juMED3hHiz0set3Vq3KeQ75KD1avthoXLtmE3I0PLs=
6561
github.com/package-url/packageurl-go v0.1.3/go.mod h1:nKAWB8E6uk1MHqiS/lQb9pYBGH2+mdJ2PJc2s50dQY0=
66-
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
67-
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
62+
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
63+
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
6864
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
6965
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7066
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
@@ -75,34 +71,30 @@ github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
7571
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
7672
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
7773
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
78-
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
79-
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
80-
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
81-
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
74+
github.com/sagikazarmark/locafero v0.7.0 h1:5MqpDsTGNDhY8sGp0Aowyf0qKsPrhewaLSsFaodPcyo=
75+
github.com/sagikazarmark/locafero v0.7.0/go.mod h1:2za3Cg5rMaTMoG/2Ulr9AwtFaIppKXTRYnozin4aB5k=
8276
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw=
8377
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
8478
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
8579
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
86-
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
87-
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
88-
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
89-
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
80+
github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs=
81+
github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4=
82+
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
83+
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
9084
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
9185
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
92-
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
9386
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
94-
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
95-
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
87+
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
88+
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
89+
github.com/spf13/viper v1.20.0 h1:zrxIyR3RQIOsarIrgL8+sAvALXul9jeEPa06Y0Ph6vY=
90+
github.com/spf13/viper v1.20.0/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
9691
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
9792
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
9893
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
99-
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
10094
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
10195
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
10296
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
10397
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
104-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
105-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
10698
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
10799
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
108100
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
@@ -117,8 +109,6 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
117109
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
118110
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
119111
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
120-
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY=
121-
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8=
122112
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
123113
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
124114
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
@@ -137,8 +127,6 @@ golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
137127
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
138128
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
139129
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
140-
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
141-
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
142130
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
143131
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
144132
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"net/http"
2525
"os"
2626
"path/filepath"
27+
"strings"
2728

2829
"github.com/guacsec/guac/pkg/events"
2930
"github.com/guacsec/guac/pkg/handler/processor"
@@ -66,13 +67,13 @@ func main() {
6667
rootCmd.Flags().StringP("document-type", "d", "", "Type of the document (image or build) sbom (optional)")
6768

6869
// Bind flags to Viper with error handling
69-
mustBindPFlag(rootCmd, "file-path", "file-path")
70-
mustBindPFlag(rootCmd, "client-id", "client-id")
71-
mustBindPFlag(rootCmd, "client-secret", "client-secret")
72-
mustBindPFlag(rootCmd, "tenant-endpoint", "tenant-endpoint")
73-
mustBindPFlag(rootCmd, "token-endpoint", "token-endpoint")
74-
mustBindPFlag(rootCmd, "alias", "alias")
75-
mustBindPFlag(rootCmd, "document-type", "document-type")
70+
mustBindPFlag(rootCmd, "file-path")
71+
mustBindPFlag(rootCmd, "client-id")
72+
mustBindPFlag(rootCmd, "client-secret")
73+
mustBindPFlag(rootCmd, "tenant-endpoint")
74+
mustBindPFlag(rootCmd, "token-endpoint")
75+
mustBindPFlag(rootCmd, "alias")
76+
mustBindPFlag(rootCmd, "document-type")
7677

7778
// Allow environment variables
7879
viper.SetEnvPrefix("UPLOADER")
@@ -91,14 +92,18 @@ func main() {
9192
}
9293
}
9394

94-
// Helper function to bind Viper flags with error handling
95-
func mustBindPFlag(cmd *cobra.Command, configKey string, flagName string) {
96-
if err := viper.BindPFlag(configKey, cmd.Flags().Lookup(flagName)); err != nil {
95+
func mustBindPFlag(cmd *cobra.Command, flagName string) {
96+
if bindErr := viper.BindPFlag(flagName, cmd.Flags().Lookup(flagName)); bindErr != nil {
9797
log.Fatal().
98-
Err(err).
99-
Str("configKey", configKey).
98+
Err(bindErr).
99+
Str("flagName", flagName).
100+
Msg("Failed bind flags")
101+
}
102+
if envErr := viper.BindEnv(flagName, "UPLOADER_"+strings.ToUpper(strings.ReplaceAll(flagName, "-", "_"))); envErr != nil {
103+
log.Fatal().
104+
Err(envErr).
100105
Str("flagName", flagName).
101-
Msg("Failed to bind flag to configuration")
106+
Msg("Failed bind env")
102107
}
103108
}
104109

0 commit comments

Comments
 (0)