code: func (ssa *SQLStorageAuthority) FinalizeAuthorization(ctx context.Context, authz core.Authorization) error {
  	tx, err := ssa.dbMap.Begin()
  	if err != nil {
  		return err
  	}
  	txWithCtx := tx.WithContext(ctx)
  
  	// Check that a pending authz exists
  	if !existingPending(txWithCtx, authz.ID) {
  		err = berrors.NotFoundError("authorization with ID %q not found", authz.ID)
  		return Rollback(tx, err)
  	}
  	if statusIsPending(authz.Status) {
  		err = berrors.InternalServerError("authorization to finalize is pending (ID %q)", authz.ID)
  		return Rollback(tx, err)
  	}
  
  	auth := &authzModel{authz}
  	pa, err := selectPendingAuthz(txWithCtx, "WHERE id = ?", authz.ID)
  	if err == sql.ErrNoRows {
  		return Rollback(tx, berrors.NotFoundError("authorization with ID %q not found", authz.ID))
  	}
  	if err != nil {
  		return Rollback(tx, err)
  	}
  
  	err = txWithCtx.Insert(auth)
  	if err != nil {
  		return Rollback(tx, err)
  	}
  
  	_, err = txWithCtx.Delete(pa)
  	if err != nil {
  		return Rollback(tx, err)
  	}
  
  	err = updateChallenges(txWithCtx, authz.ID, authz.Challenges)
  	if err != nil {
  		return Rollback(tx, err)
  	}
  
  	return tx.Commit()
  }
docs: // FinalizeAuthorization converts a Pending Authorization to a final one. If the
  // Authorization is not found a berrors.NotFound result is returned. If the
  // Authorization is status pending a berrors.InternalServer error is returned.