Skip to content

Commit

Permalink
chore: updates code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Jan 28, 2024
1 parent 2ed64ea commit 9a582c7
Show file tree
Hide file tree
Showing 49 changed files with 1,185 additions and 607 deletions.
22 changes: 11 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ after improving the test harness as part of adopting [#1460](https://github.com/

### Changes

* Use versioned migrations [#1644](https://github.com/juanfont/headscale/pull/1644)
* Make the OIDC callback page better [#1484](https://github.com/juanfont/headscale/pull/1484)
* SSH support [#1487](https://github.com/juanfont/headscale/pull/1487)
* State management has been improved [#1492](https://github.com/juanfont/headscale/pull/1492)
* Use error group handling to ensure tests actually pass [#1535](https://github.com/juanfont/headscale/pull/1535) based on [#1460](https://github.com/juanfont/headscale/pull/1460)
* Fix hang on SIGTERM [#1492](https://github.com/juanfont/headscale/pull/1492) taken from [#1480](https://github.com/juanfont/headscale/pull/1480)
* Send logs to stderr by default [#1524](https://github.com/juanfont/headscale/pull/1524)
* Fix [TS-2023-006](https://tailscale.com/security-bulletins/#ts-2023-006) security UPnP issue [#1563](https://github.com/juanfont/headscale/pull/1563)
* Turn off gRPC logging [#1640](https://github.com/juanfont/headscale/pull/1640) fixes [#1259](https://github.com/juanfont/headscale/issues/1259)
* Added the possibility to manually create a DERP-map entry which can be customized, instead of automatically creating it. [#1565](https://github.com/juanfont/headscale/pull/1565)
* Add support for deleting api keys [#1702](https://github.com/juanfont/headscale/pull/1702)
- Use versioned migrations [#1644](https://github.com/juanfont/headscale/pull/1644)
- Make the OIDC callback page better [#1484](https://github.com/juanfont/headscale/pull/1484)
- SSH support [#1487](https://github.com/juanfont/headscale/pull/1487)
- State management has been improved [#1492](https://github.com/juanfont/headscale/pull/1492)
- Use error group handling to ensure tests actually pass [#1535](https://github.com/juanfont/headscale/pull/1535) based on [#1460](https://github.com/juanfont/headscale/pull/1460)
- Fix hang on SIGTERM [#1492](https://github.com/juanfont/headscale/pull/1492) taken from [#1480](https://github.com/juanfont/headscale/pull/1480)
- Send logs to stderr by default [#1524](https://github.com/juanfont/headscale/pull/1524)
- Fix [TS-2023-006](https://tailscale.com/security-bulletins/#ts-2023-006) security UPnP issue [#1563](https://github.com/juanfont/headscale/pull/1563)
- Turn off gRPC logging [#1640](https://github.com/juanfont/headscale/pull/1640) fixes [#1259](https://github.com/juanfont/headscale/issues/1259)
- Added the possibility to manually create a DERP-map entry which can be customized, instead of automatically creating it. [#1565](https://github.com/juanfont/headscale/pull/1565)
- Add support for deleting api keys [#1702](https://github.com/juanfont/headscale/pull/1702)

## 0.22.3 (2023-05-12)

Expand Down
5 changes: 4 additions & 1 deletion cmd/gh-action-integration-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ func main() {
log.Fatalf("failed to render template: %s", err)
}

testPath := path.Join(githubWorkflowPath, fmt.Sprintf(jobFileNameTemplate, test))
testPath := path.Join(
githubWorkflowPath,
fmt.Sprintf(jobFileNameTemplate, test),
)

err := os.WriteFile(testPath, content.Bytes(), workflowFilePerm)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion cmd/headscale/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
)

const (
errPreAuthKeyMalformed = Error("key is malformed. expected 64 hex characters with `nodekey` prefix")
errPreAuthKeyMalformed = Error(
"key is malformed. expected 64 hex characters with `nodekey` prefix",
)
)

// Error is used to compare errors as per https://dave.cheney.net/2016/04/07/constant-errors
Expand Down
7 changes: 6 additions & 1 deletion cmd/headscale/cli/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ var registerNodeCmd = &cobra.Command{

SuccessOutput(
response.GetNode(),
fmt.Sprintf("Node %s registered", response.GetNode().GetGivenName()), output)
fmt.Sprintf(
"Node %s registered",
response.GetNode().GetGivenName(),
),
output,
)
},
}

Expand Down
6 changes: 5 additions & 1 deletion cmd/headscale/cli/preauthkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ var createPreAuthKeyCmd = &cobra.Command{
return
}

SuccessOutput(response.GetPreAuthKey(), response.GetPreAuthKey().GetKey(), output)
SuccessOutput(
response.GetPreAuthKey(),
response.GetPreAuthKey().GetKey(),
output,
)
},
}

Expand Down
22 changes: 18 additions & 4 deletions cmd/headscale/cli/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ var enableRouteCmd = &cobra.Command{
if err != nil {
ErrorOutput(
err,
fmt.Sprintf("Cannot enable route %d: %s", routeID, status.Convert(err).Message()),
fmt.Sprintf(
"Cannot enable route %d: %s",
routeID,
status.Convert(err).Message(),
),
output,
)

Expand Down Expand Up @@ -207,7 +211,11 @@ var disableRouteCmd = &cobra.Command{
if err != nil {
ErrorOutput(
err,
fmt.Sprintf("Cannot disable route %d: %s", routeID, status.Convert(err).Message()),
fmt.Sprintf(
"Cannot disable route %d: %s",
routeID,
status.Convert(err).Message(),
),
output,
)

Expand Down Expand Up @@ -250,7 +258,11 @@ var deleteRouteCmd = &cobra.Command{
if err != nil {
ErrorOutput(
err,
fmt.Sprintf("Cannot delete route %d: %s", routeID, status.Convert(err).Message()),
fmt.Sprintf(
"Cannot delete route %d: %s",
routeID,
status.Convert(err).Message(),
),
output,
)

Expand All @@ -267,7 +279,9 @@ var deleteRouteCmd = &cobra.Command{

// routesToPtables converts the list of routes to a nice table.
func routesToPtables(routes []*v1.Route) pterm.TableData {
tableData := pterm.TableData{{"ID", "Node", "Prefix", "Advertised", "Enabled", "Primary"}}
tableData := pterm.TableData{
{"ID", "Node", "Prefix", "Advertised", "Enabled", "Primary"},

Check failure on line 283 in cmd/headscale/cli/routes.go

View workflow job for this annotation

GitHub Actions / golangci-lint

missing type in composite literal (typecheck)
}

for _, route := range routes {
var isPrimaryStr string
Expand Down
6 changes: 5 additions & 1 deletion cmd/headscale/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ func getHeadscaleCLIClient() (context.Context, v1.HeadscaleServiceClient, *grpc.

// Try to give the user better feedback if we cannot write to the headscale
// socket.
socket, err := os.OpenFile(cfg.UnixSocket, os.O_WRONLY, SocketWritePermissions) //nolint
socket, err := os.OpenFile(
cfg.UnixSocket,
os.O_WRONLY,
SocketWritePermissions,
) //nolint
if err != nil {
if os.IsPermission(err) {
log.Fatal().
Expand Down
22 changes: 17 additions & 5 deletions hscontrol/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ func NewHeadscale(cfg *types.Config) (*Headscale, error) {

noisePrivateKey, err := readOrCreatePrivateKey(cfg.NoisePrivateKeyPath)
if err != nil {
return nil, fmt.Errorf("failed to read or create Noise protocol private key: %w", err)
return nil, fmt.Errorf(
"failed to read or create Noise protocol private key: %w",
err,
)
}

var dbString string
Expand Down Expand Up @@ -200,7 +203,10 @@ func NewHeadscale(cfg *types.Config) (*Headscale, error) {
if cfg.DERP.ServerEnabled {
derpServerKey, err := readOrCreatePrivateKey(cfg.DERP.ServerPrivateKeyPath)
if err != nil {
return nil, fmt.Errorf("failed to read or create DERP server private key: %w", err)
return nil, fmt.Errorf(
"failed to read or create DERP server private key: %w",
err,
)
}

if derpServerKey.Equal(*noisePrivateKey) {
Expand Down Expand Up @@ -268,7 +274,8 @@ func (h *Headscale) scheduledDERPMapUpdateWorker(cancelChan <-chan struct{}) {
case <-ticker.C:
log.Info().Msg("Fetching DERPMap updates")
h.DERPMap = derp.GetDERPMap(h.cfg.DERP)
if h.cfg.DERP.ServerEnabled && h.cfg.DERP.AutomaticallyAddEmbeddedDerpRegion {
if h.cfg.DERP.ServerEnabled &&
h.cfg.DERP.AutomaticallyAddEmbeddedDerpRegion {
region, _ := h.DERPServer.GenerateRegion()
h.DERPMap.Regions[region.RegionID] = &region
}
Expand Down Expand Up @@ -471,7 +478,10 @@ func (h *Headscale) createRouter(grpcMux *grpcRuntime.ServeMux) *mux.Router {
if h.cfg.DERP.ServerEnabled {
router.HandleFunc("/derp", h.DERPServer.DERPHandler)
router.HandleFunc("/derp/probe", derpServer.DERPProbeHandler)
router.HandleFunc("/bootstrap-dns", derpServer.DERPBootstrapDNSHandler(h.DERPMap))
router.HandleFunc(
"/bootstrap-dns",
derpServer.DERPBootstrapDNSHandler(h.DERPMap),
)
}

apiRouter := router.PathPrefix("/api").Subrouter()
Expand Down Expand Up @@ -711,7 +721,9 @@ func (h *Headscale) Serve() error {
var tailsqlContext context.Context
if tailsqlEnabled {
if h.cfg.DBtype != db.Sqlite {
log.Fatal().Str("type", h.cfg.DBtype).Msgf("tailsql only support %q", db.Sqlite)
log.Fatal().
Str("type", h.cfg.DBtype).
Msgf("tailsql only support %q", db.Sqlite)
}
if tailsqlTSKey == "" {
log.Fatal().Msg("tailsql requires TS_AUTHKEY to be set")
Expand Down
12 changes: 10 additions & 2 deletions hscontrol/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ func (h *Headscale) handleRegister(
logInfo, logTrace, logErr := logAuthFunc(registerRequest, machineKey)
now := time.Now().UTC()
logTrace("handleRegister called, looking up machine in DB")
node, err := h.db.GetNodeByAnyKey(machineKey, registerRequest.NodeKey, registerRequest.OldNodeKey)
node, err := h.db.GetNodeByAnyKey(
machineKey,
registerRequest.NodeKey,
registerRequest.OldNodeKey,
)
logTrace("handleRegister database lookup has returned")
if errors.Is(err, gorm.ErrRecordNotFound) {
// If the node has AuthKey set, handle registration via PreAuthKeys
Expand Down Expand Up @@ -302,7 +306,11 @@ func (h *Headscale) handleAuthKey(
// The error is not important, because if it does not
// exist, then this is a new node and we will move
// on to registration.
node, _ := h.db.GetNodeByAnyKey(machineKey, registerRequest.NodeKey, registerRequest.OldNodeKey)
node, _ := h.db.GetNodeByAnyKey(
machineKey,
registerRequest.NodeKey,
registerRequest.OldNodeKey,
)
if node != nil {
log.Trace().
Caller().
Expand Down
4 changes: 3 additions & 1 deletion hscontrol/auth_noise.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ func (ns *noiseServer) NoiseRegistrationHandler(
writer http.ResponseWriter,
req *http.Request,
) {
log.Trace().Caller().Msgf("Noise registration handler for client %s", req.RemoteAddr)
log.Trace().
Caller().
Msgf("Noise registration handler for client %s", req.RemoteAddr)
if req.Method != http.MethodPost {
http.Error(writer, "Wrong method", http.StatusMethodNotAllowed)

Expand Down
4 changes: 3 additions & 1 deletion hscontrol/db/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func (hsdb *HSDatabase) getAvailableIP(ipPrefix netip.Prefix) (*netip.Addr, erro
return nil, err
}

ipPrefixNetworkAddress, ipPrefixBroadcastAddress := util.GetIPPrefixEndpoints(ipPrefix)
ipPrefixNetworkAddress, ipPrefixBroadcastAddress := util.GetIPPrefixEndpoints(
ipPrefix,
)

// Get the first IP in our prefix
ip := ipPrefixNetworkAddress.Next()
Expand Down
Loading

0 comments on commit 9a582c7

Please sign in to comment.