Skip to content

Commit

Permalink
grpc lint fix
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Nov 20, 2023
1 parent f039e4a commit e25247b
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 161 deletions.
8 changes: 4 additions & 4 deletions cmd/headscale/cli/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ var listAPIKeys = &cobra.Command{
}

if output != "" {
SuccessOutput(response.ApiKeys, "", output)
SuccessOutput(response.GetApiKeys(), "", output)

return
}

tableData := pterm.TableData{
{"ID", "Prefix", "Expiration", "Created"},
}
for _, key := range response.ApiKeys {
for _, key := range response.GetApiKeys() {
expiration := "-"

if key.GetExpiration() != nil {
expiration = ColourTime(key.Expiration.AsTime())
expiration = ColourTime(key.GetExpiration().AsTime())
}

tableData = append(tableData, []string{
Expand Down Expand Up @@ -155,7 +155,7 @@ If you loose a key, create a new one and revoke (expire) the old one.`,
return
}

SuccessOutput(response.ApiKey, response.ApiKey, output)
SuccessOutput(response.GetApiKey(), response.GetApiKey(), output)
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/headscale/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ var createNodeCmd = &cobra.Command{
return
}

SuccessOutput(response.Node, "Node created", output)
SuccessOutput(response.GetNode(), "Node created", output)
},
}
54 changes: 27 additions & 27 deletions cmd/headscale/cli/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ var registerNodeCmd = &cobra.Command{
}

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

Expand Down Expand Up @@ -196,12 +196,12 @@ var listNodesCmd = &cobra.Command{
}

if output != "" {
SuccessOutput(response.Nodes, "", output)
SuccessOutput(response.GetNodes(), "", output)

return
}

tableData, err := nodesToPtables(user, showTags, response.Nodes)
tableData, err := nodesToPtables(user, showTags, response.GetNodes())
if err != nil {
ErrorOutput(err, fmt.Sprintf("Error converting to table: %s", err), output)

Expand Down Expand Up @@ -262,7 +262,7 @@ var expireNodeCmd = &cobra.Command{
return
}

SuccessOutput(response.Node, "Node expired", output)
SuccessOutput(response.GetNode(), "Node expired", output)
},
}

Expand Down Expand Up @@ -310,7 +310,7 @@ var renameNodeCmd = &cobra.Command{
return
}

SuccessOutput(response.Node, "Node renamed", output)
SuccessOutput(response.GetNode(), "Node renamed", output)
},
}

Expand Down Expand Up @@ -364,7 +364,7 @@ var deleteNodeCmd = &cobra.Command{
prompt := &survey.Confirm{
Message: fmt.Sprintf(
"Do you want to remove the node %s?",
getResponse.GetNode().Name,
getResponse.GetNode().GetName(),
),
}
err = survey.AskOne(prompt, &confirm)
Expand Down Expand Up @@ -473,7 +473,7 @@ var moveNodeCmd = &cobra.Command{
return
}

SuccessOutput(moveResponse.Node, "Node moved to another user", output)
SuccessOutput(moveResponse.GetNode(), "Node moved to another user", output)
},
}

Expand Down Expand Up @@ -507,44 +507,44 @@ func nodesToPtables(

for _, node := range nodes {
var ephemeral bool
if node.PreAuthKey != nil && node.PreAuthKey.Ephemeral {
if node.GetPreAuthKey() != nil && node.GetPreAuthKey().GetEphemeral() {
ephemeral = true
}

var lastSeen time.Time
var lastSeenTime string
if node.LastSeen != nil {
lastSeen = node.LastSeen.AsTime()
if node.GetLastSeen() != nil {
lastSeen = node.GetLastSeen().AsTime()
lastSeenTime = lastSeen.Format("2006-01-02 15:04:05")
}

var expiry time.Time
var expiryTime string
if node.Expiry != nil {
expiry = node.Expiry.AsTime()
if node.GetExpiry() != nil {
expiry = node.GetExpiry().AsTime()
expiryTime = expiry.Format("2006-01-02 15:04:05")
} else {
expiryTime = "N/A"
}

var machineKey key.MachinePublic
err := machineKey.UnmarshalText(
[]byte(node.MachineKey),
[]byte(node.GetMachineKey()),
)
if err != nil {
machineKey = key.MachinePublic{}
}

var nodeKey key.NodePublic
err = nodeKey.UnmarshalText(
[]byte(node.NodeKey),
[]byte(node.GetNodeKey()),
)
if err != nil {
return nil, err
}

var online string
if node.Online {
if node.GetOnline() {
online = pterm.LightGreen("online")
} else {
online = pterm.LightRed("offline")
Expand All @@ -558,36 +558,36 @@ func nodesToPtables(
}

var forcedTags string
for _, tag := range node.ForcedTags {
for _, tag := range node.GetForcedTags() {
forcedTags += "," + tag
}
forcedTags = strings.TrimLeft(forcedTags, ",")
var invalidTags string
for _, tag := range node.InvalidTags {
if !contains(node.ForcedTags, tag) {
for _, tag := range node.GetInvalidTags() {
if !contains(node.GetForcedTags(), tag) {
invalidTags += "," + pterm.LightRed(tag)
}
}
invalidTags = strings.TrimLeft(invalidTags, ",")
var validTags string
for _, tag := range node.ValidTags {
if !contains(node.ForcedTags, tag) {
for _, tag := range node.GetValidTags() {
if !contains(node.GetForcedTags(), tag) {
validTags += "," + pterm.LightGreen(tag)
}
}
validTags = strings.TrimLeft(validTags, ",")

var user string
if currentUser == "" || (currentUser == node.User.Name) {
user = pterm.LightMagenta(node.User.Name)
if currentUser == "" || (currentUser == node.GetUser().GetName()) {
user = pterm.LightMagenta(node.GetUser().GetName())
} else {
// Shared into this user
user = pterm.LightYellow(node.User.Name)
user = pterm.LightYellow(node.GetUser().GetName())
}

var IPV4Address string
var IPV6Address string
for _, addr := range node.IpAddresses {
for _, addr := range node.GetIpAddresses() {
if netip.MustParseAddr(addr).Is4() {
IPV4Address = addr
} else {
Expand All @@ -596,8 +596,8 @@ func nodesToPtables(
}

nodeData := []string{
strconv.FormatUint(node.Id, util.Base10),
node.Name,
strconv.FormatUint(node.GetId(), util.Base10),
node.GetName(),
node.GetGivenName(),
machineKey.ShortString(),
nodeKey.ShortString(),
Expand Down
10 changes: 5 additions & 5 deletions cmd/headscale/cli/preauthkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var listPreAuthKeys = &cobra.Command{
}

if output != "" {
SuccessOutput(response.PreAuthKeys, "", output)
SuccessOutput(response.GetPreAuthKeys(), "", output)

return
}
Expand All @@ -101,10 +101,10 @@ var listPreAuthKeys = &cobra.Command{
"Tags",
},
}
for _, key := range response.PreAuthKeys {
for _, key := range response.GetPreAuthKeys() {
expiration := "-"
if key.GetExpiration() != nil {
expiration = ColourTime(key.Expiration.AsTime())
expiration = ColourTime(key.GetExpiration().AsTime())
}

var reusable string
Expand All @@ -116,7 +116,7 @@ var listPreAuthKeys = &cobra.Command{

aclTags := ""

for _, tag := range key.AclTags {
for _, tag := range key.GetAclTags() {
aclTags += "," + tag
}

Expand Down Expand Up @@ -214,7 +214,7 @@ var createPreAuthKeyCmd = &cobra.Command{
return
}

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

Expand Down
24 changes: 12 additions & 12 deletions cmd/headscale/cli/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ var listRoutesCmd = &cobra.Command{
}

if output != "" {
SuccessOutput(response.Routes, "", output)
SuccessOutput(response.GetRoutes(), "", output)

return
}

routes = response.Routes
routes = response.GetRoutes()
} else {
response, err := client.GetNodeRoutes(ctx, &v1.GetNodeRoutesRequest{
NodeId: machineID,
Expand All @@ -108,12 +108,12 @@ var listRoutesCmd = &cobra.Command{
}

if output != "" {
SuccessOutput(response.Routes, "", output)
SuccessOutput(response.GetRoutes(), "", output)

return
}

routes = response.Routes
routes = response.GetRoutes()
}

tableData := routesToPtables(routes)
Expand Down Expand Up @@ -271,25 +271,25 @@ func routesToPtables(routes []*v1.Route) pterm.TableData {

for _, route := range routes {
var isPrimaryStr string
prefix, err := netip.ParsePrefix(route.Prefix)
prefix, err := netip.ParsePrefix(route.GetPrefix())
if err != nil {
log.Printf("Error parsing prefix %s: %s", route.Prefix, err)
log.Printf("Error parsing prefix %s: %s", route.GetPrefix(), err)

continue
}
if prefix == types.ExitRouteV4 || prefix == types.ExitRouteV6 {
isPrimaryStr = "-"
} else {
isPrimaryStr = strconv.FormatBool(route.IsPrimary)
isPrimaryStr = strconv.FormatBool(route.GetIsPrimary())
}

tableData = append(tableData,
[]string{
strconv.FormatUint(route.Id, Base10),
route.Node.GivenName,
route.Prefix,
strconv.FormatBool(route.Advertised),
strconv.FormatBool(route.Enabled),
strconv.FormatUint(route.GetId(), Base10),
route.GetNode().GetGivenName(),
route.GetPrefix(),
strconv.FormatBool(route.GetAdvertised()),
strconv.FormatBool(route.GetEnabled()),
isPrimaryStr,
})
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/headscale/cli/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var createUserCmd = &cobra.Command{
return
}

SuccessOutput(response.User, "User created", output)
SuccessOutput(response.GetUser(), "User created", output)
},
}

Expand Down Expand Up @@ -169,7 +169,7 @@ var listUsersCmd = &cobra.Command{
}

if output != "" {
SuccessOutput(response.Users, "", output)
SuccessOutput(response.GetUsers(), "", output)

return
}
Expand Down Expand Up @@ -236,6 +236,6 @@ var renameUserCmd = &cobra.Command{
return
}

SuccessOutput(response.User, "User renamed", output)
SuccessOutput(response.GetUser(), "User renamed", output)
},
}
4 changes: 2 additions & 2 deletions hscontrol/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (h *Headscale) handleAuthKey(
return
}

aclTags := pak.Proto().AclTags
aclTags := pak.Proto().GetAclTags()
if len(aclTags) > 0 {
// This conditional preserves the existing behaviour, although SaaS would reset the tags on auth-key login
err = h.db.SetTags(node, aclTags)
Expand Down Expand Up @@ -342,7 +342,7 @@ func (h *Headscale) handleAuthKey(
NodeKey: nodeKey,
LastSeen: &now,
AuthKeyID: uint(pak.ID),
ForcedTags: pak.Proto().AclTags,
ForcedTags: pak.Proto().GetAclTags(),
}

node, err = h.db.RegisterNode(
Expand Down
2 changes: 1 addition & 1 deletion hscontrol/db/preauth_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,5 @@ func (*Suite) TestPreAuthKeyACLTags(c *check.C) {

listedPaks, err := db.ListPreAuthKeys("test8")
c.Assert(err, check.IsNil)
c.Assert(listedPaks[0].Proto().AclTags, check.DeepEquals, tags)
c.Assert(listedPaks[0].Proto().GetAclTags(), check.DeepEquals, tags)
}
Loading

0 comments on commit e25247b

Please sign in to comment.