<commit_before>package weave

import (
	"os"

	"github.com/dchest/uniuri"
	"github.com/juju/errgo"

	"arvika.pulcy.com/iggi/yard/templates"
	"arvika.pulcy.com/iggi/yard/topics"
)

var (
	maskAny = errgo.MaskFunc(errgo.Any)
)

const (
	installServiceName     = "install-weave.service"
	installServiceTemplate = "templates/install-weave.service.tmpl"
	installServicePath     = "/etc/systemd/system/" + installServiceName

	networkServiceName     = "10-weave.network"
	networkServiceTemplate = "templates/10-weave.network.tmpl"
	networkServicePath     = "/etc/systemd/network/10-weave.network"

	serviceName     = "weave.service"
	serviceTemplate = "templates/weave.service.tmpl"
	servicePath     = "/etc/systemd/system/" + serviceName

	weaveIPs = `$(IPS=""; while [ "$IPS" == "" ]; do IPS=$(/usr/bin/etcdctl member list | grep -v ${COREOS_PRIVATE_IPV4} | sed "s/\(.*\)clientURLs=http\:\/\/\([0-9\\.]*\).*/\2/g"); done; echo $IPS)`

	fileMode = os.FileMode(0664)
)

type weaveOptions struct {
	WeavePassword string
	WeaveIPS      string
}

type WeaveTopic struct {
}

func NewTopic() *WeaveTopic {
	return &WeaveTopic{}
}

func (t *WeaveTopic) Name() string {
	return "weave"
}

func (t *WeaveTopic) Defaults(flags *topics.TopicFlags) error {
	if flags.WeavePassword == "" {
		flags.WeavePassword = uniuri.NewLen(uniuri.UUIDLen)
	}
	return nil
}

func (t *WeaveTopic) Setup(deps *topics.TopicDependencies, flags *topics.TopicFlags) error {
	if err := createWeaveNetworkService(deps); err != nil {
		return maskAny(err)
	}
	if err := createWeaveInstallService(deps); err != nil {
		return maskAny(err)
	}
	if err := createWeaveService(deps, flags); err != nil {
		return maskAny(err)
	}

	// reload unit files, that is, `systemctl daemon-reload`
	if err := deps.Systemd.Reload(); err != nil {
		return maskAny(err)
	}

	// start install-weave.service unit
	deps.Logger.Info("starting %s", installServiceName)
	if err := deps.Systemd.Start(installServiceName); err != nil {
		return maskAny(err)
	}

	// start install-weave.service unit
	deps.Logger.Info("starting %s", serviceName)
	if err := deps.Systemd.Start(serviceName); err != nil {
		return maskAny(err)
	}

	return nil
}

func createWeaveNetworkService(deps *topics.TopicDependencies) error {
	deps.Logger.Info("creating %s", networkServicePath)
	if err := templates.Render(networkServiceTemplate, networkServicePath, nil, fileMode); err != nil {
		return maskAny(err)
	}

	return nil
}

func createWeaveInstallService(deps *topics.TopicDependencies) error {
	deps.Logger.Info("creating %s", installServicePath)
	if err := templates.Render(installServiceTemplate, installServicePath, nil, fileMode); err != nil {
		return maskAny(err)
	}

	return nil
}

func createWeaveService(deps *topics.TopicDependencies, flags *topics.TopicFlags) error {
	deps.Logger.Info("creating %s", servicePath)
	opts := weaveOptions{
		WeavePassword: flags.WeavePassword,
		WeaveIPS:      weaveIPs,
	}
	if err := templates.Render(serviceTemplate, servicePath, opts, 0600); err != nil {
		return maskAny(err)
	}

	return nil
}
<commit_msg>Weave password is now required<commit_after>package weave

import (
	"os"

	"github.com/juju/errgo"

	"arvika.pulcy.com/iggi/yard/templates"
	"arvika.pulcy.com/iggi/yard/topics"
)

var (
	maskAny = errgo.MaskFunc(errgo.Any)
)

const (
	installServiceName     = "install-weave.service"
	installServiceTemplate = "templates/install-weave.service.tmpl"
	installServicePath     = "/etc/systemd/system/" + installServiceName

	networkServiceName     = "10-weave.network"
	networkServiceTemplate = "templates/10-weave.network.tmpl"
	networkServicePath     = "/etc/systemd/network/10-weave.network"

	serviceName     = "weave.service"
	serviceTemplate = "templates/weave.service.tmpl"
	servicePath     = "/etc/systemd/system/" + serviceName

	weaveIPs = `$(IPS=""; while [ "$IPS" == "" ]; do IPS=$(/usr/bin/etcdctl member list | grep -v ${COREOS_PRIVATE_IPV4} | sed "s/\(.*\)clientURLs=http\:\/\/\([0-9\\.]*\).*/\2/g"); done; echo $IPS)`

	fileMode = os.FileMode(0664)
)

type weaveOptions struct {
	WeavePassword string
	WeaveIPS      string
}

type WeaveTopic struct {
}

func NewTopic() *WeaveTopic {
	return &WeaveTopic{}
}

func (t *WeaveTopic) Name() string {
	return "weave"
}

func (t *WeaveTopic) Defaults(flags *topics.TopicFlags) error {
	if flags.WeavePassword == "" {
		return errgo.New("WeavePassword is not set")
	}
	return nil
}

func (t *WeaveTopic) Setup(deps *topics.TopicDependencies, flags *topics.TopicFlags) error {
	if err := createWeaveNetworkService(deps); err != nil {
		return maskAny(err)
	}
	if err := createWeaveInstallService(deps); err != nil {
		return maskAny(err)
	}
	if err := createWeaveService(deps, flags); err != nil {
		return maskAny(err)
	}

	// reload unit files, that is, `systemctl daemon-reload`
	if err := deps.Systemd.Reload(); err != nil {
		return maskAny(err)
	}

	// start install-weave.service unit
	deps.Logger.Info("starting %s", installServiceName)
	if err := deps.Systemd.Start(installServiceName); err != nil {
		return maskAny(err)
	}

	// start install-weave.service unit
	deps.Logger.Info("starting %s", serviceName)
	if err := deps.Systemd.Start(serviceName); err != nil {
		return maskAny(err)
	}

	return nil
}

func createWeaveNetworkService(deps *topics.TopicDependencies) error {
	deps.Logger.Info("creating %s", networkServicePath)
	if err := templates.Render(networkServiceTemplate, networkServicePath, nil, fileMode); err != nil {
		return maskAny(err)
	}

	return nil
}

func createWeaveInstallService(deps *topics.TopicDependencies) error {
	deps.Logger.Info("creating %s", installServicePath)
	if err := templates.Render(installServiceTemplate, installServicePath, nil, fileMode); err != nil {
		return maskAny(err)
	}

	return nil
}

func createWeaveService(deps *topics.TopicDependencies, flags *topics.TopicFlags) error {
	deps.Logger.Info("creating %s", servicePath)
	opts := weaveOptions{
		WeavePassword: flags.WeavePassword,
		WeaveIPS:      weaveIPs,
	}
	if err := templates.Render(serviceTemplate, servicePath, opts, 0600); err != nil {
		return maskAny(err)
	}

	return nil
}

{'fraction_non_alphanumeric': 0.13907933398628794, 'fraction_numerical': 0.005876591576885406, 'mean_word_length': 4.431737588652482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7020114', 'n_tokens_mistral': 2242, 'n_tokens_neox': 2155, 'n_words': 448}