Skip to content

Commit

Permalink
remove useless code that also made naisdevice not work on nixos
Browse files Browse the repository at this point in the history
  • Loading branch information
sechmann committed May 7, 2024
1 parent 10a0c6d commit 270a3bd
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 185 deletions.
17 changes: 0 additions & 17 deletions cmd/auth-server/go.mod

This file was deleted.

64 changes: 0 additions & 64 deletions cmd/auth-server/go.sum

This file was deleted.

26 changes: 26 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
description = "A simple Go package";

# Nixpkgs / NixOS version to use.
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";

outputs = {
self,
nixpkgs,
}: let
# to work with older version of flakes
lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";

# Generate a user-friendly version number.
version = builtins.substring 0 8 lastModifiedDate;

# System types to support.
supportedSystems = ["x86_64-linux"]; # "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];

# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;

# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;});
in {
# Provide some binary packages for selected system types.
packages = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
in {
device-agent = pkgs.buildGoModule {
pname = "device-agent";
inherit version;
# In 'nix develop', we don't need a copy of the source tree
# in the Nix store.
src = ./.;

# This hash locks the dependencies of this package. It is
# necessary because of how Go requires network access to resolve
# VCS. See https://www.tweag.io/blog/2021-03-04-gomod2nix/ for
# details. Normally one can build with a fake hash and rely on native Go
# mechanisms to tell you what the hash should be or determine what
# it should be "out-of-band" with other tooling (eg. gomod2nix).
# To begin with it is recommended to set this, but one must
# remember to bump this hash when your dependencies change.
# vendorHash = pkgs.lib.fakeHash;

vendorHash = "sha256-AgRQO3h7Atq4lnieTBohzrwrw0lRcbQi2cvpeol3owM=";
};
});

# Add dependencies that are only needed for development
devShells = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
in {
default = pkgs.mkShell {
buildInputs = with pkgs; [go gopls gotools go-tools];
};
});

# The default package for 'nix build'. This makes sense if the
# flake provides only one package or there is a clear "main"
# package.
defaultPackage = forAllSystems (system: self.packages.${system}.device-agent);
};
}
12 changes: 7 additions & 5 deletions internal/device-agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ type Config struct {
GoogleOAuth2Config oauth2.Config
Platform string
PrivateKeyPath string
WireGuardBinary string
WireGuardConfigPath string
WireGuardGoBinary string
EnrollProjectID string
EnrollTopicName string
}

func (c *Config) SetDefaults() {
c.Platform = Platform
c.SetPlatformDefaults()
c.Interface = "utun69"
c.PrivateKeyPath = filepath.Join(c.ConfigDir, "private.key")
c.WireGuardConfigPath = filepath.Join(c.ConfigDir, c.Interface+".conf")
}
Expand All @@ -60,8 +58,12 @@ func DefaultConfig() (*Config, error) {
DeviceAgentHelperAddress: filepath.Join(config2.RuntimeDir, "helper.sock"),
GoogleAuthServerAddress: "https://naisdevice-auth-server-h2pjqrstja-lz.a.run.app",
AzureOAuth2Config: oauth2.Config{
ClientID: "8086d321-c6d3-4398-87da-0d54e3d93967",
Scopes: []string{"openid", "6e45010d-2637-4a40-b91d-d4cbb451fb57/.default", "offline_access"},
ClientID: "8086d321-c6d3-4398-87da-0d54e3d93967",
Scopes: []string{
"openid",
"6e45010d-2637-4a40-b91d-d4cbb451fb57/.default",
"offline_access",
},
Endpoint: endpoints.AzureAD("62366534-1ec3-4962-8869-9b5535279d0b"),
RedirectURL: "http://localhost:PORT/",
},
Expand Down
15 changes: 0 additions & 15 deletions internal/device-agent/config/config_darwin.go

This file was deleted.

14 changes: 0 additions & 14 deletions internal/device-agent/config/config_linux.go

This file was deleted.

15 changes: 0 additions & 15 deletions internal/device-agent/config/config_windows.go

This file was deleted.

6 changes: 1 addition & 5 deletions internal/device-agent/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ import (
)

func EnsurePrerequisites(c *config.Config) error {
if err := filesExist(c.WireGuardBinary); err != nil {
return fmt.Errorf("verifying if file exists: %v", err)
}

if err := ensureDirectories(c.ConfigDir); err != nil {
return fmt.Errorf("ensuring directory exists: %v", err)
}

return ensurePlatformPrerequisites(c)
return nil
}

func FileMustExist(filepath string) error {
Expand Down
18 changes: 0 additions & 18 deletions internal/device-agent/filesystem/filesystem_darwin.go

This file was deleted.

9 changes: 0 additions & 9 deletions internal/device-agent/filesystem/filesystem_linux.go

This file was deleted.

9 changes: 0 additions & 9 deletions internal/device-agent/filesystem/filesystem_windows.go

This file was deleted.

38 changes: 31 additions & 7 deletions internal/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ type DeviceHelperServer struct {
log *logrus.Entry
}

func NewDeviceHelperServer(log *logrus.Entry, config Config, osConfigurator OSConfigurator) *DeviceHelperServer {
func NewDeviceHelperServer(
log *logrus.Entry,
config Config,
osConfigurator OSConfigurator,
) *DeviceHelperServer {
return &DeviceHelperServer{
log: log,
config: config,
osConfigurator: osConfigurator,
}
}

func (dhs *DeviceHelperServer) Teardown(ctx context.Context, req *pb.TeardownRequest) (*pb.TeardownResponse, error) {
func (dhs *DeviceHelperServer) Teardown(
ctx context.Context,
req *pb.TeardownRequest,
) (*pb.TeardownResponse, error) {
dhs.log.Infof("Removing network interface '%s' and all routes", dhs.config.Interface)
err := dhs.osConfigurator.TeardownInterface(ctx)
if err != nil {
Expand All @@ -64,7 +71,10 @@ func (dhs *DeviceHelperServer) Teardown(ctx context.Context, req *pb.TeardownReq
return &pb.TeardownResponse{}, nil
}

func (dhs *DeviceHelperServer) Configure(ctx context.Context, cfg *pb.Configuration) (*pb.ConfigureResponse, error) {
func (dhs *DeviceHelperServer) Configure(
ctx context.Context,
cfg *pb.Configuration,
) (*pb.ConfigureResponse, error) {
dhs.log.Infof("New configuration received from device-agent")

err := dhs.writeConfigFile(cfg)
Expand All @@ -85,14 +95,22 @@ func (dhs *DeviceHelperServer) Configure(ctx context.Context, cfg *pb.Configurat
if loopErr != nil {
backoff := time.Duration(attempt) * time.Second
dhs.log.Errorf("synchronize WireGuard configuration: %s", loopErr)
dhs.log.Infof("attempt %d at configuring failed, sleeping %v before retrying", attempt+1, backoff)
dhs.log.Infof(
"attempt %d at configuring failed, sleeping %v before retrying",
attempt+1,
backoff,
)
time.Sleep(backoff)
continue
}
break
}
if loopErr != nil {
return nil, status.Errorf(codes.FailedPrecondition, "synchronize WireGuard configuration: %s", loopErr)
return nil, status.Errorf(
codes.FailedPrecondition,
"synchronize WireGuard configuration: %s",
loopErr,
)
}

err = dhs.osConfigurator.SetupRoutes(ctx, cfg.GetGateways())
Expand Down Expand Up @@ -129,14 +147,20 @@ func (dhs *DeviceHelperServer) writeConfigFile(cfg *pb.Configuration) error {
return nil
}

func (dhs *DeviceHelperServer) GetSerial(context.Context, *pb.GetSerialRequest) (*pb.GetSerialResponse, error) {
func (dhs *DeviceHelperServer) GetSerial(
context.Context,
*pb.GetSerialRequest,
) (*pb.GetSerialResponse, error) {
device_serial, err := serial.GetDeviceSerial()
if err != nil {
return nil, err
}
return &pb.GetSerialResponse{Serial: device_serial}, nil
}

func (dhs *DeviceHelperServer) Upgrade(context.Context, *pb.UpgradeRequest) (*pb.UpgradeResponse, error) {
func (dhs *DeviceHelperServer) Upgrade(
context.Context,
*pb.UpgradeRequest,
) (*pb.UpgradeResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Upgrade not implemented")
}
Loading

0 comments on commit 270a3bd

Please sign in to comment.