Skip to content

Commit 8cd8e47

Browse files
authored
Merge branch 'openziti:main' into main
2 parents fa4af6c + 1b39dc9 commit 8cd8e47

31 files changed

+640
-261
lines changed

.github/CODEOWNERS

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# see:
2+
# https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-code-owners
3+
* @openziti/maintainers
4+

.github/workflows/main.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Install Go
2121
uses: actions/setup-go@v2
2222
with:
23-
go-version: '~1.16.0'
23+
go-version: '~1.18.0'
2424

2525
- name: Install Ziti CI
2626
uses: netfoundry/ziti-ci@v1
@@ -33,6 +33,8 @@ jobs:
3333
- name: Release
3434
env:
3535
gh_ci_key: ${{ secrets.GH_CI_KEY }}
36+
ziti_ci_gpg_key: ${{ secrets.ZITI_CI_GPG_KEY }}
37+
ziti_ci_gpg_key_id: ${{ secrets.ZITI_CI_GPG_KEY_ID }}
3638
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-')
3739
run: |
3840
$(go env GOPATH)/bin/ziti-ci configure-git

.github/workflows/mattermost-ziti-webhook.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
mattermost-ziti-webhook:
1616
runs-on: macos-latest
1717
name: POST Webhook
18+
if: github.actor!= 'dependabot[bot]'
1819
steps:
1920
- uses: openziti/ziti-webhook-action@main
2021
with:

.github/workflows/update-dependency.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@ jobs:
1919
- name: Install Go
2020
uses: actions/setup-go@v2
2121
with:
22-
go-version: '~1.16.0'
22+
go-version: '~1.18.0'
2323

2424
- name: Install Ziti CI
2525
uses: netfoundry/ziti-ci@v1
2626

2727
- name: Update Dependency
2828
env:
2929
gh_ci_key: ${{ secrets.GH_CI_KEY }}
30+
ziti_ci_gpg_key: ${{ secrets.ZITI_CI_GPG_KEY }}
31+
ziti_ci_gpg_key_id: ${{ secrets.ZITI_CI_GPG_KEY_ID }}
3032
run: |
3133
$(go env GOPATH)/bin/ziti-ci configure-git
3234
$(go env GOPATH)/bin/ziti-ci update-go-dependency ${{ github.event.inputs.updated-dependency }}
3335
3436
- name: Build and Test
35-
run: go test ./...
37+
run: go test ./... --tags apitests
3638

3739
- name: Complete Dependency Update
3840
run: $(go env GOPATH)/bin/ziti-ci complete-update-go-dependency

buildinfo.yml

-2
This file was deleted.

exercises/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Excercises
2+
3+
This directory is meant for any code samples or documentation that would help one learn more about how to use the Ziti SDK for go.
4+
5+
The first exercise shows code before and after zitifying a simple http server.

exercises/http/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# HTTP
2+
3+
This exercise takes a simple server listening on a port. The example is contrived and simple on purpose. When deploying
4+
locally the basic setup would look like this:
5+
6+
![image](./simple-example.png)
7+
8+
When deploying a server like this out to the internet, for example using AWS, that same basic overview would
9+
probably look more like this simplified diagram below. Notice that port 8090 is now open through the firewall. The
10+
server is also listening on port 8090.
11+
12+
![image](./simple-cloud.png)
13+
14+
With Ziti you can eliminate the need for listening ports, the need for firewall holes in you deployments entirely.
15+
This is what the same example looks like using Ziti. Notice no inbound firewall ports needed on either side. No
16+
listening port at all in the zitified example, just a Ziti service which is "bound" to the server identity
17+
18+
![image](./simple-zitified-example.png)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"net/http"
7+
)
8+
9+
func main() {
10+
target := "localhost:8090"
11+
helloUrl := fmt.Sprintf("http://%s/hello", target)
12+
httpClient := http.Client{}
13+
resp, e := httpClient.Get(helloUrl)
14+
if e != nil {
15+
panic(e)
16+
}
17+
body, _ := ioutil.ReadAll(resp.Body)
18+
fmt.Println("Hello response:", string(body))
19+
20+
a := 1
21+
b := 2
22+
addUrl := fmt.Sprintf("http://%s/add?a=%d&b=%d", target, a, b)
23+
resp, _ = httpClient.Get(addUrl)
24+
if e != nil {
25+
panic(e)
26+
}
27+
body, _ = ioutil.ReadAll(resp.Body)
28+
fmt.Println("Add Result:", string(body))
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"github.com/openziti/sdk-golang/ziti"
7+
"github.com/openziti/sdk-golang/ziti/config"
8+
"io/ioutil"
9+
"net"
10+
"net/http"
11+
"os"
12+
"strings"
13+
)
14+
15+
func main() {
16+
target := os.Args[2]
17+
helloUrl := fmt.Sprintf("http://%s/hello", target)
18+
httpClient := createZitifiedHttpClient(os.Args[1])
19+
resp, e := httpClient.Get(helloUrl)
20+
if e != nil {
21+
panic(e)
22+
}
23+
body, _ := ioutil.ReadAll(resp.Body)
24+
fmt.Println("Hello response:", string(body))
25+
26+
a := 1
27+
b := 2
28+
addUrl := fmt.Sprintf("http://%s/add?a=%d&b=%d", target, a, b)
29+
resp, _ = httpClient.Get(addUrl)
30+
if e != nil {
31+
panic(e)
32+
}
33+
body, _ = ioutil.ReadAll(resp.Body)
34+
fmt.Println("Add Result:", string(body))
35+
}
36+
37+
var zitiContext ziti.Context
38+
39+
func Dial(_ context.Context, _ string, addr string) (net.Conn, error) {
40+
service := strings.Split(addr, ":")[0] // will always get passed host:port
41+
return zitiContext.Dial(service)
42+
}
43+
func createZitifiedHttpClient(idFile string) http.Client {
44+
cfg, err := config.NewFromFile(idFile)
45+
if err != nil {
46+
panic(err)
47+
}
48+
zitiContext = ziti.NewContextWithConfig(cfg)
49+
zitiTransport := http.DefaultTransport.(*http.Transport).Clone() // copy default transport
50+
zitiTransport.DialContext = Dial //zitiDialContext.Dial
51+
return http.Client{Transport: zitiTransport}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"os"
7+
"strconv"
8+
)
9+
10+
func main() {
11+
http.HandleFunc("/hello", hello)
12+
http.HandleFunc("/add", add)
13+
if err := http.ListenAndServe(":8090", nil); err != nil {
14+
panic(err)
15+
}
16+
}
17+
18+
func hello(w http.ResponseWriter, req *http.Request) {
19+
host, _ := os.Hostname()
20+
fmt.Fprintf(w, "zitified hello from %s", host)
21+
}
22+
23+
func add(w http.ResponseWriter, req *http.Request) {
24+
a, _ := strconv.Atoi(req.URL.Query().Get("a"))
25+
b, _ := strconv.Atoi(req.URL.Query().Get("b"))
26+
c := a + b
27+
fmt.Fprintf(w, "a+b=%d+%d=%d", a, b, c)
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/openziti/sdk-golang/ziti"
6+
"github.com/openziti/sdk-golang/ziti/config"
7+
"net"
8+
"net/http"
9+
"os"
10+
"strconv"
11+
"time"
12+
)
13+
14+
func main() {
15+
http.HandleFunc("/hello", hello)
16+
http.HandleFunc("/add", add)
17+
if err := http.Serve(createZitiListener(), nil); err != nil {
18+
panic(err)
19+
}
20+
}
21+
22+
func hello(w http.ResponseWriter, req *http.Request) {
23+
host, _ := os.Hostname()
24+
fmt.Fprintf(w, "zitified hello from %s", host)
25+
}
26+
27+
func add(w http.ResponseWriter, req *http.Request) {
28+
a, _ := strconv.Atoi(req.URL.Query().Get("a"))
29+
b, _ := strconv.Atoi(req.URL.Query().Get("b"))
30+
c := a + b
31+
fmt.Fprintf(w, "zitified a+b=%d+%d=%d", a, b, c)
32+
}
33+
34+
func createZitiListener() net.Listener {
35+
cfg, err := config.NewFromFile(os.Args[1])
36+
if err != nil {
37+
panic(err)
38+
}
39+
options := ziti.ListenOptions{
40+
ConnectTimeout: 5 * time.Minute,
41+
}
42+
listener, err := ziti.NewContextWithConfig(cfg).ListenWithOptions(os.Args[2], &options)
43+
if err != nil {
44+
fmt.Printf("Error binding service %+v\n", err)
45+
panic(err)
46+
}
47+
return listener
48+
}

exercises/http/simple-cloud.png

46.3 KB
Loading

exercises/http/simple-example.png

24.1 KB
Loading
47.8 KB
Loading

go.mod

+42-15
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,60 @@
11
module github.com/openziti/sdk-golang
22

3-
go 1.16
3+
go 1.17
44

55
//replace github.com/openziti/foundation => ../foundation
66

77
require (
88
github.com/Jeffail/gabs v1.4.0
9-
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
10-
github.com/cenkalti/backoff/v4 v4.1.1
11-
github.com/deepmap/oapi-codegen v1.8.2 // indirect
9+
github.com/cenkalti/backoff/v4 v4.1.3
1210
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa
13-
github.com/go-ole/go-ole v1.2.5 // indirect
1411
github.com/golang-jwt/jwt v3.2.2+incompatible
1512
github.com/google/uuid v1.3.0
16-
github.com/influxdata/influxdb-client-go/v2 v2.4.0
17-
github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 // indirect
18-
github.com/michaelquigley/pfxlog v0.6.1
13+
github.com/influxdata/influxdb-client-go/v2 v2.8.1
14+
github.com/michaelquigley/pfxlog v0.6.9
1915
github.com/mitchellh/go-ps v1.0.0
20-
github.com/mitchellh/mapstructure v1.4.2
16+
github.com/mitchellh/mapstructure v1.4.3
2117
github.com/netfoundry/secretstream v0.1.2
22-
github.com/openziti/foundation v0.15.76
18+
github.com/openziti/channel v0.18.28
19+
github.com/openziti/foundation v0.17.22
20+
github.com/openziti/transport v0.1.5
2321
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6
2422
github.com/pkg/errors v0.9.1
2523
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0
26-
github.com/shirou/gopsutil v2.20.9+incompatible
24+
github.com/shirou/gopsutil v2.21.11+incompatible
2725
github.com/sirupsen/logrus v1.8.1
28-
github.com/spf13/cobra v1.2.1
29-
github.com/stretchr/testify v1.7.0
26+
github.com/spf13/cobra v1.4.0
27+
github.com/stretchr/testify v1.7.1
3028
go.mozilla.org/pkcs7 v0.0.0-20200128120323-432b2356ecb1
31-
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
32-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1
29+
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f
30+
)
31+
32+
require (
33+
github.com/davecgh/go-spew v1.1.1 // indirect
34+
github.com/deepmap/oapi-codegen v1.8.2 // indirect
35+
github.com/emirpasic/gods v1.12.0 // indirect
36+
github.com/go-ole/go-ole v1.2.6 // indirect
37+
github.com/golang/protobuf v1.5.2 // indirect
38+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
39+
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d // indirect
40+
github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 // indirect
41+
github.com/kr/text v0.2.0 // indirect
42+
github.com/mattn/go-colorable v0.1.12 // indirect
43+
github.com/mattn/go-isatty v0.0.14 // indirect
44+
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
45+
github.com/miekg/pkcs11 v1.1.1 // indirect
46+
github.com/parallaxsecond/parsec-client-go v0.0.0-20220111122524-cb78842db373 // indirect
47+
github.com/pmezard/go-difflib v1.0.0 // indirect
48+
github.com/speps/go-hashids v2.0.0+incompatible // indirect
49+
github.com/spf13/pflag v1.0.5 // indirect
50+
github.com/tklauser/go-sysconf v0.3.9 // indirect
51+
github.com/tklauser/numcpus v0.3.0 // indirect
52+
github.com/yusufpapurcu/wmi v1.2.2 // indirect
53+
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 // indirect
54+
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
55+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
56+
golang.org/x/text v0.3.7 // indirect
57+
google.golang.org/protobuf v1.28.0 // indirect
58+
gopkg.in/yaml.v2 v2.4.0 // indirect
59+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
3360
)

0 commit comments

Comments
 (0)