8000 Add ExtendNodeExpiration functionality to gRPC and CLI by FlorinPeter · Pull Request #2460 · juanfont/headscale · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add ExtendNodeExpiration functionality to gRPC and CLI #2460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions cmd/headscale/cli/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
"tailscale.com/types/key"
)

Expand Down Expand Up @@ -57,6 +58,18 @@ func init() {
}
nodeCmd.AddCommand(expireNodeCmd)

extendNodeExpirationCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)")
err = extendNodeExpirationCmd.MarkFlagRequired("identifier")
if err != nil {
log.Fatal(err.Error())
}
extendNodeExpirationCmd.Flags().StringP("new-expiry", "e", "", "New expiration time in RFC3339 format, e.g., 2024-01-01T15:04:05Z")
err = extendNodeExpirationCmd.MarkFlagRequired("new-expiry")
if err != nil {
log.Fatal(err.Error())
}
nodeCmd.AddCommand(extendNodeExpirationCmd)

renameNodeCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)")
err = renameNodeCmd.MarkFlagRequired("identifier")
if err != nil {
Expand Down Expand Up @@ -315,6 +328,54 @@ var expireNodeCmd = &cobra.Command{
},
}

var extendNodeExpirationCmd = &cobra.Command{
Use: "extend-expiration",
Short: "Extends the expiration of a node by setting a new expiration time",
Run: func(cmd *cobra.Command, args []string) {
output, _ := cmd.Flags().GetString("output")
nodeID, err := cmd.Flags().GetUint64("identifier")
if err != nil {
ErrorOutput(err, fmt.Sprintf("Error getting identifier from flag: %s", err), output)
}

newExpiryStr, err := cmd.Flags().GetString("new-expiry")
if err != nil {
ErrorOutput(err, fmt.Sprintf("Error getting new-expiry from flag: %s", err), output)
}

// Parse the new-expiry timestamp from string to time.Time
newExpiry, err := time.Parse(time.RFC3339, newExpiryStr)
if err != nil {
ErrorOutput(err, fmt.Sprintf("Invalid expiration time format: must be in RFC3339 format, %s", err), output)
}

// Set up context and gRPC client
ctx, client, conn, cancel := newHeadscaleCLIWithConfig()
defer cancel()
defer conn.Close()

// Build the gRPC request
request := &v1.ExtendNodeExpirationRequest{
NodeId: nodeID,
NewExpiration: timestamppb.New(newExpiry), // convert time.Time to protobuf timestamp
}

// Make the gRPC call
response, err := client.ExtendNodeExpiration(ctx, request)
if err != nil {
st, ok := status.FromError(err)
if ok {
ErrorOutput(st.Err(), st.Message(), output)
} else {
ErrorOutput(err, "Unexpected error during ExtendNodeExpiration RPC call", output)
}
}

// Print the result
SuccessOutput(response, "Node expiration extended successfully", output)
},
}

var renameNodeCmd = &cobra.Command{
Use: "rename NEW_NAME",
Short: "Renames a node in your network",
Expand Down
Loading
0