]> source.dussan.org Git - gitea.git/commitdiff
TrimSpace when reading InternalToken from a file (#11502) (#11524)
authorzeripath <art27@cantab.net>
Wed, 20 May 2020 19:42:03 +0000 (20:42 +0100)
committerGitHub <noreply@github.com>
Wed, 20 May 2020 19:42:03 +0000 (15:42 -0400)
InternalTokens are fixed as alphanum strings therefore TrimSpace from these.
Also use isatty to not add a terminal newline when redirecting generate.

Fix #11498

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Lauris BH <lauris@nix.lv>
cmd/generate.go
modules/setting/setting.go

index 4e91b1d3f0c67e6d5eb6c2463ebf6321ccce4130..13a99c94f462bab90c4848002177984cb230ffc0 100644 (file)
@@ -7,9 +7,11 @@ package cmd
 
 import (
        "fmt"
+       "os"
 
        "code.gitea.io/gitea/modules/generate"
 
+       "github.com/mattn/go-isatty"
        "github.com/urfave/cli"
 )
 
@@ -59,7 +61,12 @@ func runGenerateInternalToken(c *cli.Context) error {
                return err
        }
 
-       fmt.Printf("%s\n", internalToken)
+       fmt.Printf("%s", internalToken)
+
+       if isatty.IsTerminal(os.Stdout.Fd()) {
+               fmt.Printf("\n")
+       }
+
        return nil
 }
 
@@ -69,7 +76,12 @@ func runGenerateLfsJwtSecret(c *cli.Context) error {
                return err
        }
 
-       fmt.Printf("%s\n", JWTSecretBase64)
+       fmt.Printf("%s", JWTSecretBase64)
+
+       if isatty.IsTerminal(os.Stdout.Fd()) {
+               fmt.Printf("\n")
+       }
+
        return nil
 }
 
@@ -79,6 +91,11 @@ func runGenerateSecretKey(c *cli.Context) error {
                return err
        }
 
-       fmt.Printf("%s\n", secretKey)
+       fmt.Printf("%s", secretKey)
+
+       if isatty.IsTerminal(os.Stdout.Fd()) {
+               fmt.Printf("\n")
+       }
+
        return nil
 }
index ede4687c812c3a9481da80f1c2eca6cff6a4ac9f..9507d4693084d21a1a59ae52fe933b317d76416a 100644 (file)
@@ -1069,7 +1069,7 @@ func loadInternalToken(sec *ini.Section) string {
                        return token
                }
 
-               return string(buf)
+               return strings.TrimSpace(string(buf))
        default:
                log.Fatal("Unsupported URI-Scheme %q (INTERNAL_TOKEN_URI = %q)", tempURI.Scheme, uri)
        }