2020-10-15 02:05:30 +00:00
|
|
|
package tos
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2020-10-15 03:58:57 +00:00
|
|
|
"path/filepath"
|
2020-10-15 02:05:30 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/logrusorgru/aurora"
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/cmd"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/io/file"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/io/prompt"
|
2020-10-15 02:05:30 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
acceptTosFilename = "tosaccepted"
|
|
|
|
acceptTosPromptText = `
|
|
|
|
Prysmatic Labs Terms of Use
|
|
|
|
|
|
|
|
By downloading, accessing or using the Prysm implementation (“Prysm”), you (referenced herein
|
|
|
|
as “you” or the “user”) certify that you have read and agreed to the terms and conditions below.
|
|
|
|
|
|
|
|
TERMS AND CONDITIONS: https://github.com/prysmaticlabs/prysm/blob/master/TERMS_OF_SERVICE.md
|
|
|
|
|
|
|
|
|
|
|
|
Type "accept" to accept this terms and conditions [accept/decline]:`
|
2020-12-01 01:55:30 +00:00
|
|
|
acceptTosPromptErrText = `could not scan text input, if you are trying to run in non-interactive environment, you
|
2020-11-13 17:25:05 +00:00
|
|
|
can use the --accept-terms-of-use flag after reading the terms and conditions here:
|
2020-10-22 23:31:52 +00:00
|
|
|
https://github.com/prysmaticlabs/prysm/blob/master/TERMS_OF_SERVICE.md`
|
2020-10-15 02:05:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
au = aurora.NewAurora(true)
|
|
|
|
log = logrus.WithField("prefix", "tos")
|
|
|
|
)
|
|
|
|
|
|
|
|
// VerifyTosAcceptedOrPrompt check if Tos was accepted before or asks to accept.
|
|
|
|
func VerifyTosAcceptedOrPrompt(ctx *cli.Context) error {
|
|
|
|
if ctx.Bool(cmd.E2EConfigFlag.Name) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-17 21:55:24 +00:00
|
|
|
if file.FileExists(filepath.Join(ctx.String(cmd.DataDirFlag.Name), acceptTosFilename)) {
|
2020-10-15 02:05:30 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if ctx.Bool(cmd.AcceptTosFlag.Name) {
|
|
|
|
saveTosAccepted(ctx)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-17 21:55:24 +00:00
|
|
|
input, err := prompt.DefaultPrompt(au.Bold(acceptTosPromptText).String(), "decline")
|
2020-10-15 02:05:30 +00:00
|
|
|
if err != nil {
|
2020-10-18 17:08:57 +00:00
|
|
|
return errors.New(acceptTosPromptErrText)
|
2020-10-15 02:05:30 +00:00
|
|
|
}
|
2021-01-04 16:46:22 +00:00
|
|
|
if !strings.EqualFold(input, "accept") {
|
2020-10-15 02:05:30 +00:00
|
|
|
return errors.New("you have to accept Terms and Conditions in order to continue")
|
|
|
|
}
|
|
|
|
|
|
|
|
saveTosAccepted(ctx)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// saveTosAccepted creates a file when Tos accepted.
|
|
|
|
func saveTosAccepted(ctx *cli.Context) {
|
2020-12-15 20:01:51 +00:00
|
|
|
dataDir := ctx.String(cmd.DataDirFlag.Name)
|
2021-09-17 21:55:24 +00:00
|
|
|
dataDirExists, err := file.HasDir(dataDir)
|
2020-10-15 02:05:30 +00:00
|
|
|
if err != nil {
|
2020-12-15 20:01:51 +00:00
|
|
|
log.WithError(err).Warnf("error checking directory: %s", dataDir)
|
|
|
|
}
|
|
|
|
if !dataDirExists {
|
2021-09-17 21:55:24 +00:00
|
|
|
if err := file.MkdirAll(dataDir); err != nil {
|
2020-12-15 20:01:51 +00:00
|
|
|
log.WithError(err).Warnf("error creating directory: %s", dataDir)
|
|
|
|
}
|
|
|
|
}
|
2021-09-17 21:55:24 +00:00
|
|
|
if err := file.WriteFile(filepath.Join(dataDir, acceptTosFilename), []byte("")); err != nil {
|
2020-12-15 20:01:51 +00:00
|
|
|
log.WithError(err).Warnf("error writing %s to file: %s", cmd.AcceptTosFlag.Name,
|
|
|
|
filepath.Join(dataDir, acceptTosFilename))
|
2020-10-15 02:05:30 +00:00
|
|
|
}
|
|
|
|
}
|