mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-04 00:44:27 +00:00
e54ac48f9d
* deep source issues * fix broken build * fix beacon chain build * gaz Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
77 lines
2.4 KiB
Go
77 lines
2.4 KiB
Go
package tos
|
|
|
|
import (
|
|
"errors"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/logrusorgru/aurora"
|
|
"github.com/prysmaticlabs/prysm/shared/cmd"
|
|
"github.com/prysmaticlabs/prysm/shared/fileutil"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/promptutil"
|
|
"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]:`
|
|
acceptTosPromptErrText = `Could not scan text input, if you are trying to run in non-interactive environment, you
|
|
should use --accept-terms-of-use flag (only once) after reading the terms and conditions here:
|
|
https://github.com/prysmaticlabs/prysm/blob/master/TERMS_OF_SERVICE.md`
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
if fileutil.FileExists(filepath.Join(ctx.String(cmd.DataDirFlag.Name), acceptTosFilename)) {
|
|
return nil
|
|
}
|
|
if ctx.Bool(cmd.AcceptTosFlag.Name) {
|
|
saveTosAccepted(ctx)
|
|
return nil
|
|
}
|
|
|
|
input, err := promptutil.DefaultPrompt(au.Bold(acceptTosPromptText).String(), "decline")
|
|
if err != nil {
|
|
return errors.New(acceptTosPromptErrText)
|
|
}
|
|
if strings.ToLower(input) != "accept" {
|
|
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) {
|
|
if err := os.MkdirAll(ctx.String(cmd.DataDirFlag.Name), params.BeaconIoConfig().ReadWriteExecutePermissions); err != nil {
|
|
log.WithError(err).Warnf("error creating directory: %s", ctx.String(cmd.DataDirFlag.Name))
|
|
}
|
|
err := ioutil.WriteFile(filepath.Join(ctx.String(cmd.DataDirFlag.Name), acceptTosFilename), []byte(""), 0644)
|
|
if err != nil {
|
|
log.WithError(err).Warnf("error writing %s to file: %s", cmd.AcceptTosFlag.Name, filepath.Join(ctx.String(cmd.DataDirFlag.Name), acceptTosFilename))
|
|
}
|
|
}
|