Skip to content

Commit

Permalink
feat: buf formatting and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiebens committed Oct 31, 2022
1 parent e41bac5 commit c73b7e1
Show file tree
Hide file tree
Showing 31 changed files with 1,366 additions and 936 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,27 @@ on:
- main

jobs:
build:
buf-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Buf
uses: bufbuild/buf-setup-action@v1
- name: Buf Lint
uses: bufbuild/buf-lint-action@v1
with:
input: proto

build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.19

- name: Build
run: |
go test ./...
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ init:
go install github.com/bufbuild/connect-go/cmd/protoc-gen-connect-go@latest

generate:
buf generate proto
buf generate proto

format:
buf format -w proto

lint:
buf lint proto
2 changes: 1 addition & 1 deletion internal/cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func authLoginCommand() *coral.Command {
return err
}

req := &api.AuthenticationRequest{}
req := &api.AuthenticateRequest{}
stream, err := client.Authenticate(context.Background(), connect.NewRequest(req))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func findTailnet(client apiconnect.IonscaleServiceClient, tailnet string, tailne
return nil, fmt.Errorf("requested tailnet not found or you are not authorized for this tailnet")
}

tailnets, err := client.ListTailnets(context.Background(), connect.NewRequest(&api.ListTailnetRequest{}))
tailnets, err := client.ListTailnets(context.Background(), connect.NewRequest(&api.ListTailnetsRequest{}))
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions internal/cmd/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func getMachineRoutesCommand() *coral.Command {
return err
}

printMachinesRoutesResponse(resp.Msg)
printMachinesRoutesResponse(resp.Msg.Routes)

return nil
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func enableMachineRoutesCommand() *coral.Command {
return err
}

printMachinesRoutesResponse(resp.Msg)
printMachinesRoutesResponse(resp.Msg.Routes)

return nil
}
Expand Down Expand Up @@ -378,7 +378,7 @@ func disableMachineRoutesCommand() *coral.Command {
return err
}

printMachinesRoutesResponse(resp.Msg)
printMachinesRoutesResponse(resp.Msg.Routes)

return nil
}
Expand Down Expand Up @@ -412,7 +412,7 @@ func enableExitNodeCommand() *coral.Command {
return err
}

printMachinesRoutesResponse(resp.Msg)
printMachinesRoutesResponse(resp.Msg.Routes)

return nil
}
Expand Down Expand Up @@ -446,7 +446,7 @@ func disableExitNodeCommand() *coral.Command {
return err
}

printMachinesRoutesResponse(resp.Msg)
printMachinesRoutesResponse(resp.Msg.Routes)

return nil
}
Expand Down Expand Up @@ -500,7 +500,7 @@ func configureSetMachineKeyExpiryCommand(command *coral.Command, v bool) *coral.
return command
}

func printMachinesRoutesResponse(msg *api.GetMachineRoutesResponse) {
func printMachinesRoutesResponse(msg *api.MachineRoutes) {
w := new(tabwriter.Writer)
w.Init(os.Stdout, 8, 8, 0, '\t', 0)
defer w.Flush()
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/tailnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func listTailnetsCommand() *coral.Command {
return err
}

resp, err := client.ListTailnets(context.Background(), connect.NewRequest(&api.ListTailnetRequest{}))
resp, err := client.ListTailnets(context.Background(), connect.NewRequest(&api.ListTailnetsRequest{}))

if err != nil {
return err
Expand Down Expand Up @@ -388,7 +388,7 @@ func enableFileSharingCommand() *coral.Command {
TailnetId: tailnet.Id,
}

if _, err := client.EnabledFileSharing(context.Background(), connect.NewRequest(&req)); err != nil {
if _, err := client.EnableFileSharing(context.Background(), connect.NewRequest(&req)); err != nil {
return err
}

Expand Down Expand Up @@ -471,7 +471,7 @@ func enableServiceCollectionCommand() *coral.Command {
TailnetId: tailnet.Id,
}

if _, err := client.EnabledServiceCollection(context.Background(), connect.NewRequest(&req)); err != nil {
if _, err := client.EnableServiceCollection(context.Background(), connect.NewRequest(&req)); err != nil {
return err
}

Expand Down Expand Up @@ -553,7 +553,7 @@ func enableSSHCommand() *coral.Command {
TailnetId: tailnet.Id,
}

if _, err := client.EnabledSSH(context.Background(), connect.NewRequest(&req)); err != nil {
if _, err := client.EnableSSH(context.Background(), connect.NewRequest(&req)); err != nil {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions internal/service/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"
)

func (s *Service) Authenticate(ctx context.Context, req *connect.Request[api.AuthenticationRequest], stream *connect.ServerStream[api.AuthenticationResponse]) error {
func (s *Service) Authenticate(ctx context.Context, req *connect.Request[api.AuthenticateRequest], stream *connect.ServerStream[api.AuthenticateResponse]) error {
if s.authProvider == nil {
return connect.NewError(connect.CodeFailedPrecondition, errors.New("no authentication method available, contact your ionscale administrator for more information"))
}
Expand All @@ -27,7 +27,7 @@ func (s *Service) Authenticate(ctx context.Context, req *connect.Request[api.Aut
return err
}

if err := stream.Send(&api.AuthenticationResponse{AuthUrl: authUrl}); err != nil {
if err := stream.Send(&api.AuthenticateResponse{AuthUrl: authUrl}); err != nil {
return err
}

Expand All @@ -49,7 +49,7 @@ func (s *Service) Authenticate(ctx context.Context, req *connect.Request[api.Aut
}

if len(m.Token) != 0 {
if err := stream.Send(&api.AuthenticationResponse{Token: m.Token, TailnetId: m.TailnetID}); err != nil {
if err := stream.Send(&api.AuthenticateResponse{Token: m.Token, TailnetId: m.TailnetID}); err != nil {
return err
}
return nil
Expand All @@ -59,7 +59,7 @@ func (s *Service) Authenticate(ctx context.Context, req *connect.Request[api.Aut
return connect.NewError(connect.CodePermissionDenied, errors.New(m.Error))
}

if err := stream.Send(&api.AuthenticationResponse{AuthUrl: authUrl}); err != nil {
if err := stream.Send(&api.AuthenticateResponse{AuthUrl: authUrl}); err != nil {
return err
}

Expand Down
79 changes: 59 additions & 20 deletions internal/service/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,6 @@ func (s *Service) ExpireMachine(ctx context.Context, req *connect.Request[api.Ex
return connect.NewResponse(&api.ExpireMachineResponse{}), nil
}

func (s *Service) createMachineRoutesResponse(m *domain.Machine) (*connect.Response[api.GetMachineRoutesResponse], error) {
response := api.GetMachineRoutesResponse{
AdvertisedRoutes: m.AdvertisedPrefixes(),
EnabledRoutes: m.AllowedPrefixes(),
AdvertisedExitNode: m.IsAdvertisedExitNode(),
EnabledExitNode: m.IsAllowedExitNode(),
}

return connect.NewResponse(&response), nil
}

func (s *Service) GetMachineRoutes(ctx context.Context, req *connect.Request[api.GetMachineRoutesRequest]) (*connect.Response[api.GetMachineRoutesResponse], error) {
principal := CurrentPrincipal(ctx)

Expand All @@ -187,10 +176,20 @@ func (s *Service) GetMachineRoutes(ctx context.Context, req *connect.Request[api
return nil, connect.NewError(connect.CodePermissionDenied, errors.New("permission denied"))
}

return s.createMachineRoutesResponse(m)
response := api.GetMachineRoutesResponse{
MachineId: m.ID,
Routes: &api.MachineRoutes{
AdvertisedRoutes: m.AdvertisedPrefixes(),
EnabledRoutes: m.AllowedPrefixes(),
AdvertisedExitNode: m.IsAdvertisedExitNode(),
EnabledExitNode: m.IsAllowedExitNode(),
},
}

return connect.NewResponse(&response), nil
}

func (s *Service) EnableMachineRoutes(ctx context.Context, req *connect.Request[api.EnableMachineRoutesRequest]) (*connect.Response[api.GetMachineRoutesResponse], error) {
func (s *Service) EnableMachineRoutes(ctx context.Context, req *connect.Request[api.EnableMachineRoutesRequest]) (*connect.Response[api.EnableMachineRoutesResponse], error) {
principal := CurrentPrincipal(ctx)

m, err := s.repository.GetMachine(ctx, req.Msg.MachineId)
Expand Down Expand Up @@ -230,10 +229,20 @@ func (s *Service) EnableMachineRoutes(ctx context.Context, req *connect.Request[

s.pubsub.Publish(m.TailnetID, &broker.Signal{PeerUpdated: &m.ID})

return s.createMachineRoutesResponse(m)
response := api.EnableMachineRoutesResponse{
MachineId: m.ID,
Routes: &api.MachineRoutes{
AdvertisedRoutes: m.AdvertisedPrefixes(),
EnabledRoutes: m.AllowedPrefixes(),
AdvertisedExitNode: m.IsAdvertisedExitNode(),
EnabledExitNode: m.IsAllowedExitNode(),
},
}

return connect.NewResponse(&response), nil
}

func (s *Service) DisableMachineRoutes(ctx context.Context, req *connect.Request[api.DisableMachineRoutesRequest]) (*connect.Response[api.GetMachineRoutesResponse], error) {
func (s *Service) DisableMachineRoutes(ctx context.Context, req *connect.Request[api.DisableMachineRoutesRequest]) (*connect.Response[api.DisableMachineRoutesResponse], error) {
principal := CurrentPrincipal(ctx)

m, err := s.repository.GetMachine(ctx, req.Msg.MachineId)
Expand Down Expand Up @@ -269,10 +278,20 @@ func (s *Service) DisableMachineRoutes(ctx context.Context, req *connect.Request

s.pubsub.Publish(m.TailnetID, &broker.Signal{PeerUpdated: &m.ID})

return s.createMachineRoutesResponse(m)
response := api.DisableMachineRoutesResponse{
MachineId: m.ID,
Routes: &api.MachineRoutes{
AdvertisedRoutes: m.AdvertisedPrefixes(),
EnabledRoutes: m.AllowedPrefixes(),
AdvertisedExitNode: m.IsAdvertisedExitNode(),
EnabledExitNode: m.IsAllowedExitNode(),
},
}

return connect.NewResponse(&response), nil
}

func (s *Service) EnableExitNode(ctx context.Context, req *connect.Request[api.EnableExitNodeRequest]) (*connect.Response[api.GetMachineRoutesResponse], error) {
func (s *Service) EnableExitNode(ctx context.Context, req *connect.Request[api.EnableExitNodeRequest]) (*connect.Response[api.EnableExitNodeResponse], error) {
principal := CurrentPrincipal(ctx)

m, err := s.repository.GetMachine(ctx, req.Msg.MachineId)
Expand Down Expand Up @@ -306,10 +325,20 @@ func (s *Service) EnableExitNode(ctx context.Context, req *connect.Request[api.E

s.pubsub.Publish(m.TailnetID, &broker.Signal{PeerUpdated: &m.ID})

return s.createMachineRoutesResponse(m)
response := api.EnableExitNodeResponse{
MachineId: m.ID,
Routes: &api.MachineRoutes{
AdvertisedRoutes: m.AdvertisedPrefixes(),
EnabledRoutes: m.AllowedPrefixes(),
AdvertisedExitNode: m.IsAdvertisedExitNode(),
EnabledExitNode: m.IsAllowedExitNode(),
},
}

return connect.NewResponse(&response), nil
}

func (s *Service) DisableExitNode(ctx context.Context, req *connect.Request[api.DisableExitNodeRequest]) (*connect.Response[api.GetMachineRoutesResponse], error) {
func (s *Service) DisableExitNode(ctx context.Context, req *connect.Request[api.DisableExitNodeRequest]) (*connect.Response[api.DisableExitNodeResponse], error) {
principal := CurrentPrincipal(ctx)

m, err := s.repository.GetMachine(ctx, req.Msg.MachineId)
Expand Down Expand Up @@ -347,7 +376,17 @@ func (s *Service) DisableExitNode(ctx context.Context, req *connect.Request[api.

s.pubsub.Publish(m.TailnetID, &broker.Signal{PeerUpdated: &m.ID})

return s.createMachineRoutesResponse(m)
response := api.DisableExitNodeResponse{
MachineId: m.ID,
Routes: &api.MachineRoutes{
AdvertisedRoutes: m.AdvertisedPrefixes(),
EnabledRoutes: m.AllowedPrefixes(),
AdvertisedExitNode: m.IsAdvertisedExitNode(),
EnabledExitNode: m.IsAllowedExitNode(),
},
}

return connect.NewResponse(&response), nil
}

func (s *Service) SetMachineKeyExpiry(ctx context.Context, req *connect.Request[api.SetMachineKeyExpiryRequest]) (*connect.Response[api.SetMachineKeyExpiryResponse], error) {
Expand Down
10 changes: 5 additions & 5 deletions internal/service/tailnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ func (s *Service) GetTailnet(ctx context.Context, req *connect.Request[api.GetTa
}}), nil
}

func (s *Service) ListTailnets(ctx context.Context, req *connect.Request[api.ListTailnetRequest]) (*connect.Response[api.ListTailnetResponse], error) {
func (s *Service) ListTailnets(ctx context.Context, req *connect.Request[api.ListTailnetsRequest]) (*connect.Response[api.ListTailnetsResponse], error) {
principal := CurrentPrincipal(ctx)

resp := &api.ListTailnetResponse{}
resp := &api.ListTailnetsResponse{}

if principal.IsSystemAdmin() {
tailnets, err := s.repository.ListTailnets(ctx)
Expand Down Expand Up @@ -236,7 +236,7 @@ func (s *Service) GetDERPMap(ctx context.Context, req *connect.Request[api.GetDE
return connect.NewResponse(&api.GetDERPMapResponse{Value: raw}), nil
}

func (s *Service) EnabledFileSharing(ctx context.Context, req *connect.Request[api.EnableFileSharingRequest]) (*connect.Response[api.EnableFileSharingResponse], error) {
func (s *Service) EnableFileSharing(ctx context.Context, req *connect.Request[api.EnableFileSharingRequest]) (*connect.Response[api.EnableFileSharingResponse], error) {
principal := CurrentPrincipal(ctx)
if !principal.IsSystemAdmin() && !principal.IsTailnetAdmin(req.Msg.TailnetId) {
return nil, connect.NewError(connect.CodePermissionDenied, errors.New("permission denied"))
Expand Down Expand Up @@ -288,7 +288,7 @@ func (s *Service) DisableFileSharing(ctx context.Context, req *connect.Request[a
return connect.NewResponse(&api.DisableFileSharingResponse{}), nil
}

func (s *Service) EnabledServiceCollection(ctx context.Context, req *connect.Request[api.EnableServiceCollectionRequest]) (*connect.Response[api.EnableServiceCollectionResponse], error) {
func (s *Service) EnableServiceCollection(ctx context.Context, req *connect.Request[api.EnableServiceCollectionRequest]) (*connect.Response[api.EnableServiceCollectionResponse], error) {
principal := CurrentPrincipal(ctx)
if !principal.IsSystemAdmin() && !principal.IsTailnetAdmin(req.Msg.TailnetId) {
return nil, connect.NewError(connect.CodePermissionDenied, errors.New("permission denied"))
Expand Down Expand Up @@ -340,7 +340,7 @@ func (s *Service) DisableServiceCollection(ctx context.Context, req *connect.Req
return connect.NewResponse(&api.DisableServiceCollectionResponse{}), nil
}

func (s *Service) EnabledSSH(ctx context.Context, req *connect.Request[api.EnableSSHRequest]) (*connect.Response[api.EnableSSHResponse], error) {
func (s *Service) EnableSSH(ctx context.Context, req *connect.Request[api.EnableSSHRequest]) (*connect.Response[api.EnableSSHResponse], error) {
principal := CurrentPrincipal(ctx)
if !principal.IsSystemAdmin() && !principal.IsTailnetAdmin(req.Msg.TailnetId) {
return nil, connect.NewError(connect.CodePermissionDenied, errors.New("permission denied"))
Expand Down
Loading

0 comments on commit c73b7e1

Please sign in to comment.