Skip to content

Commit

Permalink
Teach cup to connect to Tailscale.
Browse files Browse the repository at this point in the history
  • Loading branch information
brettbuddin committed Aug 15, 2023
1 parent cc9cb2a commit f0da971
Show file tree
Hide file tree
Showing 20 changed files with 1,549 additions and 39 deletions.
2 changes: 1 addition & 1 deletion build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"crypto/sha256"
"fmt"
"log/slog"
"os"

"dagger.io/dagger"
"github.com/containerd/containerd/platforms"
"github.com/urfave/cli/v2"
"go.flipt.io/cup/build/hack"
"golang.org/x/exp/slog"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cmd/cup/ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"log/slog"
"net/http"
"os"
"os/exec"
Expand All @@ -15,7 +16,6 @@ import (

"go.flipt.io/cup/pkg/api/core"
"go.flipt.io/cup/pkg/encoding"
"golang.org/x/exp/slog"
)

var editor = "vim"
Expand Down
2 changes: 1 addition & 1 deletion cmd/cup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"encoding/json"
"errors"
"fmt"
"log/slog"
"net/http"
"os"
"path"

"github.com/urfave/cli/v2"
"golang.org/x/exp/slog"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cupd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"errors"
"flag"
"log/slog"
"os"

"github.com/peterbourgon/ff/v3"
"github.com/peterbourgon/ff/v3/ffcli"
"github.com/peterbourgon/ff/v3/ffyaml"
"go.flipt.io/cup/pkg/config"
"golang.org/x/exp/slog"
)

func main() {
Expand Down
36 changes: 32 additions & 4 deletions cmd/cupd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"context"
"fmt"
"log/slog"
"net"
"net/http"

"code.gitea.io/sdk/gitea"
Expand All @@ -15,7 +17,7 @@ import (
scmgitea "go.flipt.io/cup/pkg/source/git/scm/gitea"
scmgithub "go.flipt.io/cup/pkg/source/git/scm/github"
"go.flipt.io/cup/pkg/source/local"
"golang.org/x/exp/slog"
"tailscale.com/tsnet"
)

func serve(ctx context.Context, cfg *config.Config) error {
Expand Down Expand Up @@ -80,12 +82,38 @@ func serve(ctx context.Context, cfg *config.Config) error {
return err
}

var listener net.Listener
if cfg.Tailscale.Hostname == "" {
listener, err = net.Listen("tcp", cfg.API.Address)
if err != nil {
return err
}
defer listener.Close()
} else {
s := &tsnet.Server{
Hostname: cfg.Tailscale.Hostname,
AuthKey: cfg.Tailscale.AuthKey,
Ephemeral: cfg.Tailscale.Ephemeral,
}
defer s.Close()

listener, err = s.Listen("tcp", cfg.API.Address)
if err != nil {
return err
}
defer listener.Close()

apiConfig.TailscaleClient, err = s.LocalClient()
if err != nil {
return err
}
}

srv, err := api.NewServer(fs, apiConfig)
if err != nil {
return err
}

slog.Info("Listening...", "address", cfg.API.Address)

return http.ListenAndServe(cfg.API.Address, srv)
slog.Info("Listening...", "address", listener.Addr())
return http.Serve(listener, srv)
}
2 changes: 1 addition & 1 deletion ext/controllers/flipt.io/v1alpha1/cmd/flipt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"errors"
"fmt"
"io/fs"
"log/slog"
"os"

"go.flipt.io/cup/ext/controllers/flipt.io/v1alpha1/pkg/ext"

"github.com/gobwas/glob"
sdk "go.flipt.io/cup/sdk/controller/go"
"golang.org/x/exp/slog"
"gopkg.in/yaml.v3"
)

Expand Down
72 changes: 67 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module go.flipt.io/cup

go 1.20
go 1.21

require (
code.gitea.io/sdk/gitea v0.15.1
Expand All @@ -16,43 +16,105 @@ require (
github.com/tetratelabs/wazero v1.3.1
github.com/urfave/cli/v2 v2.25.7
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090
tailscale.com v1.1.1-0.20230810031934-6ee85ba41222
)

require (
filippo.io/edwards25519 v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230626094100-7e9e0395ebec // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/akutz/memconn v0.1.0 // indirect
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 // indirect
github.com/aws/aws-sdk-go-v2 v1.18.0 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.22 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.21 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27 // indirect
github.com/aws/aws-sdk-go-v2/service/ssm v1.36.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.9 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.9 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.18.10 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/coreos/go-iptables v0.6.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dblohm7/wingoes v0.0.0-20230803162905-5c6286bb8c6e // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/go-version v1.2.1 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/google/nftables v0.1.1-0.20230115205135-9aa6fdf5a28c // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/illarion/gonotify v1.0.1 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/insomniacslk/dhcp v0.0.0-20230407062729-974c6f05fe16 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/native v1.1.1-0.20230202152459-5c7d0dd6ab86 // indirect
github.com/jsimonetti/rtnetlink v1.3.2 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/kortschak/wol v0.0.0-20200729010619-da482cc4850a // indirect
github.com/mdlayher/genetlink v1.3.2 // indirect
github.com/mdlayher/netlink v1.7.2 // indirect
github.com/mdlayher/sdnotify v1.0.0 // indirect
github.com/mdlayher/socket v0.4.1 // indirect
github.com/miekg/dns v1.1.55 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/pierrec/lz4/v4 v4.1.17 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.1.1 // indirect
github.com/tailscale/certstore v0.1.1-0.20220316223106-78d6e1c49d8d // indirect
github.com/tailscale/golang-x-crypto v0.0.0-20230713185742-f0b76a10a08e // indirect
github.com/tailscale/goupnp v1.0.1-0.20210804011211-c64d0f06ea05 // indirect
github.com/tailscale/netlink v1.1.1-0.20211101221916-cabfb018fe85 // indirect
github.com/tailscale/wireguard-go v0.0.0-20230710185534-bb2c8f22eccf // indirect
github.com/tcnksm/go-httpstat v0.2.0 // indirect
github.com/u-root/uio v0.0.0-20230305220412-3e8cd9d6bf63 // indirect
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
go4.org/netipx v0.0.0-20230728180743-ad4cb58a6516 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.11.1 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gvisor.dev/gvisor v0.0.0-20230504175454-7b0a1988a28f // indirect
inet.af/peercred v0.0.0-20210906144145-0893ea02156a // indirect
nhooyr.io/websocket v1.8.7 // indirect
)
Loading

0 comments on commit f0da971

Please sign in to comment.