Skip to content

Commit b86901b

Browse files
committed
Release v0.14.0
1 parent dae742c commit b86901b

File tree

7 files changed

+128
-67
lines changed

7 files changed

+128
-67
lines changed

DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ go test ./...
2727
## Build Releases
2828

2929
```sh
30-
VERSION=0.13.1 ./build-releases.sh
30+
VERSION=0.14.0 ./build-releases.sh
3131
```

README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ blazectl is written in Go. All you need is a single binary which is available fo
1616
1. Download the latest release with the command:
1717

1818
```bash
19-
curl -LO https://github.com/samply/blazectl/releases/download/v0.13.1/blazectl-0.13.1-linux-amd64.tar.gz
19+
curl -LO https://github.com/samply/blazectl/releases/download/v0.14.0/blazectl-0.14.0-linux-amd64.tar.gz
2020
```
2121

2222
1. Untar the binary:
2323

2424
```bash
25-
tar xzf blazectl-0.13.1-linux-amd64.tar.gz
25+
tar xzf blazectl-0.14.0-linux-amd64.tar.gz
2626
```
2727

2828
1. Move the binary in to your PATH.
@@ -42,13 +42,13 @@ blazectl is written in Go. All you need is a single binary which is available fo
4242
1. Download the latest release with the command:
4343

4444
```bash
45-
curl -LO https://github.com/samply/blazectl/releases/download/v0.13.1/blazectl-0.13.1-darwin-amd64.tar.gz
45+
curl -LO https://github.com/samply/blazectl/releases/download/v0.14.0/blazectl-0.14.0-darwin-amd64.tar.gz
4646
```
4747

4848
1. Untar the binary:
4949

5050
```bash
51-
tar xzf blazectl-0.13.1-darwin-amd64.tar.gz
51+
tar xzf blazectl-0.14.0-darwin-amd64.tar.gz
5252
```
5353

5454
1. Move the binary in to your PATH.
@@ -69,13 +69,13 @@ blazectl is written in Go. All you need is a single binary which is available fo
6969
1. Download the latest release with the command:
7070

7171
```bash
72-
curl -LO https://github.com/samply/blazectl/releases/download/v0.13.1/blazectl-0.13.1-darwin-arm64.tar.gz
72+
curl -LO https://github.com/samply/blazectl/releases/download/v0.14.0/blazectl-0.14.0-darwin-arm64.tar.gz
7373
```
7474

7575
1. Untar the binary:
7676

7777
```bash
78-
tar xzf blazectl-0.13.1-darwin-arm64.tar.gz
78+
tar xzf blazectl-0.14.0-darwin-arm64.tar.gz
7979
```
8080

8181
1. Move the binary in to your PATH.
@@ -95,13 +95,13 @@ blazectl is written in Go. All you need is a single binary which is available fo
9595
1. Download the latest release with the command:
9696

9797
```bash
98-
curl -LO https://github.com/samply/blazectl/releases/download/v0.13.1/blazectl-0.13.1-linux-arm64.tar.gz
98+
curl -LO https://github.com/samply/blazectl/releases/download/v0.14.0/blazectl-0.14.0-linux-arm64.tar.gz
9999
```
100100

101101
1. Untar the binary:
102102

103103
```bash
104-
tar xzf blazectl-0.13.1-linux-arm64.tar.gz
104+
tar xzf blazectl-0.14.0-linux-arm64.tar.gz
105105
```
106106

107107
1. Move the binary in to your PATH.
@@ -145,18 +145,20 @@ Usage:
145145
Available Commands:
146146
completion Generate the autocompletion script for the specified shell
147147
count-resources Counts all resources by type
148-
download Download FHIR resources into an NDJSON file
148+
download Download FHIR resources in NDJSON format
149149
evaluate-measure Evaluates a Measure
150150
help Help about any command
151151
upload Upload transaction bundles
152152
153153
Flags:
154-
-h, --help help for blazectl
155-
-k, --insecure allow insecure server connections when using SSL
156-
--no-progress don't show progress bar
157-
--password string password information for basic authentication
158-
--user string user information for basic authentication
159-
-v, --version version for blazectl
154+
--certificate-authority string path to a cert file for the certificate authority
155+
-h, --help help for blazectl
156+
-k, --insecure allow insecure server connections when using SSL
157+
--no-progress don't show progress bar
158+
--password string password information for basic authentication
159+
--token string bearer token for authentication
160+
--user string user information for basic authentication
161+
-v, --version version for blazectl
160162
161163
Use "blazectl [command] --help" for more information about a command.
162164
```
@@ -280,7 +282,7 @@ Procedure : 418310
280282

281283
## License
282284

283-
Copyright 2019 - 2023 The Samply Community
285+
Copyright 2019 - 2024 The Samply Community
284286

285287
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
286288

@@ -290,7 +292,7 @@ Unless required by applicable law or agreed to in writing, software distributed
290292

291293
[1]: <http://docs.simplifier.net/vonkloader/>
292294
[2]: <https://github.com/synthetichealth/uploader>
293-
[3]: <https://github.com/samply/blazectl/releases/download/v0.13.1/blazectl-0.13.1-windows-amd64.zip>
295+
[3]: <https://github.com/samply/blazectl/releases/download/v0.14.0/blazectl-0.14.0-windows-amd64.zip>
294296
[4]: <https://github.com/samply/blaze>
295297
[5]: <https://github.com/synthetichealth/synthea>
296298
[6]: <https://github.com/tsenart/vegeta>

cmd/countResources_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestFetchResourcesTotal(t *testing.T) {
6868
defer ts.Close()
6969

7070
baseURL, _ := url.ParseRequestURI(ts.URL)
71-
client := fhir.NewClient(*baseURL, fhir.ClientAuth{})
71+
client := fhir.NewClient(*baseURL, nil)
7272
result, err := fetchResourcesTotal(client, []fm.ResourceType{fm.ResourceTypePatient})
7373
if err != nil {
7474
t.Error(err)

cmd/download_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestDownloadResources(t *testing.T) {
3333

3434
t.Run("RequestToFHIRServerFails", func(t *testing.T) {
3535
baseURL, _ := url.ParseRequestURI("http://localhost")
36-
client := fhir.NewClient(*baseURL, fhir.ClientAuth{})
36+
client := fhir.NewClient(*baseURL, nil)
3737

3838
var bundles int
3939
bundleChannel := make(chan downloadBundle)
@@ -53,7 +53,7 @@ func TestDownloadResources(t *testing.T) {
5353
defer server.Close()
5454

5555
baseURL, _ := url.ParseRequestURI(server.URL)
56-
client := fhir.NewClient(*baseURL, fhir.ClientAuth{})
56+
client := fhir.NewClient(*baseURL, nil)
5757

5858
var bundles int
5959
bundleChannel := make(chan downloadBundle)
@@ -73,7 +73,7 @@ func TestDownloadResources(t *testing.T) {
7373
defer server.Close()
7474

7575
baseURL, _ := url.ParseRequestURI(server.URL)
76-
client := fhir.NewClient(*baseURL, fhir.ClientAuth{})
76+
client := fhir.NewClient(*baseURL, nil)
7777

7878
var bundles int
7979
bundleChannel := make(chan downloadBundle)
@@ -105,7 +105,7 @@ func TestDownloadResources(t *testing.T) {
105105
defer server.Close()
106106

107107
baseURL, _ := url.ParseRequestURI(server.URL)
108-
client := fhir.NewClient(*baseURL, fhir.ClientAuth{})
108+
client := fhir.NewClient(*baseURL, nil)
109109

110110
var bundles int
111111
bundleChannel := make(chan downloadBundle)
@@ -168,7 +168,7 @@ func TestDownloadResources(t *testing.T) {
168168
defer server.Close()
169169

170170
baseURL, _ := url.ParseRequestURI(server.URL)
171-
client := fhir.NewClient(*baseURL, fhir.ClientAuth{})
171+
client := fhir.NewClient(*baseURL, nil)
172172

173173
var bundles int
174174
bundleChannel := make(chan downloadBundle)
@@ -209,7 +209,7 @@ func TestDownloadResources(t *testing.T) {
209209
defer server.Close()
210210

211211
baseURL, _ := url.ParseRequestURI(server.URL)
212-
client := fhir.NewClient(*baseURL, fhir.ClientAuth{})
212+
client := fhir.NewClient(*baseURL, nil)
213213

214214
var bundles int
215215
bundleChannel := make(chan downloadBundle)
@@ -290,7 +290,7 @@ func TestDownloadResources(t *testing.T) {
290290
server.Start()
291291

292292
baseURL, _ := url.ParseRequestURI(server.URL)
293-
client := fhir.NewClient(*baseURL, fhir.ClientAuth{})
293+
client := fhir.NewClient(*baseURL, nil)
294294

295295
var bundles int
296296
bundleChannel := make(chan downloadBundle)

cmd/root.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import (
2424

2525
var server string
2626
var disableTlsSecurity bool
27+
var caCert string
2728
var basicAuthUser string
2829
var basicAuthPassword string
30+
var bearerToken string
2931
var noProgress bool
3032

3133
var client *fhir.Client
@@ -36,15 +38,29 @@ func createClient() error {
3638
return fmt.Errorf("could not parse server's base URL: %v", err)
3739
}
3840

39-
clientAuth := fhir.ClientAuth{BasicAuthUser: basicAuthUser, BasicAuthPassword: basicAuthPassword}
4041
if disableTlsSecurity {
41-
client = fhir.NewClientInsecure(*fhirServerBaseUrl, clientAuth)
42+
client = fhir.NewClientInsecure(*fhirServerBaseUrl, clientAuth())
43+
} else if caCert != "" {
44+
client, err = fhir.NewClientCa(*fhirServerBaseUrl, clientAuth(), caCert)
45+
if err != nil {
46+
return err
47+
}
4248
} else {
43-
client = fhir.NewClient(*fhirServerBaseUrl, clientAuth)
49+
client = fhir.NewClient(*fhirServerBaseUrl, clientAuth())
4450
}
4551
return nil
4652
}
4753

54+
func clientAuth() fhir.Auth {
55+
if basicAuthUser != "" && basicAuthPassword != "" {
56+
return fhir.BasicAuth{User: basicAuthUser, Password: basicAuthPassword}
57+
} else if bearerToken != "" {
58+
return fhir.TokenAuth{Token: bearerToken}
59+
} else {
60+
return nil
61+
}
62+
}
63+
4864
// rootCmd represents the base command when called without any subcommands
4965
var rootCmd = &cobra.Command{
5066
Use: "blazectl",
@@ -53,7 +69,7 @@ var rootCmd = &cobra.Command{
5369
5470
Currently you can upload transaction bundles from a directory, download
5571
and count resources and evaluate measures.`,
56-
Version: "0.13.1",
72+
Version: "0.14.0",
5773
}
5874

5975
// Execute adds all child commands to the root command and sets flags appropriately.
@@ -67,7 +83,9 @@ func Execute() {
6783

6884
func init() {
6985
rootCmd.PersistentFlags().BoolVarP(&disableTlsSecurity, "insecure", "k", false, "allow insecure server connections when using SSL")
86+
rootCmd.PersistentFlags().StringVar(&caCert, "certificate-authority", "", "path to a cert file for the certificate authority")
7087
rootCmd.PersistentFlags().StringVar(&basicAuthUser, "user", "", "user information for basic authentication")
7188
rootCmd.PersistentFlags().StringVar(&basicAuthPassword, "password", "", "password information for basic authentication")
89+
rootCmd.PersistentFlags().StringVar(&bearerToken, "token", "", "bearer token for authentication")
7290
rootCmd.PersistentFlags().BoolVarP(&noProgress, "no-progress", "", false, "don't show progress bar")
7391
}

fhir/client.go

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
package fhir
1616

1717
import (
18+
"crypto/tls"
19+
"crypto/x509"
1820
"encoding/json"
1921
"fmt"
2022
fm "github.com/samply/golang-fhir-models/fhir-models/fhir"
2123
"io"
2224
"net/http"
2325
"net/url"
26+
"os"
2427
"strings"
2528
)
2629

@@ -30,29 +33,73 @@ import (
3033
type Client struct {
3134
httpClient http.Client
3235
baseURL url.URL
33-
auth ClientAuth
36+
auth Auth
3437
}
3538

36-
// ClientAuth comprises the authentication information used by the Client in
39+
type Auth interface {
40+
setAuth(req *http.Request)
41+
}
42+
43+
// BasicAuth comprises basic authentication information used by the Client in
44+
// order to communicate with a FHIR server.
45+
type BasicAuth struct {
46+
User string
47+
Password string
48+
}
49+
50+
func (auth BasicAuth) setAuth(req *http.Request) {
51+
req.SetBasicAuth(auth.User, auth.Password)
52+
}
53+
54+
// TokenAuth comprises bearer token authentication information used by the Client in
3755
// order to communicate with a FHIR server.
38-
type ClientAuth struct {
39-
BasicAuthUser string
40-
BasicAuthPassword string
56+
type TokenAuth struct {
57+
Token string
4158
}
4259

43-
// NewClient creates a new Client with the given base URL and ClientAuth configuration.
44-
func NewClient(fhirServerBaseUrl url.URL, auth ClientAuth) *Client {
60+
func (auth TokenAuth) setAuth(req *http.Request) {
61+
req.Header.Set("Authorization", "Bearer "+auth.Token)
62+
}
63+
64+
// NewClient creates a new Client with the given base URL and BasicAuth configuration.
65+
func NewClient(fhirServerBaseUrl url.URL, auth Auth) *Client {
4566
return createClient(fhirServerBaseUrl, auth, false)
4667
}
4768

4869
// NewClientInsecure creates a new Client as NewClient does but disables TLS security checks. I.e. the client will
4970
// accept any connection to a servers without verifying its certificate.
5071
// Use this with great caution as it opens up man-in-the-middle attacks.
51-
func NewClientInsecure(fhirServerBaseUrl url.URL, auth ClientAuth) *Client {
72+
func NewClientInsecure(fhirServerBaseUrl url.URL, auth Auth) *Client {
5273
return createClient(fhirServerBaseUrl, auth, true)
5374
}
5475

55-
func createClient(fhirServerBaseUrl url.URL, auth ClientAuth, insecure bool) *Client {
76+
func NewClientCa(fhirServerBaseUrl url.URL, auth Auth, caCertFilename string) (*Client, error) {
77+
caCert, err := os.ReadFile(caCertFilename)
78+
if err != nil {
79+
return nil, err
80+
}
81+
82+
caCertPool := x509.NewCertPool()
83+
caCertPool.AppendCertsFromPEM(caCert)
84+
85+
tlsConfig := &tls.Config{
86+
RootCAs: caCertPool,
87+
}
88+
89+
t := http.DefaultTransport.(*http.Transport).Clone()
90+
t.MaxIdleConns = 100
91+
t.MaxConnsPerHost = 100
92+
t.MaxIdleConnsPerHost = 100
93+
t.TLSClientConfig = tlsConfig
94+
95+
return &Client{
96+
httpClient: http.Client{Transport: t},
97+
baseURL: fhirServerBaseUrl,
98+
auth: auth,
99+
}, nil
100+
}
101+
102+
func createClient(fhirServerBaseUrl url.URL, auth Auth, insecure bool) *Client {
56103
t := http.DefaultTransport.(*http.Transport).Clone()
57104
t.MaxIdleConns = 100
58105
t.MaxConnsPerHost = 100
@@ -158,8 +205,8 @@ func (c *Client) NewTypeOperationRequest(resourceType string, operationName stri
158205

159206
// Do calls Do on the HTTP client of the FHIR client.
160207
func (c *Client) Do(req *http.Request) (*http.Response, error) {
161-
if len(c.auth.BasicAuthUser) != 0 {
162-
req.SetBasicAuth(c.auth.BasicAuthUser, c.auth.BasicAuthPassword)
208+
if c.auth != nil {
209+
c.auth.setAuth(req)
163210
}
164211

165212
return c.httpClient.Do(req)

0 commit comments

Comments
 (0)