Skip to content

Commit

Permalink
TrimSpace when reading InternalToken from a file (#11502) (#11524)
Browse files Browse the repository at this point in the history
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 <[email protected]>

Co-authored-by: Lauris BH <[email protected]>

Co-authored-by: Lauris BH <[email protected]>
  • Loading branch information
zeripath and lafriks committed May 20, 2020
1 parent 09cc639 commit c83bc55
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ package cmd

import (
"fmt"
"os"

"code.gitea.io/gitea/modules/generate"

"github.com/mattn/go-isatty"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
2 changes: 1 addition & 1 deletion modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit c83bc55

Please sign in to comment.