// Build validates the configuration options provided then builds the command
9077
func (builder *ResetBucketCommandBuilder) Build() (Command, error) {
	if builder.protobuf == nil {
		panic("builder.protobuf must not be nil")
	}
	if err := validateLocatable(builder.protobuf); err != nil {
		return nil, err
	}
	return &ResetBucketCommand{protobuf: builder.protobuf}, nil
}
1239335
func (builder *SecondaryIndexQueryCommandBuilder) Build() (Command, error) {
	if builder.protobuf == nil {
		panic("builder.protobuf must not be nil")
	}
	if err := validateLocatable(builder.protobuf); err != nil {
		return nil, err
	}
	if builder.protobuf.GetKey() == nil &&
		(builder.protobuf.GetRangeMin() == nil || builder.protobuf.GetRangeMax() == nil) {
		return nil, newClientError("either WithIndexKey or WithRange are required", nil)
	}
	if builder.protobuf.GetStream() && builder.callback == nil {
		return nil, newClientError("SecondaryIndexQueryCommand requires a callback when streaming.", nil)
	}
	return &SecondaryIndexQueryCommand{
		timeoutImpl: timeoutImpl{
			timeout: builder.timeout,
		},
		protobuf: builder.protobuf,
		callback: builder.callback,
	}, nil
}
5783
func (c *initiateCommand) build(clientShortNonce shortNoncer,
	clientLongNonce *longNonce,
	cookie serverCookie,
	permClientPrivkey permanentClientPrivkey,
	permClientPubkey permanentClientPubkey,
	permServerPubkey permanentServerPubkey,
	ephServerPubkey ephemeralServerPubkey,
	ephClientPrivkey ephemeralClientPrivkey,
	ephClientPubkey ephemeralClientPubkey) error {

	// FIXME: to support metadata, bump the size of this buffer.
	_, err := c.realloc(257)
	if err != nil {
		return err
	}

	destHeader := c.buf[:9]
	destCookie := c.buf[9 : 9+96]
	destUnprefixedNonce := c.buf[9+96 : 9+96+8]
	destEncInitiateBox := c.buf[9+96+8 : 9+96+8+144]

	prefixedNonce, unprefixedNonce, err := clientShortNonce.prefixAndBump(initiateNoncePrefix)
	if err != nil {
		return err
	}

	vouch, err := newClientVouch(clientLongNonce, ephClientPubkey, permServerPubkey, ephServerPubkey, permClientPrivkey)
	if err != nil {
		return err
	}

	var initiateBox [32 + 96]byte
	copy(initiateBox[:32], permClientPubkey[:])
	copy(initiateBox[32:], vouch[:])

	Cprime := [32]byte(ephClientPrivkey)
	Sprime := [32]byte(ephServerPubkey)

	encInitiateBox := box.Seal(nil, initiateBox[:], &prefixedNonce, &Sprime, &Cprime)

	copy(destHeader, []byte{8, 'I', 'N', 'I', 'T', 'I', 'A', 'T', 'E'})
	copy(destCookie, cookie[:])
	copy(destUnprefixedNonce, unprefixedNonce[:])
	copy(destEncInitiateBox, encInitiateBox)

	return nil
}
975314
func (b *SecretBuilder) Build(c *fi.ModelBuilderContext) error {
	if b.KeyStore == nil {
		return fmt.Errorf("KeyStore not set")
	}

	// @step: retrieve the platform ca
	if err := b.BuildCertificateTask(c, fi.CertificateId_CA, "ca.crt"); err != nil {
		return err
	}

	if b.SecretStore != nil {
		key := "dockerconfig"
		dockercfg, _ := b.SecretStore.Secret(key)
		if dockercfg != nil {
			contents := string(dockercfg.Data)
			c.AddTask(&nodetasks.File{
				Path:     filepath.Join("root", ".docker", "config.json"),
				Contents: fi.NewStringResource(contents),
				Type:     nodetasks.FileType_File,
				Mode:     s("0600"),
			})
		}
	}

	// if we are not a master we can stop here
	if !b.IsMaster {
		return nil
	}

	{
		name := "master"
		if err := b.BuildCertificateTask(c, name, "server.cert"); err != nil {
			return err
		}
		if err := b.BuildPrivateKeyTask(c, name, "server.key"); err != nil {
			return err
		}
	}

	if b.IsKubernetesGTE("1.7") {
		// TODO: Remove - we use the apiserver-aggregator keypair instead (which is signed by a different CA)
		if err := b.BuildCertificateTask(c, "apiserver-proxy-client", "proxy-client.cert"); err != nil {
			return err
		}
		if err := b.BuildPrivateKeyTask(c, "apiserver-proxy-client", "proxy-client.key"); err != nil {
			return err
		}
	}

	if b.IsKubernetesGTE("1.7") {
		if err := b.BuildCertificateTask(c, "apiserver-aggregator", "apiserver-aggregator.cert"); err != nil {
			return err
		}
		if err := b.BuildPrivateKeyTask(c, "apiserver-aggregator", "apiserver-aggregator.key"); err != nil {
			return err
		}
	}

	if b.IsKubernetesGTE("1.7") {
		if err := b.BuildCertificateTask(c, "apiserver-aggregator-ca", "apiserver-aggregator-ca.cert"); err != nil {
			return err
		}
	}

	if b.SecretStore != nil {
		key := "kube"
		token, err := b.SecretStore.FindSecret(key)
		if err != nil {
			return err
		}
		if token == nil {
			return fmt.Errorf("token not found: %q", key)
		}
		csv := string(token.Data) + "," + adminUser + "," + adminUser + "," + adminGroup

		t := &nodetasks.File{
			Path:     filepath.Join(b.PathSrvKubernetes(), "basic_auth.csv"),
			Contents: fi.NewStringResource(csv),
			Type:     nodetasks.FileType_File,
			Mode:     s("0600"),
		}
		c.AddTask(t)
	}

	if b.SecretStore != nil {
		allTokens, err := b.allAuthTokens()
		if err != nil {
			return err
		}

		var lines []string
		for id, token := range allTokens {
			if id == adminUser {
				lines = append(lines, token+","+id+","+id+","+adminGroup)
			} else {
				lines = append(lines, token+","+id+","+id)
			}
		}
		csv := strings.Join(lines, "\n")

		c.AddTask(&nodetasks.File{
			Path:     filepath.Join(b.PathSrvKubernetes(), "known_tokens.csv"),
			Contents: fi.NewStringResource(csv),
			Type:     nodetasks.FileType_File,
			Mode:     s("0600"),
		})
	}

	return nil
}
280963
func (c *messageCommand) build(sn shortNoncer, sk *precomputedKey, data []byte, sentByServer bool) error {

	total := uint64(8 + 8 + 16 + 1)
	total += uint64(len(data))

	_, err := c.realloc(total)
	if err != nil {
		return err
	}

	destHeader := c.buf[:8]
	destUnprefixedNonce := c.buf[8:16]
	destEncMessageBox := c.buf[16:total]

	var prefix [16]byte
	if sentByServer {
		prefix = serverMessageNoncePrefix
	} else {
		prefix = clientMessageNoncePrefix
	}
	prefixedNonce, unprefixedNonce, err := sn.prefixAndBump(prefix)
	if err != nil {
		return err
	}

	payload := append([]byte{0}, data...)
	encMessageBox := box.SealAfterPrecomputation(nil, payload, &prefixedNonce, (*[32]byte)(sk))

	copy(destHeader, []byte{7, 'M', 'E', 'S', 'S', 'A', 'G', 'E'})
	copy(destUnprefixedNonce, unprefixedNonce[:])
	copy(destEncMessageBox, encMessageBox)

	return nil
}
253599
func (op *UpdateMachineOperation) Build(attempt int) ([]txn.Op, error) {
	if attempt > 0 {
		if err := op.m.Refresh(); err != nil {
			return nil, err
		}
	}

	var allOps []txn.Op

	if op.AgentVersion != nil {
		ops, _, err := op.m.setAgentVersionOps(*op.AgentVersion)
		if err != nil {
			return nil, errors.Annotate(err, "cannot set agent version")
		}
		allOps = append(allOps, ops...)
	}

	if op.Constraints != nil {
		ops, err := op.m.setConstraintsOps(*op.Constraints)
		if err != nil {
			return nil, errors.Annotate(err, "cannot set constraints")
		}
		allOps = append(allOps, ops...)
	}

	if op.HasVote != nil {
		ops, err := op.m.setHasVoteOps(*op.HasVote)
		if err != nil {
			return nil, errors.Annotate(err, "cannot set has-vote")
		}
		allOps = append(allOps, ops...)
	}

	if op.MachineAddresses != nil || op.ProviderAddresses != nil {
		ops, _, _, _, _, err := op.m.setAddressesOps(op.MachineAddresses, op.ProviderAddresses)
		if err != nil {
			return nil, errors.Annotate(err, "cannot set addresses")
		}
		allOps = append(allOps, ops...)
	}

	if op.PasswordHash != nil {
		ops, err := op.m.setPasswordHashOps(*op.PasswordHash)
		if err != nil {
			return nil, errors.Annotate(err, "cannot set password")
		}
		allOps = append(allOps, ops...)
	}

	return allOps, nil
}
692665
func Build(m *serf.Member) (*version.Version, error) {
	str := versionFormat.FindString(m.Tags["build"])
	return version.NewVersion(str)
}
25225
func (g *Gen) Build(config *Config) error {
	if _, err := os.Stat(config.SearchDir); os.IsNotExist(err) {
		return fmt.Errorf("dir: %s is not exist", config.SearchDir)
	}

	log.Println("Generate swagger docs....")
	p := swag.New()
	p.PropNamingStrategy = config.PropNamingStrategy
	p.ParseVendor = config.ParseVendor

	if err := p.ParseAPI(config.SearchDir, config.MainAPIFile); err != nil {
		return err
	}
	swagger := p.GetSwagger()

	b, err := json.MarshalIndent(swagger, "", "    ")
	if err != nil {
		return err
	}

	os.MkdirAll(config.OutputDir, os.ModePerm)
	docs, err := os.Create(path.Join(config.OutputDir, "docs.go"))
	if err != nil {
		return err
	}
	defer docs.Close()

	swaggerJSON, err := os.Create(path.Join(config.OutputDir, "swagger.json"))
	if err != nil {
		return err
	}

	defer swaggerJSON.Close()
	swaggerJSON.Write(b)

	swaggerYAML, err := os.Create(path.Join(config.OutputDir, "swagger.yaml"))
	if err != nil {
		return err
	}

	defer swaggerYAML.Close()
	y, err := yaml.JSONToYAML(b)
	if err != nil {
		return errors.Wrap(err, "cannot covert json to yaml")
	}

	swaggerYAML.Write(y)

	if err := packageTemplate.Execute(docs, struct {
		Timestamp time.Time
		Doc       string
	}{
		Timestamp: time.Now(),
		Doc:       "`" + string(b) + "`",
	}); err != nil {
		return err
	}

	log.Printf("create docs.go at  %+v", docs.Name())
	log.Printf("create swagger.json at  %+v", swaggerJSON.Name())
	log.Printf("create swagger.yaml at  %+v", swaggerYAML.Name())

	return nil
}
1007425
func (builder *UpdateHllCommandBuilder) Build() (Command, error) {
	if builder.protobuf == nil {
		panic("builder.protobuf must not be nil")
	}
	if err := validateLocatable(builder.protobuf); err != nil {
		return nil, err
	}
	return &UpdateHllCommand{
		timeoutImpl: timeoutImpl{
			timeout: builder.timeout,
		},
		protobuf: builder.protobuf,
	}, nil
}
242885
func (c *welcomeCommand) build(
	serverLongNonce *longNonce,
	ephClientPubkey ephemeralClientPubkey,
	permServerPrivkey permanentServerPrivkey) (serverCookieKey, error) {

	destHeader := c.buf[:8]
	destUnprefixedLongNonce := c.buf[8 : 8+16]
	destEncWelcomeBox := c.buf[8+16 : 168]

	ephServerPrivkey, p, err := genEphemeralServerKeyPair()
	if err != nil {
		return serverCookieKey{}, fmt.Errorf("cannot generate ephemeral keypair", err)
	}
	ephServerPubkey := ephemeralServerPubkey(p)

	cookie, cookieKey, err := newServerCookie(serverLongNonce, ephClientPubkey, ephServerPrivkey)
	if err != nil {
		return serverCookieKey{}, err
	}

	var unencwelcomebox [32 + 96]byte
	copy(unencwelcomebox[:32], ephServerPubkey[:])
	copy(unencwelcomebox[32:], cookie[:])

	Cprime := [32]byte(ephClientPubkey)
	S := [32]byte(permServerPrivkey)
	prefixedNonce := serverLongNonce.prefix(welcomeNoncePrefix)
	encWelcomeBox := box.Seal(nil, unencwelcomebox[:], &prefixedNonce, &Cprime, &S)

	copy(destHeader, []byte{7, 'W', 'E', 'L', 'C', 'O', 'M', 'E'})
	if err := serverLongNonce.writeUnprefixed(destUnprefixedLongNonce); err != nil {
		return serverCookieKey{}, err
	}
	copy(destEncWelcomeBox, encWelcomeBox)

	return cookieKey, nil
}
932569
func (t *ProtokubeBuilder) Build(c *fi.ModelBuilderContext) error {
	useGossip := dns.IsGossipHostname(t.Cluster.Spec.MasterInternalName)

	// check is not a master and we are not using gossip (https://github.com/kubernetes/kops/pull/3091)
	if !t.IsMaster && !useGossip {
		glog.V(2).Infof("skipping the provisioning of protokube on the nodes")
		return nil
	}

	if t.IsMaster {
		kubeconfig, err := t.BuildPKIKubeconfig("kops")
		if err != nil {
			return err
		}

		c.AddTask(&nodetasks.File{
			Path:     "/var/lib/kops/kubeconfig",
			Contents: fi.NewStringResource(kubeconfig),
			Type:     nodetasks.FileType_File,
			Mode:     s("0400"),
		})

		// retrieve the etcd peer certificates and private keys from the keystore
		if !t.UseEtcdManager() && t.UseEtcdTLS() {
			for _, x := range []string{"etcd", "etcd-peer", "etcd-client"} {
				if err := t.BuildCertificateTask(c, x, fmt.Sprintf("%s.pem", x)); err != nil {
					return err
				}
			}
			for _, x := range []string{"etcd", "etcd-peer", "etcd-client"} {
				if err := t.BuildPrivateKeyTask(c, x, fmt.Sprintf("%s-key.pem", x)); err != nil {
					return err
				}
			}
		}
	}

	service, err := t.buildSystemdService()
	if err != nil {
		return err
	}
	c.AddTask(service)

	return nil
}
859488
func (builder *ListBucketsCommandBuilder) Build() (Command, error) {
	if builder.protobuf == nil {
		panic("builder.protobuf must not be nil")
	}
	if err := validateLocatable(builder.protobuf); err != nil {
		return nil, err
	}
	if builder.protobuf.GetStream() && builder.callback == nil {
		return nil, newClientError("ListBucketsCommand requires a callback when streaming.", nil)
	}
	if !builder.allowListing {
		return nil, ErrListingDisabled
	}
	return &ListBucketsCommand{
		listingImpl: listingImpl{
			allowListing: builder.allowListing,
		},
		protobuf: builder.protobuf,
		callback: builder.callback}, nil
}
783595
func (c *readyCommand) build(serverShortNonce shortNoncer, sk *precomputedKey) error {

	// FIXME: to support metadata, bump the size of this buffer.
	_, err := c.realloc(30)
	if err != nil {
		return err
	}

	destHeader := c.buf[:6]
	destUnprefixedNonce := c.buf[6 : 6+8]
	destEncReadyBox := c.buf[6+8 : 6+8+16]

	prefixedNonce, unprefixedNonce, err := serverShortNonce.prefixAndBump(readyNoncePrefix)
	if err != nil {
		return err
	}

	encReadyBox := box.SealAfterPrecomputation(nil, []byte{}, &prefixedNonce, (*[32]byte)(sk))

	copy(destHeader, []byte{5, 'R', 'E', 'A', 'D', 'Y'})
	copy(destUnprefixedNonce, unprefixedNonce[:])
	copy(destEncReadyBox, encReadyBox)

	return nil
}
1166989
func (builder *FetchIndexCommandBuilder) Build() (Command, error) {
	if builder.protobuf == nil {
		panic("builder.protobuf must not be nil")
	}
	return &FetchIndexCommand{protobuf: builder.protobuf}, nil
}
898289
func (c *client) Build(owner, name string, num int) (*Build, error) {
	out := new(Build)
	uri := fmt.Sprintf(pathBuild, c.addr, owner, name, num)
	err := c.get(uri, out)
	return out, err
}
1245312
func (builder *FetchSetCommandBuilder) Build() (Command, error) {
	if builder.protobuf == nil {
		panic("builder.protobuf must not be nil")
	}
	if err := validateLocatable(builder.protobuf); err != nil {
		return nil, err
	}
	return &FetchSetCommand{
		timeoutImpl: timeoutImpl{
			timeout: builder.timeout,
		},
		protobuf: builder.protobuf,
	}, nil
}
1118537
func (builder *TsListKeysCommandBuilder) Build() (Command, error) {
	if builder.protobuf == nil {
		panic("builder.protobuf must not be nil")
	}
	if len(builder.protobuf.GetTable()) == 0 {
		return nil, ErrTableRequired
	}
	if builder.streaming && builder.callback == nil {
		return nil, newClientError("ListKeysCommand requires a callback when streaming.", nil)
	}
	if !builder.allowListing {
		return nil, ErrListingDisabled
	}
	return &TsListKeysCommand{
		timeoutImpl: timeoutImpl{
			timeout: builder.timeout,
		},
		protobuf:  builder.protobuf,
		streaming: builder.streaming,
		callback:  builder.callback,
	}, nil
}