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

Commit c85e77c

Browse files
committed
Remove fhir package and clean up warnings
1 parent b6ccd74 commit c85e77c

31 files changed

+396
-299
lines changed

audit/client.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package audit provides support for HSDP Audit service
1+
// Package audit provides support for interacting with the HSDP Audit service
22
package audit
33

44
import (
@@ -33,10 +33,6 @@ type OptionFunc func(*http.Request) error
3333
type Config struct {
3434
Region string
3535
Environment string
36-
// ProductKey is provided as part of Auditing onboarding
37-
ProductKey string
38-
// Tenant value is used to support multi tenancy with a single ProductKey
39-
Tenant string
4036
// AuditBaseURL is provided as part of Auditing onboarding
4137
AuditBaseURL string
4238
// SharedKey is the IAM API signing key
@@ -98,7 +94,7 @@ func newClient(httpClient *http.Client, config *Config) (*Client, error) {
9894
return nil, fmt.Errorf("cdr.NewClient create FHIR STU3 unmarshaller (timezone=[%s]): %w", config.TimeZone, err)
9995
}
10096
c.um = um
101-
c.setAuditBaseURL(c.config.AuditBaseURL)
97+
_ = c.setAuditBaseURL(c.config.AuditBaseURL)
10298

10399
return c, nil
104100
}
@@ -207,7 +203,7 @@ func (c *Client) do(req *http.Request, v interface{}) (*Response, error) {
207203

208204
response := newResponse(resp)
209205

210-
doErr := CheckResponse(resp)
206+
doErr := checkResponse(resp)
211207

212208
if v != nil {
213209
defer resp.Body.Close() // Only close if we plan to read it
@@ -224,8 +220,8 @@ func (c *Client) do(req *http.Request, v interface{}) (*Response, error) {
224220
return response, doErr
225221
}
226222

227-
// CheckResponse checks the API response for errors, and returns them if present.
228-
func CheckResponse(r *http.Response) error {
223+
// checkResponse checks the API response for errors, and returns them if present.
224+
func checkResponse(r *http.Response) error {
229225
switch r.StatusCode {
230226
case 200, 201, 202, 204, 304:
231227
return nil

credentials/client.go

+64-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import (
1111
"net/http/httputil"
1212
"net/url"
1313
"os"
14+
"sort"
1415
"strings"
1516

1617
autoconf "github.com/philips-software/go-hsdp-api/config"
1718

1819
"github.com/go-playground/validator/v10"
1920
"github.com/google/go-querystring/query"
20-
"github.com/philips-software/go-hsdp-api/fhir"
2121
"github.com/philips-software/go-hsdp-api/iam"
2222
)
2323

@@ -219,7 +219,7 @@ func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {
219219

220220
response := newResponse(resp)
221221

222-
err = fhir.CheckResponse(resp)
222+
err = checkResponse(resp)
223223
if err != nil {
224224
// even though there was an error, we still return the response
225225
// in case the caller wants to inspect it further
@@ -236,3 +236,65 @@ func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) {
236236

237237
return response, err
238238
}
239+
240+
// ErrorResponse represents an IAM errors response
241+
// containing a code and a human readable message
242+
type ErrorResponse struct {
243+
Response *http.Response `json:"-"`
244+
Code string `json:"responseCode"`
245+
Message string `json:"responseMessage"`
246+
}
247+
248+
func (e *ErrorResponse) Error() string {
249+
path, _ := url.QueryUnescape(e.Response.Request.URL.Opaque)
250+
u := fmt.Sprintf("%s://%s%s", e.Response.Request.URL.Scheme, e.Response.Request.URL.Host, path)
251+
return fmt.Sprintf("%s %s: %d %s", e.Response.Request.Method, u, e.Response.StatusCode, e.Message)
252+
}
253+
254+
func checkResponse(r *http.Response) error {
255+
switch r.StatusCode {
256+
case 200, 201, 202, 204, 304:
257+
return nil
258+
}
259+
260+
errorResponse := &ErrorResponse{Response: r}
261+
data, err := ioutil.ReadAll(r.Body)
262+
if err == nil && data != nil {
263+
var raw interface{}
264+
if err := json.Unmarshal(data, &raw); err != nil {
265+
errorResponse.Message = "failed to parse unknown error format"
266+
}
267+
268+
errorResponse.Message = parseError(raw)
269+
}
270+
271+
return errorResponse
272+
}
273+
274+
func parseError(raw interface{}) string {
275+
switch raw := raw.(type) {
276+
case string:
277+
return raw
278+
279+
case []interface{}:
280+
var errs []string
281+
for _, v := range raw {
282+
errs = append(errs, parseError(v))
283+
}
284+
return fmt.Sprintf("[%s]", strings.Join(errs, ", "))
285+
286+
case map[string]interface{}:
287+
var errs []string
288+
for k, v := range raw {
289+
errs = append(errs, fmt.Sprintf("{%s: %s}", k, parseError(v)))
290+
}
291+
sort.Strings(errs)
292+
return strings.Join(errs, ", ")
293+
case float64:
294+
return fmt.Sprintf("%d", int64(raw))
295+
case int64:
296+
return fmt.Sprintf("%d", raw)
297+
default:
298+
return fmt.Sprintf("failed to parse unexpected error type: %T", raw)
299+
}
300+
}

fhir/backbone_element.go

-5
This file was deleted.

fhir/check_response.go

-44
This file was deleted.

fhir/check_response_test.go

-59
This file was deleted.

fhir/datetime.go

-38
This file was deleted.

fhir/datetime_test.go

-31
This file was deleted.

fhir/domain_resource.go

-7
This file was deleted.

fhir/element.go

-5
This file was deleted.

fhir/meta.go

-10
This file was deleted.

fhir/narrative.go

-6
This file was deleted.

fhir/operation_outcome.go

-20
This file was deleted.

fhir/resource.go

-9
This file was deleted.

has/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func main() {
4444
Count: 1,
4545
ClusterTag: "andytest",
4646
EBS: has.EBS{
47-
DeleteOnTermination: true,
47+
DeleteOnTermination: true,
4848
VolumeSize: 50,
4949
VolumeType: "standard",
5050
},

0 commit comments

Comments
 (0)