Skip to content

Commit

Permalink
feat(cmd/flipt): wire in flipt client listener
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeMac committed May 1, 2024
1 parent 866a77c commit 076b7c1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
40 changes: 25 additions & 15 deletions cmd/flipt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package main
import (
"bytes"
"context"
"crypto/tls"
"errors"
"fmt"
"io/fs"
"net/http"
"os"
"os/signal"
"path/filepath"
Expand All @@ -22,6 +24,8 @@ import (
"go.flipt.io/flipt/internal/info"
"go.flipt.io/flipt/internal/release"
"go.flipt.io/flipt/internal/telemetry"
"go.flipt.io/reverst/client"
"go.flipt.io/reverst/pkg/protocol"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -370,26 +374,32 @@ func run(ctx context.Context, logger *zap.Logger, cfg *config.Config) error {

if cfg.Server.Cloud.Enabled {
// starts QUIC tunnel server to connect to Cloud
var (
orgHost = fmt.Sprintf("%s.%s", cfg.Server.Cloud.Organization, cfg.Server.Cloud.Address)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Tests (Go - Darwin)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Tests (Migration)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/cache)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / UI Integration Tests

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/cockroach)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/mysql)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/sqlite)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/postgres)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/libsql)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Tests (Go)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Lint Go

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / CLI Integration Tests

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/gcs)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/git)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/azblob)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/local)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/oci)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/s3)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Benchmark SQLite

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)

Check failure on line 378 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (import/export)

cfg.Server.Cloud.Organization undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Organization)
tunnel = fmt.Sprintf("%s-%s", cfg.Server.Cloud.Instance, orgHost)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Tests (Go - Darwin)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Tests (Migration)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/cache)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / UI Integration Tests

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/cockroach)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/mysql)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/sqlite)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/postgres)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/libsql)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Tests (Go)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Lint Go

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / CLI Integration Tests

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/gcs)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/git)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/azblob)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/local)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/oci)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/s3)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Benchmark SQLite

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)

Check failure on line 379 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (import/export)

cfg.Server.Cloud.Instance undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Instance)
)

// TODO: get organization, instance, and authentication from config

// g.Go(func() error {
// tunnelServer := &client.Server{
// TunnelGroup: fmt.Sprintf("%s.%s", cfg.Server.Cloud.Organization, cfg.Server.Cloud.Address),
// Handler: httpServer.Handler,
// Authenticator: client.BearerAuthenticator(cfg.Server.Cloud.Authentication.ApiKey),
// }
g.Go(func() error {
tunnelServer := &client.Server{
TunnelGroup: tunnel,
Handler: httpServer.Handler,
Authenticator: client.BearerAuthenticator(cfg.Server.Cloud.Authentication.ApiKey),

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Tests (Go - Darwin)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Tests (Migration)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/cache)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / UI Integration Tests

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/cockroach)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/mysql)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/sqlite)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/postgres)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (api/libsql)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Tests (Go)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Lint Go

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication) (typecheck)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / CLI Integration Tests

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/gcs)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/git)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/azblob)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/local)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/oci)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (fs/s3)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Benchmark SQLite

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)

Check failure on line 386 in cmd/flipt/main.go

View workflow job for this annotation

GitHub Actions / Integration Tests (import/export)

cfg.Server.Cloud.Authentication undefined (type "go.flipt.io/flipt/internal/config".CloudConfig has no field or method Authentication)
TLSConfig: &tls.Config{
NextProtos: []string{protocol.Name},
ServerName: orgHost,
},
}

// tunnel := fmt.Sprintf("%s-%s.%s", cfg.Server.Cloud.Instance, cfg.Server.Cloud.Organization, cfg.Server.Cloud.Address)
addr := fmt.Sprintf("%s:%d", tunnel, cfg.Server.Cloud.Port)

// logger.Info("cloud tunnel available", zap.String("address", tunnel), zap.Int("port", cfg.Server.Cloud.Port))
logger.Info("cloud tunnel established", zap.String("address", fmt.Sprintf("https://%s", tunnel)))

// if err := tunnelServer.DialAndServe(ctx, fmt.Sprintf("%s:%d", tunnel, cfg.Server.Cloud.Port)); !errors.Is(err, http.ErrServerClosed) {
// return fmt.Errorf("cloud tunnel server: %w", err)
// }
if err := tunnelServer.DialAndServe(ctx, addr); err != nil && !errors.Is(err, http.ErrServerClosed) {
return fmt.Errorf("cloud tunnel server: %w", err)
}

// return nil
// })
return nil
})
}

// block until root context is cancelled
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.flipt.io/reverst v0.1.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/contrib/propagators/aws v1.25.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
go.flipt.io/reverst v0.1.2 h1:L43Jx5oWAQwOCK6J/bCN9fXgIIGymnJx1yyp2UCbb14=
go.flipt.io/reverst v0.1.2/go.mod h1:0kDf22udIDgZAruOu6/9/dZIHRpWJhDcZ3fqoP33jc0=
go.mongodb.org/mongo-driver v1.11.4/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
Expand Down

0 comments on commit 076b7c1

Please sign in to comment.