// runDetached verifies a detached signature
423590
func (e *PGPVerify) runDetached(m libkb.MetaContext) error {
	sk, err := NewScanKeys(m)
	if err != nil {
		return err
	}
	checkfn := openpgp.CheckDetachedSignature
	if libkb.IsArmored(e.arg.Signature) {
		checkfn = openpgp.CheckArmoredDetachedSignature
	}
	signer, err := checkfn(sk, e.source, bytes.NewReader(e.arg.Signature))
	if err != nil {
		return err
	}

	e.signer = sk.KeyOwnerByEntity(signer)
	e.signStatus = &libkb.SignatureStatus{IsSigned: true}

	if signer != nil {
		if len(signer.UnverifiedRevocations) > 0 {
			return libkb.BadSigError{
				E: fmt.Sprintf("Key %x belonging to %q has been revoked by its designated revoker.", signer.PrimaryKey.KeyId, e.signer.GetName()),
			}
		}

		e.signStatus.Verified = true
		e.signStatus.Entity = signer
		if err := e.checkSignedBy(m); err != nil {
			return err
		}

		var r io.Reader = bytes.NewReader(e.arg.Signature)
		if libkb.IsArmored(e.arg.Signature) {
			block, err := armor.Decode(r)
			if err != nil {
				return err
			}
			r = block.Body
		}

		p, err := packet.Read(r)
		if err != nil {
			return err
		}

		if val, ok := p.(*packet.Signature); ok {
			e.signStatus.SignatureTime = val.CreationTime
		}

		fingerprint := libkb.PGPFingerprint(signer.PrimaryKey.Fingerprint)
		OutputSignatureSuccess(m, fingerprint, e.signer, e.signStatus.SignatureTime)
	}

	return nil
}
1201613
func (c *Container) runRemove(v uint16) bool {
	runs := c.runs()
	i, contains := binSearchRuns(v, runs)
	if !contains {
		return false
	}
	c.unmapRun()
	runs = c.runs()
	if v == runs[i].last && v == runs[i].start {
		runs = append(runs[:i], runs[i+1:]...)
	} else if v == runs[i].last {
		runs[i].last--
	} else if v == runs[i].start {
		runs[i].start++
	} else if v > runs[i].start {
		last := runs[i].last
		runs[i].last = v - 1
		runs = append(runs, interval16{})
		copy(runs[i+2:], runs[i+1:])
		runs[i+1] = interval16{start: v + 1, last: last}
		// runs = append(runs[:i+1], append([]interval16{{start: v + 1, last: last}}, runs[i+1:]...)...)
	}
	c.n--
	c.setRuns(runs)
	return true
}
536732
func startsWaitingForDependentsDeleted(oldObj interface{}, newAccessor metav1.Object) bool {
	return deletionStarts(oldObj, newAccessor) && hasDeleteDependentsFinalizer(newAccessor)
}
952059
func (ds *DiskSpec) newDetached() (*compute.Disk, error) {
	if ds.Scratch {
		return nil, errors.New("cannot create scratch volumes detached")
	}
	if ds.PersistentDiskType == DiskLocalSSD {
		return nil, errors.New("cannot create local ssd disks detached")
	}
	return &compute.Disk{
		Name:        ds.Name,
		SizeGb:      int64(ds.SizeGB()),
		SourceImage: ds.ImageURL,
		Type:        string(ds.PersistentDiskType),
		Labels:      ds.Labels,
	}, nil
}
167307
func (r *cmdRun) done(err error) int {
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		if err, ok := err.(*exitCode); ok {
			return err.code
		}
		return ecOtherError
	}
	return 0
}
963444
func (r *marathonClient) DeleteDeployment(id string, force bool) (*DeploymentID, error) {
	path := fmt.Sprintf("%s/%s", marathonAPIDeployments, id)

	// if force=true, no body is returned
	if force {
		path += "?force=true"
		return nil, r.apiDelete(path, nil, nil)
	}

	deployment := new(DeploymentID)
	err := r.apiDelete(path, nil, deployment)

	if err != nil {
		return nil, err
	}

	return deployment, nil
}
480001
func (e *PGPVerify) runAttached(m libkb.MetaContext) error {
	arg := &PGPDecryptArg{
		Source:       e.source,
		Sink:         libkb.NopWriteCloser{W: ioutil.Discard},
		AssertSigned: true,
		SignedBy:     e.arg.SignedBy,
	}
	eng := NewPGPDecrypt(m.G(), arg)
	if err := RunEngine2(m, eng); err != nil {
		return err
	}
	e.signStatus = eng.SignatureStatus()
	e.signer = eng.Signer()

	return nil
}
683938
func CheckArmoredDetachedSignature(keyring KeyRing, signed, signature io.Reader) (signer *Entity, err error) {
	body, err := readArmored(signature, SignatureType)
	if err != nil {
		return
	}

	return CheckDetachedSignature(keyring, signed, body)
}
260673
func (c *Controller) updateSpecLocked() error {
	crdSpecs := []*spec.Swagger{}
	for _, versionSpecs := range c.crdSpecs {
		for _, s := range versionSpecs {
			crdSpecs = append(crdSpecs, s)
		}
	}
	return c.openAPIService.UpdateSpec(mergeSpecs(c.staticSpec, crdSpecs...))
}
296814
func VerifyDetachedCheckSender(message io.Reader, signature []byte, checkSender func(sp.BasePublicKey) error) error {
	kr := basic.NewKeyring()
	var skey sp.SigningPublicKey
	var err error
	skey, _, err = sp.Dearmor62VerifyDetachedReader(sp.CheckKnownMajorVersion, message, string(signature), kr)
	if err != nil {
		return err
	}

	if err = checkSender(skey); err != nil {
		return err
	}

	return nil
}
987107
func (ipc *IPCache) deleteLocked(ip string, source Source) {
	scopedLog := log.WithFields(logrus.Fields{
		logfields.IPAddr: ip,
	})

	cachedIdentity, found := ipc.ipToIdentityCache[ip]
	if !found {
		scopedLog.Debug("Attempt to remove non-existing IP from ipcache layer")
		return
	}

	if cachedIdentity.Source != source {
		scopedLog.WithField("source", cachedIdentity.Source).
			Debugf("Skipping delete of identity from source %s", source)
		return
	}

	var cidr *net.IPNet
	cacheModification := Delete
	oldHostIP, encryptKey := ipc.getHostIPCache(ip)
	var newHostIP net.IP
	var oldIdentity *identity.NumericIdentity
	newIdentity := cachedIdentity
	callbackListeners := true

	var err error
	if _, cidr, err = net.ParseCIDR(ip); err == nil {
		// Remove a reference for the prefix length if this is a CIDR.
		pl, bits := cidr.Mask.Size()
		switch bits {
		case net.IPv6len * 8:
			unrefPrefixLength(ipc.v6PrefixLengths, pl)
		case net.IPv4len * 8:
			unrefPrefixLength(ipc.v4PrefixLengths, pl)
		}

		// Check whether the deleted CIDR was shadowed by an endpoint IP. In
		// this case, skip calling back the listeners since they don't know
		// about its mapping.
		if _, endpointIPFound := ipc.ipToIdentityCache[cidr.IP.String()]; endpointIPFound {
			scopedLog.Debug("Deleting CIDR shadowed by endpoint IP")
			callbackListeners = false
		}
	} else if endpointIP := net.ParseIP(ip); endpointIP != nil { // Endpoint IP.
		// Convert the endpoint IP into an equivalent full CIDR.
		bits := net.IPv6len * 8
		if endpointIP.To4() != nil {
			bits = net.IPv4len * 8
		}
		cidr = &net.IPNet{
			IP:   endpointIP,
			Mask: net.CIDRMask(bits, bits),
		}

		// Check whether the deleted endpoint IP was shadowing that CIDR, and
		// restore its mapping with the listeners if that was the case.
		cidrStr := cidr.String()
		if cidrIdentity, cidrFound := ipc.ipToIdentityCache[cidrStr]; cidrFound {
			newHostIP, _ = ipc.getHostIPCache(cidrStr)
			if cidrIdentity.ID != cachedIdentity.ID || bytes.Compare(oldHostIP, newHostIP) != 0 {
				scopedLog.Debug("Removal of endpoint IP revives shadowed CIDR to identity mapping")
				cacheModification = Upsert
				oldIdentity = &cachedIdentity.ID
				newIdentity = cidrIdentity
			} else {
				// The endpoint IP and the CIDR were associated with the same
				// identity and host IP. Nothing changes for the listeners.
				callbackListeners = false
			}
		}
	} else {
		scopedLog.Error("Attempt to delete invalid IP from ipcache layer")
		return
	}

	scopedLog.Debug("Deleting IP from ipcache layer")

	delete(ipc.ipToIdentityCache, ip)
	delete(ipc.identityToIPCache[cachedIdentity.ID], ip)
	if len(ipc.identityToIPCache[cachedIdentity.ID]) == 0 {
		delete(ipc.identityToIPCache, cachedIdentity.ID)
	}
	delete(ipc.ipToHostIPCache, ip)

	if callbackListeners {
		for _, listener := range ipc.listeners {
			listener.OnIPIdentityCacheChange(cacheModification, *cidr, oldHostIP, newHostIP,
				oldIdentity, newIdentity.ID, encryptKey)
		}
	}
}
1165261
func (op *UpdateUnitOperation) Done(err error) error {
	if err != nil {
		return errors.Annotatef(err, "updating unit %q", op.unit.Name())
	}
	// We can't include in the ops slice the necessary status history updates,
	// so as with existing practice, do a best effort update of status history.
	for key, doc := range op.setStatusDocs {
		probablyUpdateStatusHistory(op.unit.st.db(), key, doc)
	}
	return nil
}
198151
func (g *GlobalContext) shutdownCachesLocked() {

	// shutdown and nil out any existing caches.
	if g.trackCache != nil {
		g.trackCache.Shutdown()
	}
	if g.identify2Cache != nil {
		g.identify2Cache.Shutdown()
	}
	if g.linkCache != nil {
		g.linkCache.Shutdown()
	}
	if g.cardCache != nil {
		g.cardCache.Shutdown()
	}
}
49658
func (c *Client) RunJobAttached(appID string, job *ct.NewJob) (httpclient.ReadWriteCloser, error) {
	return c.Hijack("POST", fmt.Sprintf("/apps/%s/jobs", appID), http.Header{"Upgrade": {"flynn-attach/0"}}, job)
}
1196077
func (c *ReportingClient) RunStepsAdded(ctx context.Context, args RunStepsAddedArgs) error {
	return c.postJSON("runstepsadded", args)
}
1131884
func runDeps(ctx context.Context, types []funcType, fns []interface{}) {
	mu := &sync.Mutex{}
	var errs []string
	var exit int
	wg := &sync.WaitGroup{}
	for i, f := range fns {
		fn := addDep(ctx, types[i], f)
		wg.Add(1)
		go func() {
			defer func() {
				if v := recover(); v != nil {
					mu.Lock()
					if err, ok := v.(error); ok {
						exit = changeExit(exit, ExitStatus(err))
					} else {
						exit = changeExit(exit, 1)
					}
					errs = append(errs, fmt.Sprint(v))
					mu.Unlock()
				}
				wg.Done()
			}()
			if err := fn.run(); err != nil {
				mu.Lock()
				errs = append(errs, fmt.Sprint(err))
				exit = changeExit(exit, ExitStatus(err))
				mu.Unlock()
			}
		}()
	}

	wg.Wait()
	if len(errs) > 0 {
		panic(Fatal(exit, strings.Join(errs, "\n")))
	}
}
1332395
func SignDetachedArmor62(version Version, plaintext []byte, signer SigningSecretKey, brand string) (string, error) {
	buf, err := signToStream(version, plaintext, signer, applyBrand(NewSignDetachedArmor62Stream, brand))
	if err != nil {
		return "", err
	}
	return buf.String(), nil
}