Skip to content
This repository was archived by the owner on Aug 11, 2025. It is now read-only.

Commit dfd5131

Browse files
authored
Add Bom client for mtcl to call with tests covered (#10)
1 parent 7b3d8a9 commit dfd5131

File tree

9 files changed

+630
-36
lines changed

9 files changed

+630
-36
lines changed

go.mod

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ require (
77
github.com/coreos/go-oidc v2.2.1+incompatible
88
github.com/gin-gonic/gin v1.9.1
99
github.com/golang/mock v1.6.0
10+
github.com/google/uuid v1.3.1
1011
github.com/hashicorp/go-retryablehttp v0.7.4
1112
github.com/pkg/errors v0.9.1
1213
github.com/sirupsen/logrus v1.9.3
1314
github.com/spf13/cobra v1.7.0
1415
github.com/spf13/viper v1.16.0
16+
github.com/stretchr/testify v1.8.4
1517
github.com/tealeg/xlsx v1.0.5
1618
go.hollow.sh/serverservice v0.16.1
1719
go.hollow.sh/toolbox v0.6.1
1820
golang.org/x/oauth2 v0.11.0
21+
gopkg.in/square/go-jose.v2 v2.6.0
1922
)
2023

2124
require (
22-
github.com/bytedance/sonic v1.10.0 // indirect
25+
github.com/bytedance/sonic v1.10.1 // indirect
2326
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
2427
github.com/chenzhuoyu/iasm v0.9.0 // indirect
2528
github.com/cockroachdb/cockroach-go/v2 v2.3.5 // indirect
@@ -29,16 +32,16 @@ require (
2932
github.com/fsnotify/fsnotify v1.6.0 // indirect
3033
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
3134
github.com/gin-contrib/sse v0.1.0 // indirect
35+
github.com/gin-contrib/zap v0.2.0 // indirect
3236
github.com/go-logr/logr v1.2.4 // indirect
3337
github.com/go-logr/stdr v1.2.2 // indirect
3438
github.com/go-playground/locales v0.14.1 // indirect
3539
github.com/go-playground/universal-translator v0.18.1 // indirect
36-
github.com/go-playground/validator/v10 v10.15.0 // indirect
40+
github.com/go-playground/validator/v10 v10.15.3 // indirect
3741
github.com/goccy/go-json v0.10.2 // indirect
3842
github.com/gofrs/uuid v4.4.0+incompatible // indirect
3943
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
4044
github.com/golang/protobuf v1.5.3 // indirect
41-
github.com/google/uuid v1.3.1 // indirect
4245
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
4346
github.com/gosimple/slug v1.13.1 // indirect
4447
github.com/gosimple/unidecode v1.0.1 // indirect
@@ -71,15 +74,14 @@ require (
7174
github.com/nats-io/nats.go v1.28.0 // indirect
7275
github.com/nats-io/nkeys v0.4.4 // indirect
7376
github.com/nats-io/nuid v1.0.1 // indirect
74-
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
77+
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
7578
github.com/pmezard/go-difflib v1.0.0 // indirect
7679
github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021 // indirect
7780
github.com/rogpeppe/go-internal v1.10.0 // indirect
7881
github.com/spf13/afero v1.9.5 // indirect
7982
github.com/spf13/cast v1.5.1 // indirect
8083
github.com/spf13/jwalterweatherman v1.1.0 // indirect
8184
github.com/spf13/pflag v1.0.5 // indirect
82-
github.com/stretchr/testify v1.8.4 // indirect
8385
github.com/subosito/gotenv v1.6.0 // indirect
8486
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
8587
github.com/ugorji/go/codec v1.2.11 // indirect
@@ -97,12 +99,12 @@ require (
9799
go.uber.org/multierr v1.11.0 // indirect
98100
go.uber.org/zap v1.25.0 // indirect
99101
gocloud.dev v0.33.0 // indirect
100-
golang.org/x/arch v0.4.0 // indirect
101-
golang.org/x/crypto v0.12.0 // indirect
102+
golang.org/x/arch v0.5.0 // indirect
103+
golang.org/x/crypto v0.13.0 // indirect
102104
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
103-
golang.org/x/net v0.14.0 // indirect
104-
golang.org/x/sys v0.11.0 // indirect
105-
golang.org/x/text v0.12.0 // indirect
105+
golang.org/x/net v0.15.0 // indirect
106+
golang.org/x/sys v0.12.0 // indirect
107+
golang.org/x/text v0.13.0 // indirect
106108
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
107109
google.golang.org/api v0.137.0 // indirect
108110
google.golang.org/appengine v1.6.7 // indirect
@@ -111,6 +113,7 @@ require (
111113
google.golang.org/protobuf v1.31.0 // indirect
112114
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
113115
gopkg.in/ini.v1 v1.67.0 // indirect
114-
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
115116
gopkg.in/yaml.v3 v3.0.1 // indirect
116117
)
118+
119+
replace go.hollow.sh/serverservice v0.16.1 => /Users/alzhang/project/hollow-serverservice

go.sum

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
9999
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
100100
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
101101
github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
102-
github.com/bytedance/sonic v1.10.0 h1:qtNZduETEIWJVIyDl01BeNxur2rW9OwTQ/yBqFRkKEk=
103-
github.com/bytedance/sonic v1.10.0/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
102+
github.com/bytedance/sonic v1.10.1 h1:7a1wuFXL1cMy7a3f7/VFcEtriuXQnUBhtoVfOZiaysc=
103+
github.com/bytedance/sonic v1.10.1/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
104104
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
105105
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
106106
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
@@ -181,6 +181,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
181181
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
182182
github.com/gin-contrib/zap v0.1.0 h1:RMSFFJo34XZogV62OgOzvrlaMNmXrNxmJ3bFmMwl6Cc=
183183
github.com/gin-contrib/zap v0.1.0/go.mod h1:hvnZaPs478H1PGvRP8w89ZZbyJUiyip4ddiI/53WG3o=
184+
github.com/gin-contrib/zap v0.2.0 h1:HLvt3rZXyC8XC+s2lHzMFow3UDqiEbfrBWJyHHS6L8A=
185+
github.com/gin-contrib/zap v0.2.0/go.mod h1:eqfbe9ZmI+GgTZF6nRiC2ZwDeM4DK1Viwc8OxTCphh0=
184186
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
185187
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
186188
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
@@ -203,8 +205,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
203205
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
204206
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
205207
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
206-
github.com/go-playground/validator/v10 v10.15.0 h1:nDU5XeOKtB3GEa+uB7GNYwhVKsgjAR7VgKoNB6ryXfw=
207-
github.com/go-playground/validator/v10 v10.15.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
208+
github.com/go-playground/validator/v10 v10.15.3 h1:S+sSpunYjNPDuXkWbK+x+bA7iXiW296KG4dL3X7xUZo=
209+
github.com/go-playground/validator/v10 v10.15.3/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
208210
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
209211
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
210212
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
@@ -546,8 +548,8 @@ github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144T
546548
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
547549
github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
548550
github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
549-
github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0=
550-
github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
551+
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
552+
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
551553
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ=
552554
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
553555
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -734,8 +736,8 @@ go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk=
734736
gocloud.dev v0.33.0 h1:ET5z49jm1+eUhY5BkuGk2d7czfgGeXKd4vtg1Jcg9OQ=
735737
gocloud.dev v0.33.0/go.mod h1:z6W8qorjrfM09H8t1MDk8KLPj3Xi26aFBzDKAHWIgLU=
736738
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
737-
golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc=
738-
golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
739+
golang.org/x/arch v0.5.0 h1:jpGode6huXQxcskEIpOCvrU+tzo81b6+oFLUYXWtH/Y=
740+
golang.org/x/arch v0.5.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
739741
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
740742
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
741743
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
@@ -757,8 +759,8 @@ golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88/go.mod h1:IxCIyHEi3zRg3s0
757759
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
758760
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
759761
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
760-
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
761-
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
762+
golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck=
763+
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
762764
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
763765
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
764766
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -848,8 +850,8 @@ golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su
848850
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
849851
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
850852
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
851-
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
852-
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
853+
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
854+
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
853855
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
854856
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
855857
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -976,8 +978,8 @@ golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBc
976978
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
977979
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
978980
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
979-
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
980-
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
981+
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
982+
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
981983
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
982984
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
983985
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
@@ -992,8 +994,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
992994
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
993995
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
994996
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
995-
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
996-
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
997+
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
998+
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
997999
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
9981000
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
9991001
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

internal/store/serverservice.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ var (
2727
// ErrServerserviceConfig is returned when theres an error in loading serverservice configuration.
2828
ErrServerserviceConfig = errors.New("Serverservice configuration error")
2929

30-
// ErrServerserviceQuery is returned when a serverservice query error was received.
31-
ErrServerserviceQuery = errors.New("Serverservice query error")
32-
3330
// ErrServserviceAttribute is returned when a serverservice attribute does not contain the expected fields.
3431
ErrServerserviceAttribute = errors.New("error in serverservice attribute")
3532

pkg/api/v1/client/client.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package client
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
8+
sservice "go.hollow.sh/serverservice/pkg/api/v1"
9+
)
10+
11+
const (
12+
bomInfoEndpoint = "bomservice"
13+
uploadFileEndpoint = "upload-xlsx-file"
14+
bomByMacAOCAddressEndpoint = "aoc-mac-address"
15+
bomByMacBMCAddressEndpoint = "bmc-mac-address"
16+
)
17+
18+
// Doer performs HTTP requests.
19+
//
20+
// The standard http.Client implements this interface.
21+
type HTTPRequestDoer interface {
22+
Do(req *http.Request) (*http.Response, error)
23+
}
24+
25+
// Client can perform queries against the Bom service.
26+
type Client struct {
27+
// The server address with the schema
28+
serverAddress string
29+
30+
// Authentication token
31+
authToken string
32+
33+
// Doer for performing requests, typically a *http.Client with any
34+
// customized settings, such as certificate chains.
35+
client HTTPRequestDoer
36+
}
37+
38+
// Option allows setting custom parameters during construction
39+
type Option func(*Client) error
40+
41+
// Creates a new Client, with reasonable defaults
42+
func NewClient(serverAddress string, opts ...Option) (*Client, error) {
43+
// create a client with sane default values
44+
client := Client{serverAddress: serverAddress}
45+
// mutate client and add all optional params
46+
for _, o := range opts {
47+
if err := o(&client); err != nil {
48+
return nil, err
49+
}
50+
}
51+
52+
// create httpClient, if not already present
53+
if client.client == nil {
54+
client.client = &http.Client{}
55+
}
56+
57+
return &client, nil
58+
}
59+
60+
// WithHTTPClient allows overriding the default Doer, which is
61+
// automatically created using http.Client. This is useful for tests.
62+
func WithHTTPClient(doer HTTPRequestDoer) Option {
63+
return func(c *Client) error {
64+
c.client = doer
65+
return nil
66+
}
67+
}
68+
69+
// WithAuthToken sets the client auth token.
70+
func WithAuthToken(authToken string) Option {
71+
return func(c *Client) error {
72+
c.authToken = authToken
73+
return nil
74+
}
75+
}
76+
77+
func (c *Client) XlsxFileUpload(ctx context.Context, fileBytes []byte) (*sservice.ServerResponse, error) {
78+
path := fmt.Sprintf("%s/%s", bomInfoEndpoint, uploadFileEndpoint)
79+
return c.postRawBytes(ctx, path, fileBytes)
80+
}
81+
82+
func (c *Client) GetBomInfoByAOCMacAddr(ctx context.Context, aocMacAddr string) (*sservice.ServerResponse, error) {
83+
path := fmt.Sprintf("%s/%s/%s", bomInfoEndpoint, bomByMacAOCAddressEndpoint, aocMacAddr)
84+
return c.get(ctx, path)
85+
}
86+
87+
func (c *Client) GetBomInfoByBMCMacAddr(ctx context.Context, bmcMacAddr string) (*sservice.ServerResponse, error) {
88+
path := fmt.Sprintf("servers/%s/condition/%s", bomByMacBMCAddressEndpoint, bmcMacAddr)
89+
return c.get(ctx, path)
90+
}

0 commit comments

Comments
 (0)