@@ -15,8 +15,8 @@ import (
1515)
1616
1717const (
18- clientID = "e6d00a6c53b4f4b63ae0156c8e09c4957caeb382d5b63f8b301f710f9aadcbe6" // Only client ID is needed
19- authFile = "credentials"
18+ clientID = "e6d00a6c53b4f4b63ae0156c8e09c4957caeb382d5b63f8b301f710f9aadcbe6" // Only client ID is needed
19+ authFileName = "credentials"
2020
2121 appName = "flit-vpn" // Constant application name
2222)
@@ -68,6 +68,8 @@ func main() {
6868 Run : destroyApp ,
6969 }
7070
71+ // TODO: Add status command to check if node is running
72+
7173 rootCmd .AddCommand (loginCmd , upCmd , downCmd )
7274
7375 if err := rootCmd .Execute (); err != nil {
@@ -116,6 +118,7 @@ func getTailscaleKey() string {
116118}
117119
118120// Deploys or updates the application
121+ // TODO: Create a specific project for the app and encapsulate deployment within
119122func deployApp (cmd * cobra.Command , args []string ) {
120123 client := getClient ()
121124 ctx := context .TODO ()
@@ -174,7 +177,7 @@ func deployApp(cmd *cobra.Command, args []string) {
174177 if err != nil {
175178 log .Fatalf ("Failed to update the node: %v" , err )
176179 }
177- fmt .Println ("App updated and redeployed successfully." )
180+ fmt .Println ("Node updated and redeployed successfully." )
178181 } else {
179182 fmt .Println ("Creating new Tailscale node..." )
180183 _ , _ , err := client .Apps .Create (ctx , & godo.AppCreateRequest {Spec : appSpec })
@@ -229,13 +232,14 @@ func saveToken(creds credentials) {
229232
230233 configDir := createConfigDirectory ()
231234
232- if err := os .WriteFile (filepath .Join (configDir , authFile ), []byte (data ), 0600 ); err != nil {
235+ if err := os .WriteFile (filepath .Join (configDir , authFileName ), []byte (data ), 0600 ); err != nil {
233236 log .Fatalf ("Failed to write token to file: %v" , err )
234237 }
235238}
236239
237240func loadToken () error {
238- data , err := os .ReadFile (authFile )
241+ configDir := buildConfigDirPath ()
242+ data , err := os .ReadFile (filepath .Join (configDir , authFileName ))
239243 if err != nil {
240244 return err
241245 }
@@ -250,14 +254,19 @@ func loadToken() error {
250254 // TODO: Check if tokens are specified in environment and use those instead
251255}
252256
253- // Create config directory if it doesn't already exist
254- func createConfigDirectory () string {
257+ // Build config directory based on user's home directory
258+ func buildConfigDirPath () string {
255259 homeDir , err := os .UserHomeDir ()
256260 if err != nil {
257261 log .Fatal (err )
258262 }
259263
260- configDir := filepath .Join (homeDir , ".flit-vpn" )
264+ return filepath .Join (homeDir , ".flit-vpn" )
265+ }
266+
267+ // Create config directory if it doesn't already exist
268+ func createConfigDirectory () string {
269+ configDir := buildConfigDirPath ()
261270
262271 if err := os .MkdirAll (configDir , 0755 ); err != nil {
263272 log .Fatalf ("Failed to create config directory: %v" , err )
0 commit comments