text:
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0

package oauth2

import (
	"bytes"
	"context"
	"encoding/json"
	"net/http"
	"net/url"

	"github.com/hashicorp/go-retryablehttp"

	"github.com/ory/hydra/v2/flow"
	"github.com/ory/hydra/v2/x"

	"github.com/ory/fosite"
	"github.com/ory/hydra/v2/driver/config"
	"github.com/ory/x/errorsx"
)

// AccessRequestHook is called when an access token request is performed.
type AccessRequestHook func(ctx context.Context, requester fosite.AccessRequester) error

// Request is a token endpoint's request context.
//
// swagger:ignore
type Request struct {
	// ClientID is the identifier of the OAuth 2.0 client.
	ClientID string `json:"client_id"`
	// GrantedScopes is the list of scopes granted to the OAuth 2.0 client.
	GrantedScopes []string `json:"granted_scopes"`
	// GrantedAudience is the list of audiences granted to the OAuth 2.0 client.
	GrantedAudience []string `json:"granted_audience"`
	// GrantTypes is the requests grant types.
	GrantTypes []string `json:"grant_types"`
	// Payload is the requests payload.
	Payload map[string][]string `json:"payload"`
}

// TokenHookRequest is the request body sent to the token hook.
//
// swagger:ignore
type TokenHookRequest struct {
	// Session is the request's session..
	Session *Session `json:"session"`
	// Requester is a token endpoint's request context.
	Request Request `json:"request"`
}

// TokenHookResponse is the response body received from the token hook.
//
// swagger:ignore
type TokenHookResponse struct {
	// Session is the session data returned by the hook.
	Session flow.AcceptOAuth2ConsentRequestSession `json:"session"`
}

func executeHookAndUpdateSession(ctx context.Context, reg x.HTTPClientProvider, hookURL *url.URL, reqBodyBytes []byte, session *Session) error {
	req, err := retryablehttp.NewRequestWithContext(ctx, http.MethodPost, hookURL.String(), bytes.NewReader(reqBodyBytes))
	if err != nil {
		return errorsx.WithStack(
			fosite.ErrServerError.
				WithWrap(err).
				WithDescription("An error occurred while preparing the token hook.").
				WithDebugf("Unable to prepare the HTTP Request: %s", err),
		)
	}
	req.Header.Set("Content-Type", "application/json; charset=UTF-8")

	resp, err := reg.HTTPClient(ctx).Do(req)
	if err != nil {
		return errorsx.WithStack(
			fosite.ErrServerError.
				WithWrap(err).
				WithDescription("An error occurred while executing the token hook.").
				WithDebugf("Unable to execute HTTP Request: %s", err),
		)
	}
	defer resp.Body.Close()

	switch resp.StatusCode {
	case http.StatusOK:
		// Token permitted with new session data
	case http.StatusNoContent:
		// Token is permitted without overriding session data
		return nil
	case http.StatusForbidden:
		return errorsx.WithStack(
			fosite.ErrAccessDenied.
				WithDescription("The token hook target responded with an error.").
				WithDebugf("Token hook responded with HTTP status code: %s", resp.Status),
		)
	default:
		return errorsx.WithStack(
			fosite.ErrServerError.
				WithDescription("The token hook target responded with an error.").
				WithDebugf("Token hook responded with HTTP status code: %s", resp.Status),
		)
	}

	var respBody TokenHookResponse
	if err := json.NewDecoder(resp.Body).Decode(&respBody); err != nil {
		return errorsx.WithStack(
			fosite.ErrServerError.
				WithWrap(err).
				WithDescription("The token hook target responded with an error.").
				WithDebugf("Response from token hook could not be decoded: %s", err),
		)
	}

	// Overwrite existing session data (extra claims).
	session.Extra = respBody.Session.AccessToken
	idTokenClaims := session.IDTokenClaims()
	idTokenClaims.Extra = respBody.Session.IDToken
	return nil
}

// TokenHook is an AccessRequestHook called for all grant types.
func TokenHook(reg interface {
	config.Provider
	x.HTTPClientProvider
}) AccessRequestHook {
	return func(ctx context.Context, requester fosite.AccessRequester) error {
		hookURL := reg.Config().TokenHookURL(ctx)
		if hookURL == nil {
			return nil
		}

		session, ok := requester.GetSession().(*Session)
		if !ok {
			return nil
		}

		request := Request{
			ClientID:        requester.GetClient().GetID(),
			GrantedScopes:   requester.GetGrantedScopes(),
			GrantedAudience: requester.GetGrantedAudience(),
			GrantTypes:      requester.GetGrantTypes(),
			Payload:         requester.Sanitize([]string{"assertion"}).GetRequestForm(),
		}

		reqBody := TokenHookRequest{
			Session: session,
			Request: request,
		}

		reqBodyBytes, err := json.Marshal(&reqBody)
		if err != nil {
			return errorsx.WithStack(
				fosite.ErrServerError.
					WithWrap(err).
					WithDescription("An error occurred while encoding the token hook.").
					WithDebugf("Unable to encode the token hook body: %s", err),
			)
		}

		err = executeHookAndUpdateSession(ctx, reg, hookURL, reqBodyBytes, session)
		if err != nil {
			return err
		}

		return nil
	}
}

repository: ory/hydra

repo_name: ory/hydra


text:
using System;

namespace Nameless {

    /// <summary>
    /// Extension methods for <see cref="EventHandler{TEventArgs}"/>.
    /// </summary>
    public static class EventHandlerExtension {

        #region Public Static Methods

        /// <summary>
        /// Before invokes the handler, checks if it is not <c>null</c>.
        /// </summary>
        /// <typeparam name="TEventArgs">The type of the event handler.</typeparam>
        /// <param name="self">The event handler.</param>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">The event arguments.</param>
        public static void SafeInvoke<TEventArgs> (this EventHandler<TEventArgs> self, object sender, TEventArgs e) where TEventArgs : EventArgs {
            self?.Invoke (sender, e);
        }

        #endregion Public Static Methods
    }
}

license: MIT

repository: marcoaoteixeira/Nameless

license_type: permissive

repo_name: marcoaoteixeira/Nameless

branch_name: refs/heads/master

extension: cs


text:
using System;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
using OpenSim.Framework;
using OpenMetaverse;
using log4net;
using OpenSim.Server.Base;

namespace OpenSim.Services.Connectors.Hypergrid
{
    public class DisplayNameServiceConnector
    {
        private static readonly ILog m_log =
            LogManager.GetLogger(
            MethodBase.GetCurrentMethod().DeclaringType);

        private string m_ServerURLHost;
        private string m_ServerURL;

        public DisplayNameServiceConnector(string url) : this(url, true)
        {
        }

        public DisplayNameServiceConnector(string url, bool dnsLookup)
        {
            m_ServerURL = m_ServerURLHost = url;

            if (dnsLookup)
            {
                try
                {
                    Uri m_Uri = new Uri(m_ServerURL);
                    IPAddress ip = Util.GetHostFromDNS(m_Uri.Host);
                    if(ip != null)
                    {
                        m_ServerURL = m_ServerURL.Replace(m_Uri.Host, ip.ToString());
                        if (!m_ServerURL.EndsWith("/"))
                            m_ServerURL += "/";
                    }
                    else
                        m_log.DebugFormat("[DISPLAY NAME CONNECTOR]: Failed to resolve address of {0}", url);
                }
                catch (Exception e)
                {
                    m_log.DebugFormat("[DISPLAY NAME CONNECTOR]: Malformed Uri {0}: {1}", url, e.Message);
                }
            }
        }

        public Dictionary<UUID, string> GetDisplayNames (UUID[] userIDs)
        {
            string uri = m_ServerURL + "get_display_names";

            List<string> str_userIDs = new List<string>();
            foreach(UUID id in userIDs) str_userIDs.Add(id.ToString());

            Dictionary<string, object> sendData = new Dictionary<string, object>();
            sendData["AgentIDs"] = new List<string>(str_userIDs);

            string reqString = ServerUtils.BuildQueryString(sendData);

            Dictionary<UUID, string> data = new Dictionary<UUID, string>();
            try
            {
                string reply = SynchronousRestFormsRequester.MakeRequest("POST",
                        uri,
                        reqString, 5, null, false);
                if (reply != string.Empty)
                {
                    Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);

                    if((string)replyData?["success"] == "true")
                    {
                        int i = 0;
                        while(true)
                        {
                            if(replyData.ContainsKey("uuid" + i) && replyData.ContainsKey("name" + i))
                            {
                                string str_uuid = replyData["uuid" + i].ToString();
                                string name = replyData["name" + i].ToString();

                                UUID uuid = UUID.Parse(str_uuid);
                                data.Add(uuid, name);
                                i++;
                            }
                            else break;
                        }
                    }

                }
            }
            catch (Exception e)
            {
                m_log.DebugFormat("[HGGetDisplayNames Connector]: Exception when contacting display name server at {0}: {1}", uri, e.Message);
            }

            return data;
        }

    }
}

repository: Open-Consortium/opensim

repo_name: Open-Consortium/opensim

gha_license_id: NOASSERTION

gha_language: C#


text:
package transactions

import (
	"context"
	"encoding/json"
	"reflect"
	"time"

	"github.com/centrifuge/go-centrifuge/identity"
	"github.com/centrifuge/go-centrifuge/protobufs/gen/go/transactions"
	"github.com/ethereum/go-ethereum/common/hexutil"
	"github.com/satori/go.uuid"
)

// Status represents the status of the transaction
type Status string

const (
	// Status constants

	// Success is the success status for a transaction or a task
	Success Status = "success"
	// Failed is the failed status for a transaction or a task
	Failed Status = "failed"
	// Pending is the pending status for a transaction or a task
	Pending Status = "pending"

	// TxIDParam maps transaction ID in the kwargs.
	TxIDParam = "transactionID"

	// BootstrappedRepo is the key mapped to transactions.Repository.
	BootstrappedRepo = "BootstrappedRepo"

	// BootstrappedService is the key to mapped transactions.Manager
	BootstrappedService = "BootstrappedService"
)

// Log represents a single task in a transaction.
type Log struct {
	Action    string
	Message   string
	CreatedAt time.Time
}

// NewLog constructs a new log with action and message
func NewLog(action, message string) Log {
	return Log{
		Action:    action,
		Message:   message,
		CreatedAt: time.Now().UTC(),
	}
}

// TxID is a centrifuge transaction ID. Internally represented by a UUID. Externally visible as a byte slice or a hex encoded string.
type TxID uuid.UUID

// NewTxID creates a new TxID
func NewTxID() TxID {
	u := uuid.Must(uuid.NewV4())
	return TxID(u)
}

// FromString tries to convert the given hex string txID into a type TxID
func FromString(tIDHex string) (TxID, error) {
	tidBytes, err := hexutil.Decode(tIDHex)
	if err != nil {
		return NilTxID(), err
	}
	u, err := uuid.FromBytes(tidBytes)
	if err != nil {
		return NilTxID(), err
	}
	return TxID(u), nil
}

// NilTxID returns a nil TxID
func NilTxID() TxID {
	return TxID(uuid.Nil)
}

// String marshals a TxID to its hex string form
func (t TxID) String() string {
	return hexutil.Encode(t[:])
}

// Bytes returns the byte slice representation of the TxID
func (t TxID) Bytes() []byte {
	return uuid.UUID(t).Bytes()
}

// TxIDEqual checks if given two TxIDs are equal
func TxIDEqual(t1 TxID, t2 TxID) bool {
	u1 := uuid.UUID(t1)
	u2 := uuid.UUID(t2)
	return uuid.Equal(u1, u2)
}

// Transaction contains details of transaction.
type Transaction struct {
	ID          TxID
	DID         identity.DID
	Description string

	// Status is the overall status of the transaction
	Status Status

	// TaskStatus tracks the status of individual tasks running in the system for this transaction
	TaskStatus map[string]Status

	// Logs are transaction log messages
	Logs      []Log
	CreatedAt time.Time

	// Values retrieved from events
	Values map[string]TXValue
}

// JSON returns json marshaled transaction.
func (t *Transaction) JSON() ([]byte, error) {
	return json.Marshal(t)
}

// FromJSON loads the data into transaction.
func (t *Transaction) FromJSON(data []byte) error {
	return json.Unmarshal(data, t)
}

// Type returns the reflect.Type of the transaction.
func (t *Transaction) Type() reflect.Type {
	return reflect.TypeOf(t)
}

// NewTransaction returns a new transaction with a pending state
func NewTransaction(identity identity.DID, description string) *Transaction {
	return &Transaction{
		ID:          NewTxID(),
		DID:         identity,
		Description: description,
		Status:      Pending,
		TaskStatus:  make(map[string]Status),
		CreatedAt:   time.Now().UTC(),
		Values:      make(map[string]TXValue),
	}
}

// TXValue holds the key and value filtered by the transaction
type TXValue struct {
	Key    string
	KeyIdx int
	Value  []byte
}

// Config is the config interface for transactions package
type Config interface {
	GetEthereumContextWaitTimeout() time.Duration
}

// Manager is a manager for centrifuge transactions.
type Manager interface {
	// ExecuteWithinTX executes the given unit of work within a transaction
	ExecuteWithinTX(ctx context.Context, accountID identity.DID, existingTxID TxID, desc string, work func(accountID identity.DID, txID TxID, txMan Manager, err chan<- error)) (txID TxID, done chan bool, err error)
	GetTransaction(accountID identity.DID, id TxID) (*Transaction, error)
	UpdateTransactionWithValue(accountID identity.DID, id TxID, key string, value []byte) error
	UpdateTaskStatus(accountID identity.DID, id TxID, status Status, taskName, message string) error
	GetTransactionStatus(accountID identity.DID, id TxID) (*transactionspb.TransactionStatusResponse, error)
	WaitForTransaction(accountID identity.DID, txID TxID) error
	GetDefaultTaskTimeout() time.Duration
}

// Repository can be implemented by a type that handles storage for transactions.
type Repository interface {
	Get(cid identity.DID, id TxID) (*Transaction, error)
	Save(transaction *Transaction) error
}

repository: neuromancer/go-centrifuge

repo_name: neuromancer/go-centrifuge

extension: go


text:
using System;
using System.Reflection;
using Sitecore.Data;
using Sitecore.Data.Fields;
using Sitecore.Data.Items;

namespace Propeller.Mvc.Model.Strategies
{
    class DateFieldStrategy : IFieldStrategy
    {
        public object CreateField(Item item, ID propertyId, PropertyInfo pi)
        {
            var field = item.Fields[propertyId];
            var dateField = (DateField)field;
            if (dateField != null)
                return dateField.DateTime;
            return DateTime.MinValue;
        }
    }
}

gha_license_id: MIT


text:
// Package model declares interfaces for model objects
package model

import (
	"html/template"
	"time"

	"github.com/go-xiaohei/pugo/app/model/index"
)

type (
	// Target is object that will compiled
	Target interface {
		SrcFile() string
		DstFile() string
	}
	// Node is object of a node in site
	Node interface {
		URL() string
		CreateTime() time.Time
		UpdateTime() time.Time
	}
	// Content is object of node with content output
	Content interface {
		Target
		Node
		Content() []byte
		ContentHTML() template.HTML
		ContentLength() int
	}
	// Index is object of node that can get index for content
	Index interface {
		Index() []*index.Index
	}
)

repository: kgotso/docker-image

repo_name: kgotso/docker-image


text:
package indicators

import (
	"testing"
)

// nolint dupl false positive
func TestSMA(t *testing.T) {
	expectedOutput := []float64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7256.463571428571, 7245.534999999999, 7277.432857142857, 7342.2535714285705, 7402.871428571429, 7447.0485714285705, 7515.191428571428, 7566.61857142857, 7623.419999999999, 7686.617857142856, 7804.094999999999, 7920.558571428571, 8046.24357142857, 8157.223571428571, 8268.941428571428, 8364.648571428572, 8426.250714285716, 8466.170714285716, 8509.848571428573, 8550.68142857143, 8566.547857142858, 8588.925000000001, 8618.190714285714, 8674.585714285713, 8716.511428571428, 8750.797857142856, 8807.215714285714, 8838.302857142857, 8871.777142857141, 8916.976428571428, 8964.327857142856, 8995.862142857142, 9064.611428571428, 9162.910714285714, 9261.574285714285, 9373.895714285713, 9487.002142857144, 9555.25, 9617.320000000002, 9693.005714285715, 9745.05357142857, 9819.06714285714, 9856.396428571428, 9898.074999999999, 9927.29357142857, 10000.565, 9998.94357142857, 9988.81, 9981.146428571428, 9964.441428571428, 9949.529999999999, 9935.427857142857, 9866.600714285716, 9754.499285714284, 9653.630000000001, 9535.044285714286, 9437.041428571427, 9338.18857142857, 9282.487857142856, 9180.365, 9120.190714285714, 9081.182857142856, 9042.444285714286, 8987.144285714285, 8849.179285714283, 8726.584285714283, 8625.192857142856, 8564.850714285712, 8280.934285714286, 8060.855714285715, 7820.972142857144, 7593.45, 7316.027142857143, 7070.994285714286, 6831.9685714285715, 6625.863571428571, 6415.602857142859, 6222.306428571428, 6063.695714285713, 5960.642857142856, 5880.837142857142, 5792.097857142857, 5929.172857142857, 5982.979285714285, 6060.387142857143, 6098.0485714285705, 6163.304999999999}

	ret := SMA(testClose, 14)
	if len(ret) != len(expectedOutput) {
		t.Fatalf("unexpected length of return slice %v", len(ret))
	}

	for x := range ret {
		if ret[x] != expectedOutput[x] {
			t.Fatalf("unexpected value returned %v", ret[x])
		}
	}

	ret = SMA([]float64{10, 5.0}, 15)
	if ret[0] != 0 {
		t.Fatalf("unexpected value returned %v", ret[0])
	}
}

// nolint dupl false positive
func TestEMA(t *testing.T) {
	expectedOutput := []float64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7256.463571428571, 7269.828428571429, 7335.549971428572, 7445.344641904762, 7525.224022984127, 7562.764819919577, 7647.729510596967, 7696.861575850705, 7761.3813657372775, 7807.1985169723075, 7941.310714709333, 8057.025286081423, 8144.108581270566, 8243.911437101156, 8332.527245487669, 8381.070279422645, 8413.616908832959, 8454.186654321898, 8481.08576707898, 8467.399664801782, 8461.363709494877, 8443.781881562227, 8463.341630687262, 8520.834746595627, 8638.056780382876, 8724.87320966516, 8828.223448376471, 8894.840321926275, 8959.150945669438, 9008.516152913513, 9045.792665858378, 9060.936310410594, 9135.267469022516, 9217.849139819513, 9295.925254510244, 9376.735220575545, 9483.033191165472, 9531.96343234341, 9630.232308030954, 9726.038666960161, 9793.05617803214, 9869.187354294521, 9873.266373721919, 9878.54952389233, 9854.362920706686, 9898.470531279128, 9858.103793775244, 9825.391287938544, 9808.15644954674, 9789.48625627384, 9812.91608877066, 9791.537943601239, 9726.719551121074, 9600.404944304932, 9495.884285064274, 9390.278380389038, 9275.273263003834, 9175.763494603323, 9141.307028656214, 9089.859424835386, 9044.982168190667, 9047.871212431912, 9061.99371744099, 9039.58522178219, 8905.467192211232, 8776.238233249735, 8657.529135483102, 8561.134584085356, 8065.205972873975, 7739.543843157445, 7396.853997403119, 7123.092131082703, 6844.469180271676, 6641.871956235453, 6477.211695404059, 6437.740802683518, 6407.394028992382, 6378.112158460064, 6302.783870665389, 6328.214021243338, 6386.937485077559, 6427.641820400551, 6472.052244347145, 6459.249278434192, 6431.760041309633, 6356.978702468349, 6302.3162088059025}

	ret := EMA(testClose, 14)
	if len(ret) != len(expectedOutput) {
		t.Fatalf("unexpected length of return slice %v", len(ret))
	}

	for x := range ret {
		if ret[x] != expectedOutput[x] {
			t.Fatalf("unexpected value returned %v", ret[x])
		}
	}

	ret = EMA([]float64{10, 5.0}, 15)
	if ret[0] != 0 {
		t.Fatalf("unexpected value returned %v", ret[0])
	}

	ret = MA(testClose, 14, Ema)
	if len(ret) != len(expectedOutput) {
		t.Fatalf("unexpected length of return slice %v", len(ret))
	}

	for x := range ret {
		if ret[x] != expectedOutput[x] {
			t.Fatalf("unexpected value returned %v", ret[x])
		}
	}
}

func TestMA(t *testing.T) {
	ret := MA([]float64{10, 0}, 1, Sma)
	if ret[0] != 10 && ret[1] != 0 {
		t.Fatalf("unexpected values returned %v | %v", ret[0], ret[1])
	}
}

func TestMACD(t *testing.T) {
	expectedOutput := []float64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 384.56291818286354, 342.45086208073735, 326.37342938442, 334.3132934612713, 377.0457420290477, 397.38842119720175, 425.61532457741123, 429.1473391963518, 430.95837812348327, 423.6545667060109, 409.80964816860615, 384.02403224136833, 396.0646575719784, 411.8503935709232, 423.4167634439327, 435.51740350462205, 461.7304131988403, 451.1628234926138, 471.16402445220774, 487.8309024182472, 485.7482466660749, 489.379690203079, 449.6128759918647, 414.3785585786136, 364.8410328721784, 360.8022189099029, 306.5045473564405, 261.8300235198931, 230.49539631439438, 201.08512831789994, 199.45001660192247, 170.95686620790184, 118.98967582845034, 34.95532808582175, -28.31916462519257, -86.5575943603144, -145.24744564156208, -189.4777570939168, -190.98916627061772, -202.911106038453, -210.11238527492242, -188.36179339153205, -162.22281919922716, -160.62444546794177, -226.16401652784407, -282.70910477673715, -327.80398468938256, -355.5181614335979, -619.907124279539, -757.6774270872747, -893.1488902319425, -975.2072856845234, -1053.131472598261, -1078.922542429842, -1080.2980809881474, -1007.3003624114554, -936.3190118181901, -871.820244124684, -841.2367623804885, -753.4148691349728, -654.0749257758371, -574.8868228502934, -500.8290576197369, -467.7866597026932, -446.3758162098229, -455.00132838823083, -450.5025549851234}
	expectedOutput2 := []float64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 499.4721770310679, 468.06791404100176, 439.7290171096854, 418.6458723800026, 410.3258463098116, 407.73836128728965, 411.313753945314, 414.88047099552153, 418.0960524211139, 419.20775527809326, 417.32813385619585, 410.66731353323036, 407.74678234097996, 408.5675045869686, 411.5373563583614, 416.33336578761356, 425.4127752698589, 430.5627849144099, 438.6830328219695, 448.51260674122506, 455.95973472619505, 462.6437258215718, 460.0375558556304, 450.905756400227, 433.69281169461726, 419.1146931376744, 396.5926639814276, 369.6401358891207, 341.8111879741754, 313.6659760429203, 290.82278415472075, 266.849600565357, 237.27761561797564, 196.81315811154485, 151.78669356419738, 104.11783597929502, 54.2447796551236, 5.500272305315512, -33.797615409871135, -67.62031353558751, -96.1187278834545, -114.56734098507, -124.09843662790144, -131.4036383959095, -150.3557140222964, -176.82639217318456, -207.02191067642417, -236.7211608278589, -313.3583535181949, -402.22216823201086, -500.4075126319972, -595.3674672425025, -686.9202683136542, -765.3207231368917, -828.3161947071428, -864.1130282480053, -878.5542249620423, -877.2074287945707, -870.0132955117542, -846.693610236398, -808.1698733442857, -761.5132632454872, -709.3764221203371, -661.0584696368084, -618.1219389514113, -585.4978168387752, -558.4987644680448}
	expectedOutput3 := []float64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -114.90925884820433, -125.6170519602644, -113.35558772526542, -84.33257891873126, -33.28010428076391, -10.349940090087898, 14.301570632097253, 14.266868200830288, 12.86232570236939, 4.446811427917623, -7.518485687589703, -26.643281291862024, -11.682124769001575, 3.2828889839545923, 11.879407085571302, 19.184037717008493, 36.31763792898141, 20.600038578203907, 32.480991630238236, 39.31829567702215, 29.788511939879868, 26.735964381507188, -10.424679863765675, -36.52719782161341, -68.85177882243886, -58.31247422777153, -90.0881166249871, -107.81011236922762, -111.31579165978104, -112.58084772502036, -91.37276755279828, -95.89273435745514, -118.2879397895253, -161.8578300257231, -180.10585818938995, -190.67543033960942, -199.4922252966857, -194.97802939923233, -157.1915508607466, -135.2907925028655, -113.99365739146792, -73.79445240646204, -38.124382571325725, -29.220807072032272, -75.80830250554766, -105.88271260355259, -120.78207401295839, -118.79700060573902, -306.54877076134403, -355.4552588552639, -392.7413775999453, -379.83981844202094, -366.2112042846069, -313.60181929295027, -251.98188628100456, -143.18733416345003, -57.76478685614779, 5.387184669886665, 28.77653313126575, 93.27874110142511, 154.09494756844867, 186.62644039519387, 208.54736450060022, 193.27180993411514, 171.74612274158835, 130.49648845054435, 107.99620948292136}
	ret, ret2, ret3 := MACD(testClose, 12, 26, 9)
	if len(ret) != len(expectedOutput) || len(ret2) != len(expectedOutput2) || len(ret3) != len(expectedOutput3) {
		t.Fatalf("unexpected length of return slice %v", len(ret))
	}

	for x := range ret {
		if ret[x] != expectedOutput[x] {
			t.Fatalf("unexpected value returned %v", ret[x])
		}
		if ret2[x] != expectedOutput2[x] {
			t.Fatalf("unexpected value returned %v", ret2[x])
		}
		if ret3[x] != expectedOutput3[x] {
			t.Fatalf("unexpected value returned %v", ret3[x])
		}
	}
}

repository: NirvanaNimbusa/gct-ta

repo_name: NirvanaNimbusa/gct-ta


text:
package cpt

import (
	"context"
	"time"

	"github.com/go-kit/kit/metrics"
	"github.com/money-hub/MoneyDodo.service/model"
)

type InstrumentingMiddleware struct {
	RequestCount   metrics.Counter
	RequestLatency metrics.Histogram
	Next           CptService
}

func (i *InstrumentingMiddleware) GetSpec(ctx context.Context, taskId string) (status bool, errinfo string, data interface{}) {
	defer func(begin time.Time) {
		lvs := []string{"method", "GetSpec", "error", errinfo}
		i.RequestCount.With(lvs...).Add(1)
		i.RequestLatency.With(lvs...).Observe(time.Since(begin).Seconds())
	}(time.Now())
	status, errinfo, data = i.Next.GetSpec(ctx, taskId)
	return
}

func (i *InstrumentingMiddleware) GetAll(ctx context.Context, kind, state string, page, offset, limit int, orderby string) (status bool, errinfo string, data []model.Task) {
	defer func(begin time.Time) {
		lvs := []string{"method", "GetAll", "error", errinfo}
		i.RequestCount.With(lvs...).Add(1)
		i.RequestLatency.With(lvs...).Observe(time.Since(begin).Seconds())
	}(time.Now())
	status, errinfo, data = i.Next.GetAll(ctx, kind, state, page, offset, limit, orderby)
	return
}

func (i *InstrumentingMiddleware) Post(ctx context.Context, kind string, task interface{}) (status bool, errinfo string, data interface{}) {
	defer func(begin time.Time) {
		lvs := []string{"method", "Post", "error", errinfo}
		i.RequestCount.With(lvs...).Add(1)
		i.RequestLatency.With(lvs...).Observe(time.Since(begin).Seconds())
	}(time.Now())
	status, errinfo, data = i.Next.Post(ctx, kind, task)
	return
}

func (i *InstrumentingMiddleware) Put(ctx context.Context, taskId string, task interface{}) (status bool, errinfo string, data interface{}) {
	defer func(begin time.Time) {
		lvs := []string{"method", "Put", "error", errinfo}
		i.RequestCount.With(lvs...).Add(1)
		i.RequestLatency.With(lvs...).Observe(time.Since(begin).Seconds())
	}(time.Now())
	status, errinfo, data = i.Next.Put(ctx, taskId, task)
	return
}

func (i *InstrumentingMiddleware) Delete(ctx context.Context, taskId string, state string) (status bool, errinfo string, data *model.Task) {
	defer func(begin time.Time) {
		lvs := []string{"method", "Delete", "error", errinfo}
		i.RequestCount.With(lvs...).Add(1)
		i.RequestLatency.With(lvs...).Observe(time.Since(begin).Seconds())
	}(time.Now())
	status, errinfo, data = i.Next.Delete(ctx, taskId, state)
	return
}

gha_language: Go


text:
# A macro to define a command that uses the BIF compiler to produce C++
# segments and Zeek language declarations from a .bif file. The outputs
# are returned in BIF_OUTPUT_{CC,H,BRO}. By default, it runs bifcl in
# alternative mode (-a; suitable for standalone compilation). If
# an additional parameter "standard" is given, it runs it in standard mode
# for inclusion in NetVar.*. If an additional parameter "plugin" is given,
# it runs it in plugin mode (-p). In the latter case, one more argument
# is required with the plugin's name.
#
# The macro also creates a target that can be used to define depencencies on
# the generated files. The name of the target depends on the mode and includes
# a normalized path to the input bif to make it unique. The target is added
# automatically to bro_ALL_GENERATED_OUTPUTS.
macro(bif_target bifInput)
    set(target "")
    get_filename_component(bifInputBasename "${bifInput}" NAME)

    if ( "${ARGV1}" STREQUAL "standard" )
        set(bifcl_args "")
	set(target "bif-std-${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}")
        set(bifOutputs
            ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.func_def
            ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.func_h
            ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.func_init
            ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.netvar_def
            ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.netvar_h
            ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.netvar_init)
        set(BIF_OUTPUT_CC  ${bifInputBasename}.func_def
                           ${bifInputBasename}.func_init
                           ${bifInputBasename}.netvar_def
                           ${bifInputBasename}.netvar_init)
        set(BIF_OUTPUT_H   ${bifInputBasename}.func_h
                           ${bifInputBasename}.netvar_h)
        set(BIF_OUTPUT_BRO ${Zeek_BINARY_DIR}/scripts/base/bif/${bifInputBasename}.zeek)
        set(bro_BASE_BIF_SCRIPTS ${bro_BASE_BIF_SCRIPTS} ${BIF_OUTPUT_BRO} CACHE INTERNAL "Zeek script stubs for BIFs in base distribution of Zeek" FORCE) # Propogate to top-level

        # Do this here so that all of the necessary files for each individual BIF get added to clang-tidy
        add_clang_tidy_files(${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}.func_def)

    elseif ( "${ARGV1}" STREQUAL "plugin" )
        set(plugin_name ${ARGV2})
        set(plugin_name_canon ${ARGV3})
        set(plugin_is_static ${ARGV4})
        set(target "bif-plugin-${plugin_name_canon}-${bifInputBasename}")
        set(bifcl_args "-p;${plugin_name}")
        set(bifOutputs
            ${bifInputBasename}.h
            ${bifInputBasename}.cc
            ${bifInputBasename}.init.cc
            ${bifInputBasename}.register.cc)

        if ( plugin_is_static )
            set(BIF_OUTPUT_CC  ${bifInputBasename}.cc
                               ${bifInputBasename}.init.cc)
            set(bro_REGISTER_BIFS ${bro_REGISTER_BIFS} ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename} CACHE INTERNAL "BIFs for automatic registering" FORCE) # Propagate to top-level.
        else ()
            set(BIF_OUTPUT_CC  ${bifInputBasename}.cc
                               ${bifInputBasename}.init.cc
                               ${bifInputBasename}.register.cc)
        endif()

        # Do this here so that all of the necessary files for each individual BIF get added to clang-tidy
        foreach (bif_cc_file ${BIF_OUTPUT_CC})
            add_clang_tidy_files(${CMAKE_CURRENT_BINARY_DIR}/${bif_cc_file})
        endforeach(bif_cc_file)

        set(BIF_OUTPUT_H   ${bifInputBasename}.h)

        if ( NOT ZEEK_PLUGIN_BUILD_DYNAMIC )
            set(BIF_OUTPUT_BRO ${Zeek_BINARY_DIR}/scripts/base/bif/plugins/${plugin_name_canon}.${bifInputBasename}.zeek)
        else ()
            set(BIF_OUTPUT_BRO ${BRO_PLUGIN_BIF}/${bifInputBasename}.zeek)
        endif()

        set(bro_PLUGIN_BIF_SCRIPTS ${bro_PLUGIN_BIF_SCRIPTS} ${BIF_OUTPUT_BRO} CACHE INTERNAL "Zeek script stubs for BIFs in Zeek plugins" FORCE) # Propogate to top-level

    else ()
        # Alternative mode. These will get compiled in automatically.
        set(bifcl_args "-s")
        set(target "bif-alt-${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename}")
        set(bifOutputs
            ${bifInputBasename}.h
            ${bifInputBasename}.cc
            ${bifInputBasename}.init.cc)
        set(BIF_OUTPUT_CC  ${bifInputBasename}.cc)
        set(BIF_OUTPUT_H   ${bifInputBasename}.h)

        # Do this here so that all of the necessary files for each individual BIF get added to clang-tidy
        foreach (bif_cc_file ${BIF_OUTPUT_CC})
            add_clang_tidy_files(${CMAKE_CURRENT_BINARY_DIR}/${bif_cc_file})
        endforeach(bif_cc_file)

        # In order be able to run Zeek from the build directory, the
        # generated Zeek script needs to be inside a directory tree
        # named the same way it will be referenced from an @load.
	set(BIF_OUTPUT_BRO ${Zeek_BINARY_DIR}/scripts/base/bif/${bifInputBasename}.zeek)

        set(bro_AUTO_BIFS  ${bro_AUTO_BIFS} ${CMAKE_CURRENT_BINARY_DIR}/${bifInputBasename} CACHE INTERNAL "BIFs for automatic inclusion" FORCE) # Propagate to top-level.
        set(bro_BASE_BIF_SCRIPTS ${bro_BASE_BIF_SCRIPTS} ${BIF_OUTPUT_BRO} CACHE INTERNAL "Zeek script stubs for BIFs in base distribution of Zeek" FORCE) # Propogate to top-level

    endif ()

    if ( ZEEK_PLUGIN_INTERNAL_BUILD )
        if ( BIFCL_EXE_PATH )
            set(BifCl_EXE ${BIFCL_EXE_PATH})
        else ()
            set(BifCl_EXE "bifcl")
        endif ()
    else ()
        if ( NOT BifCl_EXE )
            if ( BRO_PLUGIN_BRO_BUILD )
                # Zeek 3.2+ has auxil/ instead of aux/
                if ( EXISTS "${BRO_PLUGIN_BRO_BUILD}/auxil" )
                    set(BifCl_EXE "${BRO_PLUGIN_BRO_BUILD}/auxil/bifcl/bifcl")
                else ()
                    set(BifCl_EXE "${BRO_PLUGIN_BRO_BUILD}/aux/bifcl/bifcl")
                endif ()
            else ()
                find_program(BifCl_EXE bifcl)

                if ( NOT BifCl_EXE )
                    message(FATAL_ERROR "Failed to find 'bifcl' program")
                endif ()
            endif ()
        endif ()
    endif ()

    set(bifclDep ${BifCl_EXE})

    add_custom_command(OUTPUT ${bifOutputs} ${BIF_OUTPUT_BRO}
                       COMMAND ${BifCl_EXE}
                       ARGS ${bifcl_args} ${CMAKE_CURRENT_SOURCE_DIR}/${bifInput} || (rm -f ${bifOutputs} && exit 1)
                       COMMAND "${CMAKE_COMMAND}"
                       ARGS -E copy ${bifInputBasename}.zeek ${BIF_OUTPUT_BRO}
                       COMMAND "${CMAKE_COMMAND}"
                       ARGS -E remove -f ${bifInputBasename}.zeek
                       DEPENDS ${bifInput}
                       DEPENDS ${bifclDep}
                       COMMENT "[BIFCL] Processing ${bifInput}"
    )

    # Make sure to escape a bunch of special characters in the path before trying to use it as a
    # regular expression below.
    string(REGEX REPLACE "([][+.*()^])" "\\\\\\1" escaped_path "${Zeek_BINARY_DIR}/src/")

    string(REGEX REPLACE "${escaped_path}" "" target "${target}")
    string(REGEX REPLACE "/" "-" target "${target}")
    string(REGEX REPLACE ":" "" target "${target}")
    add_custom_target(${target} DEPENDS ${BIF_OUTPUT_H} ${BIF_OUTPUT_CC})
    set_source_files_properties(${bifOutputs} PROPERTIES GENERATED 1)
    set(BIF_BUILD_TARGET ${target})

    set(bro_ALL_GENERATED_OUTPUTS ${bro_ALL_GENERATED_OUTPUTS} ${target} CACHE INTERNAL "automatically generated files" FORCE) # Propagate to top-level.
endmacro(bif_target)

# A macro to create a __load__.zeek file for all *.bif.zeek files in
# a given collection (which should all be in the same directory).
# It creates a corresponding target to trigger the generation.
function(bro_bif_create_loader target bifinputs)
    set(_bif_loader_dir "")

    foreach ( _bro_file ${bifinputs} )
        get_filename_component(_bif_loader_dir_tmp ${_bro_file} PATH)
        get_filename_component(_bro_file_name ${_bro_file} NAME)

        if ( _bif_loader_dir )
            if ( NOT _bif_loader_dir_tmp STREQUAL _bif_loader_dir )
                message(FATAL_ERROR "Directory of Zeek script BIF stub ${_bro_file} differs from expected: ${_bif_loader_dir}")
            endif ()
        else ()
            set(_bif_loader_dir ${_bif_loader_dir_tmp})
        endif ()

        set(_bif_loader_content "${_bif_loader_content} ${_bro_file_name}")
    endforeach ()

    if ( NOT _bif_loader_dir )
        return ()
    endif ()

    file(MAKE_DIRECTORY ${_bif_loader_dir})

    set(_bif_loader_file ${_bif_loader_dir}/__load__.zeek)
    add_custom_target(${target}
        COMMAND "sh" "-c" "rm -f ${_bif_loader_file}"
        COMMAND "sh" "-c" "for i in ${_bif_loader_content}; do echo @load ./$i >> ${_bif_loader_file}; done"
        WORKING_DIRECTORY ${_bif_loader_dir}
        VERBATIM
    )

     add_dependencies(${target} generate_outputs)
endfunction()

# A macro to create joint include files for compiling in all the
# autogenerated bif code.  Adds an empty target named ${target} (for
# compatibility) and creates ${dstdir}/__all__.bif.cc and
# ${dstdir}/__all__.bif.init.cc.
function(bro_bif_create_includes target dstdir bifinputs)
    add_custom_target(${target})
    bif_create_include(${dstdir} "" "${bifinputs}")
    bif_create_include(${dstdir} .init "${bifinputs}")
endfunction()

# Adds and empty target (for compatibility) and creates
# ${dstdir}/__all__.bif.register.cc.
function(bro_bif_create_register target dstdir bifinputs)
    add_custom_target(${target})
    bif_create_include(${dstdir} .register "${bifinputs}")
endfunction()

# Creates ${dstdir}/__all__.bif${suffix}.cc.
function(bif_create_include dstdir suffix bifinputs)
    set(dst ${dstdir}/__all__.bif${suffix}.cc)
    file(REMOVE ${dst}.tmp)
    foreach (b ${bifinputs})
        file(APPEND ${dst}.tmp "#include \"${b}${suffix}.cc\"\n")
    endforeach ()
    configure_file(${dst}.tmp ${dst} COPYONLY)
    file(REMOVE ${dst}.tmp)
endfunction()

repository: bro/cmake

repo_name: bro/cmake

extension: cmake


text:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE eagle SYSTEM "eagle.dtd">
<eagle version="8.2.2">
<drawing>
<settings>
<setting alwaysvectorfont="no"/>
<setting verticaltext="up"/>
</settings>
<grid distance="0.025" unitdist="inch" unit="inch" style="lines" multiple="4" display="yes" altdistance="0.005" altunitdist="inch" altunit="inch"/>
<layers>
<layer number="1" name="Top" color="4" fill="1" visible="yes" active="yes"/>
<layer number="2" name="Route2" color="1" fill="3" visible="no" active="no"/>
<layer number="3" name="Route3" color="4" fill="3" visible="no" active="no"/>
<layer number="4" name="Route4" color="1" fill="4" visible="no" active="no"/>
<layer number="5" name="Route5" color="4" fill="4" visible="no" active="no"/>
<layer number="6" name="Route6" color="1" fill="8" visible="no" active="no"/>
<layer number="7" name="Route7" color="4" fill="8" visible="no" active="no"/>
<layer number="8" name="Route8" color="1" fill="2" visible="no" active="no"/>
<layer number="9" name="Route9" color="4" fill="2" visible="no" active="no"/>
<layer number="10" name="Route10" color="1" fill="7" visible="no" active="no"/>
<layer number="11" name="Route11" color="4" fill="7" visible="no" active="no"/>
<layer number="12" name="Route12" color="1" fill="5" visible="no" active="no"/>
<layer number="13" name="Route13" color="4" fill="5" visible="no" active="no"/>
<layer number="14" name="Route14" color="1" fill="6" visible="no" active="no"/>
<layer number="15" name="Route15" color="4" fill="6" visible="no" active="no"/>
<layer number="16" name="Bottom" color="1" fill="1" visible="no" active="yes"/>
<layer number="17" name="Pads" color="2" fill="1" visible="yes" active="yes"/>
<layer number="18" name="Vias" color="2" fill="1" visible="yes" active="yes"/>
<layer number="19" name="Unrouted" color="6" fill="1" visible="yes" active="yes"/>
<layer number="20" name="Dimension" color="15" fill="1" visible="yes" active="yes"/>
<layer number="21" name="tPlace" color="7" fill="1" visible="no" active="yes"/>
<layer number="22" name="bPlace" color="7" fill="1" visible="no" active="yes"/>
<layer number="23" name="tOrigins" color="15" fill="1" visible="yes" active="yes"/>
<layer number="24" name="bOrigins" color="15" fill="1" visible="no" active="yes"/>
<layer number="25" name="tNames" color="7" fill="1" visible="yes" active="yes"/>
<layer number="26" name="bNames" color="7" fill="1" visible="no" active="yes"/>
<layer number="27" name="tValues" color="7" fill="1" visible="yes" active="yes"/>
<layer number="28" name="bValues" color="7" fill="1" visible="no" active="yes"/>
<layer number="29" name="tStop" color="7" fill="3" visible="no" active="yes"/>
<layer number="30" name="bStop" color="7" fill="6" visible="no" active="yes"/>
<layer number="31" name="tCream" color="7" fill="4" visible="no" active="yes"/>
<layer number="32" name="bCream" color="7" fill="5" visible="no" active="yes"/>
<layer number="33" name="tFinish" color="6" fill="3" visible="no" active="yes"/>
<layer number="34" name="bFinish" color="6" fill="6" visible="no" active="yes"/>
<layer number="35" name="tGlue" color="7" fill="4" visible="no" active="yes"/>
<layer number="36" name="bGlue" color="7" fill="5" visible="no" active="yes"/>
<layer number="37" name="tTest" color="7" fill="1" visible="no" active="yes"/>
<layer number="38" name="bTest" color="7" fill="1" visible="no" active="yes"/>
<layer number="39" name="tKeepout" color="4" fill="11" visible="no" active="yes"/>
<layer number="40" name="bKeepout" color="1" fill="11" visible="no" active="yes"/>
<layer number="41" name="tRestrict" color="4" fill="10" visible="no" active="yes"/>
<layer number="42" name="bRestrict" color="1" fill="10" visible="no" active="yes"/>
<layer number="43" name="vRestrict" color="2" fill="10" visible="no" active="yes"/>
<layer number="44" name="Drills" color="7" fill="1" visible="no" active="yes"/>
<layer number="45" name="Holes" color="7" fill="1" visible="no" active="yes"/>
<layer number="46" name="Milling" color="3" fill="1" visible="no" active="yes"/>
<layer number="47" name="Measures" color="7" fill="1" visible="no" active="yes"/>
<layer number="48" name="Document" color="7" fill="1" visible="no" active="yes"/>
<layer number="49" name="Reference" color="7" fill="1" visible="no" active="yes"/>
<layer number="50" name="dxf" color="7" fill="1" visible="no" active="no"/>
<layer number="51" name="tDocu" color="7" fill="1" visible="yes" active="yes"/>
<layer number="52" name="bDocu" color="7" fill="1" visible="no" active="yes"/>
<layer number="53" name="tGND_GNDA" color="7" fill="9" visible="no" active="no"/>
<layer number="54" name="bGND_GNDA" color="1" fill="9" visible="no" active="no"/>
<layer number="56" name="wert" color="7" fill="1" visible="no" active="no"/>
<layer number="57" name="tCAD" color="7" fill="1" visible="no" active="no"/>
<layer number="59" name="tCarbon" color="7" fill="1" visible="no" active="no"/>
<layer number="60" name="bCarbon" color="7" fill="1" visible="no" active="no"/>
<layer number="90" name="Modules" color="5" fill="1" visible="no" active="no"/>
<layer number="91" name="Nets" color="2" fill="1" visible="no" active="no"/>
<layer number="92" name="Busses" color="1" fill="1" visible="no" active="no"/>
<layer number="93" name="Pins" color="2" fill="1" visible="no" active="no"/>
<layer number="94" name="Symbols" color="4" fill="1" visible="no" active="no"/>
<layer number="95" name="Names" color="7" fill="1" visible="no" active="no"/>
<layer number="96" name="Values" color="7" fill="1" visible="no" active="no"/>
<layer number="97" name="Info" color="7" fill="1" visible="no" active="no"/>
<layer number="98" name="Guide" color="6" fill="1" visible="no" active="no"/>
<layer number="99" name="SpiceOrder" color="7" fill="1" visible="no" active="no"/>
<layer number="100" name="Muster" color="7" fill="1" visible="no" active="no"/>
<layer number="101" name="Patch_Top" color="12" fill="4" visible="no" active="yes"/>
<layer number="102" name="Vscore" color="7" fill="1" visible="no" active="yes"/>
<layer number="103" name="tMap" color="7" fill="1" visible="no" active="yes"/>
<layer number="104" name="Name" color="7" fill="1" visible="no" active="yes"/>
<layer number="105" name="tPlate" color="7" fill="1" visible="no" active="yes"/>
<layer number="106" name="bPlate" color="7" fill="1" visible="no" active="yes"/>
<layer number="107" name="Crop" color="7" fill="1" visible="no" active="yes"/>
<layer number="108" name="tplace-old" color="10" fill="1" visible="no" active="yes"/>
<layer number="109" name="ref-old" color="11" fill="1" visible="no" active="yes"/>
<layer number="110" name="fp0" color="7" fill="1" visible="no" active="yes"/>
<layer number="111" name="LPC17xx" color="7" fill="1" visible="no" active="yes"/>
<layer number="112" name="tSilk" color="7" fill="1" visible="no" active="yes"/>
<layer number="113" name="IDFDebug" color="7" fill="1" visible="no" active="yes"/>
<layer number="114" name="Badge_Outline" color="7" fill="1" visible="no" active="yes"/>
<layer number="115" name="ReferenceISLANDS" color="7" fill="1" visible="no" active="yes"/>
<layer number="116" name="Patch_BOT" color="9" fill="4" visible="no" active="yes"/>
<layer number="118" name="Rect_Pads" color="7" fill="1" visible="no" active="yes"/>
<layer number="121" name="_tsilk" color="7" fill="1" visible="no" active="yes"/>
<layer number="122" name="_bsilk" color="7" fill="1" visible="no" active="yes"/>
<layer number="123" name="tTestmark" color="7" fill="1" visible="no" active="yes"/>
<layer number="124" name="bTestmark" color="7" fill="1" visible="no" active="yes"/>
<layer number="125" name="_tNames" color="7" fill="1" visible="no" active="yes"/>
<layer number="126" name="_bNames" color="7" fill="1" visible="no" active="yes"/>
<layer number="127" name="_tValues" color="7" fill="1" visible="no" active="yes"/>
<layer number="128" name="_bValues" color="7" fill="1" visible="no" active="yes"/>
<layer number="129" name="Mask" color="7" fill="1" visible="no" active="yes"/>
<layer number="131" name="tAdjust" color="7" fill="1" visible="no" active="yes"/>
<layer number="132" name="bAdjust" color="7" fill="1" visible="no" active="yes"/>
<layer number="144" name="Drill_legend" color="7" fill="1" visible="no" active="yes"/>
<layer number="150" name="Notes" color="7" fill="1" visible="no" active="yes"/>
<layer number="151" name="HeatSink" color="7" fill="1" visible="no" active="yes"/>
<layer number="152" name="_bDocu" color="7" fill="1" visible="no" active="yes"/>
<layer number="153" name="FabDoc1" color="7" fill="1" visible="no" active="yes"/>
<layer number="154" name="FabDoc2" color="7" fill="1" visible="no" active="yes"/>
<layer number="155" name="FabDoc3" color="7" fill="1" visible="no" active="yes"/>
<layer number="199" name="Contour" color="7" fill="1" visible="no" active="yes"/>
<layer number="200" name="200bmp" color="1" fill="10" visible="no" active="yes"/>
<layer number="201" name="201bmp" color="2" fill="10" visible="no" active="yes"/>
<layer number="202" name="202bmp" color="3" fill="10" visible="no" active="yes"/>
<layer number="203" name="203bmp" color="4" fill="10" visible="no" active="yes"/>
<layer number="204" name="204bmp" color="5" fill="10" visible="no" active="yes"/>
<layer number="205" name="205bmp" color="6" fill="10" visible="no" active="yes"/>
<layer number="206" name="206bmp" color="7" fill="10" visible="no" active="yes"/>
<layer number="207" name="207bmp" color="8" fill="10" visible="no" active="yes"/>
<layer number="208" name="208bmp" color="9" fill="10" visible="no" active="yes"/>
<layer number="209" name="209bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="210" name="210bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="211" name="211bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="212" name="212bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="213" name="213bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="214" name="214bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="215" name="215bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="216" name="216bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="217" name="217bmp" color="18" fill="1" visible="no" active="no"/>
<layer number="218" name="218bmp" color="19" fill="1" visible="no" active="no"/>
<layer number="219" name="219bmp" color="20" fill="1" visible="no" active="no"/>
<layer number="220" name="220bmp" color="21" fill="1" visible="no" active="no"/>
<layer number="221" name="221bmp" color="22" fill="1" visible="no" active="no"/>
<layer number="222" name="222bmp" color="23" fill="1" visible="no" active="no"/>
<layer number="223" name="223bmp" color="24" fill="1" visible="no" active="no"/>
<layer number="224" name="224bmp" color="25" fill="1" visible="no" active="no"/>
<layer number="225" name="225bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="226" name="226bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="227" name="227bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="228" name="228bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="229" name="229bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="230" name="230bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="231" name="231bmp" color="7" fill="1" visible="no" active="yes"/>
<layer number="248" name="Housing" color="7" fill="1" visible="no" active="yes"/>
<layer number="249" name="Edge" color="7" fill="1" visible="no" active="yes"/>
<layer number="250" name="Descript" color="3" fill="1" visible="no" active="no"/>
<layer number="251" name="SMDround" color="12" fill="11" visible="no" active="no"/>
<layer number="254" name="cooling" color="7" fill="1" visible="no" active="yes"/>
<layer number="255" name="routoute" color="7" fill="1" visible="no" active="yes"/>
</layers>
<board>
<plain>
<wire x1="0" y1="0" x2="50.526" y2="0" width="0.8128" layer="20"/>
<wire x1="50.526" y1="0" x2="50.526" y2="28.118" width="0.8128" layer="20"/>
<wire x1="50.526" y1="28.118" x2="0" y2="28.118" width="0.8128" layer="20"/>
<wire x1="0" y1="28.118" x2="0" y2="0" width="0.8128" layer="20"/>
<text x="2.286" y="23.114" size="1.778" layer="1" font="vector">Fab FTDI</text>
<text x="23.368" y="7.62" size="1.016" layer="27">12 MHz</text>
<text x="17.653" y="24.511" size="1.016" layer="27">5V</text>
<text x="25.4" y="20.066" size="1.016" layer="27">3V</text>
</plain>
<libraries>
<library name="00fab">
<packages>
<package name="C1206FAB">
<wire x1="-2.032" y1="1.016" x2="2.032" y2="1.016" width="0.127" layer="21"/>
<wire x1="2.032" y1="1.016" x2="2.032" y2="-1.016" width="0.127" layer="21"/>
<wire x1="2.032" y1="-1.016" x2="-2.032" y2="-1.016" width="0.127" layer="21"/>
<wire x1="-2.032" y1="-1.016" x2="-2.032" y2="1.016" width="0.127" layer="21"/>
<smd name="1" x="-1.651" y="0" dx="1.27" dy="1.905" layer="1"/>
<smd name="2" x="1.651" y="0" dx="1.27" dy="1.905" layer="1"/>
<text x="-1.778" y="1.27" size="1.016" layer="25" ratio="15">>NAME</text>
<text x="-1.778" y="-2.286" size="1.016" layer="27" ratio="15">>VALUE</text>
</package>
<package name="SOD123">
<description><b>SMALL OUTLINE DIODE</b></description>
<wire x1="-2.973" y1="0.983" x2="2.973" y2="0.983" width="0.0508" layer="39"/>
<wire x1="2.973" y1="-0.983" x2="-2.973" y2="-0.983" width="0.0508" layer="39"/>
<wire x1="-2.973" y1="-0.983" x2="-2.973" y2="0.983" width="0.0508" layer="39"/>
<wire x1="2.973" y1="0.983" x2="2.973" y2="-0.983" width="0.0508" layer="39"/>
<wire x1="-1.321" y1="0.787" x2="1.321" y2="0.787" width="0.1016" layer="51"/>
<wire x1="-1.321" y1="-0.787" x2="1.321" y2="-0.787" width="0.1016" layer="51"/>
<wire x1="-1.321" y1="-0.787" x2="-1.321" y2="0.787" width="0.1016" layer="51"/>
<wire x1="1.321" y1="-0.787" x2="1.321" y2="0.787" width="0.1016" layer="51"/>
<wire x1="-1" y1="0" x2="0" y2="0.5" width="0.2032" layer="51"/>
<wire x1="0" y1="0.5" x2="0" y2="-0.5" width="0.2032" layer="51"/>
<wire x1="0" y1="-0.5" x2="-1" y2="0" width="0.2032" layer="51"/>
<wire x1="-1" y1="0.5" x2="-1" y2="0" width="0.2032" layer="51"/>
<wire x1="-1" y1="0" x2="-1" y2="-0.5" width="0.2032" layer="51"/>
<smd name="CATHODE" x="-1.7" y="0" dx="1.6" dy="0.8" layer="1"/>
<smd name="ANODE" x="1.7" y="0" dx="1.6" dy="0.8" layer="1"/>
<text x="-1.905" y="1.905" size="1.27" layer="25">>NAME</text>
<text x="-1.905" y="-3.175" size="1.27" layer="27">>VALUE</text>
<rectangle x1="-1.9558" y1="-0.3048" x2="-1.3716" y2="0.3048" layer="51" rot="R180"/>
<rectangle x1="1.3716" y1="-0.3048" x2="1.9558" y2="0.3048" layer="51" rot="R180"/>
<rectangle x1="-0.4001" y1="-0.7" x2="0.4001" y2="0.7" layer="35"/>
</package>
<package name="1X06SMD">
<smd name="1" x="0" y="6.35" dx="2.54" dy="1.27" layer="1"/>
<smd name="2" x="0" y="3.81" dx="2.54" dy="1.27" layer="1"/>
<smd name="3" x="0" y="1.27" dx="2.54" dy="1.27" layer="1"/>
<smd name="4" x="0" y="-1.27" dx="2.54" dy="1.27" layer="1"/>
<smd name="5" x="0" y="-3.81" dx="2.54" dy="1.27" layer="1"/>
<smd name="6" x="0" y="-6.35" dx="2.54" dy="1.27" layer="1"/>
<text x="-1.905" y="-3.175" size="1.27" layer="25" rot="R90">>NAME</text>
</package>
<package name="USB_MINIB">
<wire x1="-0.03" y1="3.8" x2="2.07" y2="3.8" width="0.2032" layer="21"/>
<wire x1="4.57" y1="3.1" x2="4.57" y2="2.2" width="0.2032" layer="21"/>
<wire x1="4.57" y1="-2.2" x2="4.57" y2="-3.1" width="0.2032" layer="21"/>
<wire x1="2.07" y1="-3.8" x2="-0.03" y2="-3.8" width="0.2032" layer="21"/>
<wire x1="-4.63" y1="3.8" x2="-4.63" y2="-3.8" width="0.2032" layer="51"/>
<wire x1="-4.63" y1="-3.8" x2="-3.23" y2="-3.8" width="0.2032" layer="51"/>
<wire x1="-4.63" y1="3.8" x2="-3.23" y2="3.8" width="0.2032" layer="51"/>
<smd name="D+" x="3.77" y="0" dx="2.5" dy="0.35" layer="1"/>
<smd name="D-" x="3.77" y="0.8" dx="2.5" dy="0.35" layer="1"/>
<smd name="GND" x="3.77" y="-1.6" dx="2.5" dy="0.35" layer="1"/>
<smd name="ID" x="3.77" y="-0.8" dx="2.5" dy="0.35" layer="1"/>
<smd name="SHIELD@1" x="-1.73" y="-4.5" dx="2.5" dy="2" layer="1"/>
<smd name="SHIELD@2" x="-1.73" y="4.5" dx="2.5" dy="2" layer="1"/>
<smd name="SHIELD@4" x="3.77" y="-4.5" dx="2.5" dy="2" layer="1"/>
<smd name="SHIELD@3" x="3.77" y="4.5" dx="2.5" dy="2" layer="1"/>
<smd name="VBUS" x="3.77" y="1.6" dx="2.5" dy="0.35" layer="1"/>
<text x="-2.54" y="1.27" size="0.4064" layer="25">>NAME</text>
<text x="-2.54" y="0" size="0.4064" layer="27">>VALUE</text>
</package>
<package name="SOIC16">
<wire x1="-4.267" y1="-1.791" x2="5.537" y2="-1.791" width="0.1524" layer="51"/>
<wire x1="5.537" y1="-1.791" x2="5.537" y2="1.791" width="0.1524" layer="21"/>
<wire x1="5.537" y1="1.791" x2="-4.267" y2="1.791" width="0.1524" layer="51"/>
<wire x1="-4.267" y1="1.791" x2="-4.267" y2="-1.791" width="0.1524" layer="21"/>
<circle x="-3.5052" y="-0.7747" radius="0.5334" width="0.1524" layer="21"/>
<smd name="1" x="-3.81" y="-2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="16" x="-3.81" y="2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="2" x="-2.54" y="-2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="3" x="-1.27" y="-2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="15" x="-2.54" y="2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="14" x="-1.27" y="2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="4" x="0" y="-2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="13" x="0" y="2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="5" x="1.27" y="-2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="6" x="2.54" y="-2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="12" x="1.27" y="2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="11" x="2.54" y="2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="7" x="3.81" y="-2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="10" x="3.81" y="2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<text x="-4.5085" y="-2.032" size="1.27" layer="25" ratio="10" rot="R90">>NAME</text>
<text x="-2.54" y="-0.6985" size="1.27" layer="27" ratio="10">>VALUE</text>
<rectangle x1="-3.9878" y1="1.8415" x2="-3.6322" y2="2.8575" layer="51"/>
<rectangle x1="-2.7178" y1="1.8415" x2="-2.3622" y2="2.8575" layer="51"/>
<rectangle x1="-1.4478" y1="1.8415" x2="-1.0922" y2="2.8575" layer="51"/>
<rectangle x1="-0.1778" y1="1.8415" x2="0.1778" y2="2.8575" layer="51"/>
<rectangle x1="1.0922" y1="1.8415" x2="1.4478" y2="2.8575" layer="51"/>
<rectangle x1="2.3622" y1="1.8415" x2="2.7178" y2="2.8575" layer="51"/>
<rectangle x1="3.6322" y1="1.8415" x2="3.9878" y2="2.8575" layer="51"/>
<rectangle x1="3.6322" y1="-2.8575" x2="3.9878" y2="-1.8415" layer="51"/>
<rectangle x1="2.3622" y1="-2.8575" x2="2.7178" y2="-1.8415" layer="51"/>
<rectangle x1="1.0922" y1="-2.8575" x2="1.4478" y2="-1.8415" layer="51"/>
<rectangle x1="-0.1778" y1="-2.8575" x2="0.1778" y2="-1.8415" layer="51"/>
<rectangle x1="-1.4478" y1="-2.8575" x2="-1.0922" y2="-1.8415" layer="51"/>
<rectangle x1="-2.7178" y1="-2.8575" x2="-2.3622" y2="-1.8415" layer="51"/>
<rectangle x1="-3.9878" y1="-2.8575" x2="-3.6322" y2="-1.8415" layer="51"/>
<rectangle x1="4.9022" y1="-2.8575" x2="5.2578" y2="-1.8415" layer="51"/>
<smd name="8" x="5.08" y="-2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<smd name="9" x="5.08" y="2.6035" dx="0.6096" dy="2.2098" layer="1"/>
<rectangle x1="3.6322" y1="1.8415" x2="3.9878" y2="2.8575" layer="51"/>
<rectangle x1="4.9022" y1="1.8415" x2="5.2578" y2="2.8575" layer="51"/>
</package>
<package name="R1206FAB">
<wire x1="-2.032" y1="1.016" x2="2.032" y2="1.016" width="0.127" layer="21"/>
<wire x1="2.032" y1="1.016" x2="2.032" y2="-1.016" width="0.127" layer="21"/>
<wire x1="2.032" y1="-1.016" x2="-2.032" y2="-1.016" width="0.127" layer="21"/>
<wire x1="-2.032" y1="-1.016" x2="-2.032" y2="1.016" width="0.127" layer="21"/>
<smd name="1" x="-1.651" y="0" dx="1.27" dy="1.905" layer="1"/>
<smd name="2" x="1.651" y="0" dx="1.27" dy="1.905" layer="1"/>
<text x="-1.778" y="1.27" size="1.016" layer="25" ratio="15">>NAME</text>
<text x="-1.778" y="-2.286" size="1.016" layer="27" ratio="15">>VALUE</text>
</package>
</packages>
</library>
<library name="pinhead" urn="urn:adsk.eagle:library:325">
<description><b>Pin Header Connectors</b><p>
<author>Created by librarian@cadsoft.de</author></description>
<packages>
<package name="1X03" library_version="1">
<description><b>PIN HEADER</b></description>
<wire x1="-3.175" y1="1.27" x2="-1.905" y2="1.27" width="0.1524" layer="21"/>
<wire x1="-1.905" y1="1.27" x2="-1.27" y2="0.635" width="0.1524" layer="21"/>
<wire x1="-1.27" y1="0.635" x2="-1.27" y2="-0.635" width="0.1524" layer="21"/>
<wire x1="-1.27" y1="-0.635" x2="-1.905" y2="-1.27" width="0.1524" layer="21"/>
<wire x1="-1.27" y1="0.635" x2="-0.635" y2="1.27" width="0.1524" layer="21"/>
<wire x1="-0.635" y1="1.27" x2="0.635" y2="1.27" width="0.1524" layer="21"/>
<wire x1="0.635" y1="1.27" x2="1.27" y2="0.635" width="0.1524" layer="21"/>
<wire x1="1.27" y1="0.635" x2="1.27" y2="-0.635" width="0.1524" layer="21"/>
<wire x1="1.27" y1="-0.635" x2="0.635" y2="-1.27" width="0.1524" layer="21"/>
<wire x1="0.635" y1="-1.27" x2="-0.635" y2="-1.27" width="0.1524" layer="21"/>
<wire x1="-0.635" y1="-1.27" x2="-1.27" y2="-0.635" width="0.1524" layer="21"/>
<wire x1="-3.81" y1="0.635" x2="-3.81" y2="-0.635" width="0.1524" layer="21"/>
<wire x1="-3.175" y1="1.27" x2="-3.81" y2="0.635" width="0.1524" layer="21"/>
<wire x1="-3.81" y1="-0.635" x2="-3.175" y2="-1.27" width="0.1524" layer="21"/>
<wire x1="-1.905" y1="-1.27" x2="-3.175" y2="-1.27" width="0.1524" layer="21"/>
<wire x1="1.27" y1="0.635" x2="1.905" y2="1.27" width="0.1524" layer="21"/>
<wire x1="1.905" y1="1.27" x2="3.175" y2="1.27" width="0.1524" layer="21"/>
<wire x1="3.175" y1="1.27" x2="3.81" y2="0.635" width="0.1524" layer="21"/>
<wire x1="3.81" y1="0.635" x2="3.81" y2="-0.635" width="0.1524" layer="21"/>
<wire x1="3.81" y1="-0.635" x2="3.175" y2="-1.27" width="0.1524" layer="21"/>
<wire x1="3.175" y1="-1.27" x2="1.905" y2="-1.27" width="0.1524" layer="21"/>
<wire x1="1.905" y1="-1.27" x2="1.27" y2="-0.635" width="0.1524" layer="21"/>
<pad name="1" x="-2.54" y="0" drill="1.016" shape="long" rot="R90"/>
<pad name="2" x="0" y="0" drill="1.016" shape="long" rot="R90"/>
<pad name="3" x="2.54" y="0" drill="1.016" shape="long" rot="R90"/>
<text x="-3.8862" y="1.8288" size="1.27" layer="25" ratio="10">>NAME</text>
<text x="-3.81" y="-3.175" size="1.27" layer="27">>VALUE</text>
<rectangle x1="-0.254" y1="-0.254" x2="0.254" y2="0.254" layer="51"/>
<rectangle x1="-2.794" y1="-0.254" x2="-2.286" y2="0.254" layer="51"/>
<rectangle x1="2.286" y1="-0.254" x2="2.794" y2="0.254" layer="51"/>
</package>
</packages>
</library>
<library name="SparkFun-FreqCtrl">
<description><h3>SparkFun Electronics' preferred foot prints</h3>
In this library you'll find crystals and oscillators and other things that go "tick".<br><br>
We've spent an enormous amount of time creating and checking these footprints and parts, but it is the end user's responsibility to ensure correctness and suitablity for a given componet or application. If you enjoy using this library, please buy one of our products at www.sparkfun.com.
<br><br>
<b>Licensing:</b> Creative Commons ShareAlike 4.0 International - https://creativecommons.org/licenses/by-sa/4.0/
<br><br>
You are welcome to use this library for commercial purposes. For attribution, we ask that when you begin to sell your device using our footprint, you email us with a link to the product being sold. We want bragging rights that we helped (in a very small part) to create your 8th world wonder. We would like the opportunity to feature your device on our homepage.</description>
<packages>
<package name="CRYSTAL-SMD-10.5X4.8-2PIN">
<wire x1="-6.2" y1="1.5" x2="-6.2" y2="2.4" width="0.127" layer="21"/>
<wire x1="-6.2" y1="2.4" x2="6.2" y2="2.4" width="0.127" layer="21"/>
<wire x1="6.2" y1="2.4" x2="6.2" y2="1.5" width="0.127" layer="21"/>
<wire x1="-6.2" y1="-1.5" x2="-6.2" y2="-2.4" width="0.127" layer="21"/>
<wire x1="-6.2" y1="-2.4" x2="6.2" y2="-2.4" width="0.127" layer="21"/>
<wire x1="6.2" y1="-2.4" x2="6.2" y2="-1.5" width="0.127" layer="21"/>
<smd name="P$1" x="-4.3" y="0" dx="5.5" dy="1.5" layer="1"/>
<smd name="P$2" x="4.3" y="0" dx="5.5" dy="1.5" layer="1"/>
</package>
</packages>
</library>
</libraries>
<attributes>
</attributes>
<variantdefs>
</variantdefs>
<classes>
<class number="0" name="default" width="0" drill="0">
</class>
</classes>
<designrules name="default *">
<description language="de"><b>EAGLE Design Rules</b>
<p>
Die Standard-Design-Rules sind so gewählt, dass sie für
die meisten Anwendungen passen. Sollte ihre Platine
besondere Anforderungen haben, treffen Sie die erforderlichen
Einstellungen hier und speichern die Design Rules unter
einem neuen Namen ab.</description>
<description language="en"><b>EAGLE Design Rules</b>
<p>
The default Design Rules have been set to cover
a wide range of applications. Your particular design
may have different requirements, so please make the
necessary adjustments and save your customized
design rules under a new name.</description>
<param name="layerSetup" value="(1*16)"/>
<param name="mtCopper" value="0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm 0.035mm"/>
<param name="mtIsolate" value="1.5mm 0.15mm 0.2mm 0.15mm 0.2mm 0.15mm 0.2mm 0.15mm 0.2mm 0.15mm 0.2mm 0.15mm 0.2mm 0.15mm 0.2mm"/>
<param name="mdWireWire" value="10mil"/>
<param name="mdWirePad" value="10mil"/>
<param name="mdWireVia" value="8mil"/>
<param name="mdPadPad" value="10mil"/>
<param name="mdPadVia" value="8mil"/>
<param name="mdViaVia" value="8mil"/>
<param name="mdSmdPad" value="8mil"/>
<param name="mdSmdVia" value="8mil"/>
<param name="mdSmdSmd" value="8mil"/>
<param name="mdViaViaSameLayer" value="6mil"/>
<param name="mnLayersViaInSmd" value="2"/>
<param name="mdCopperDimension" value="40mil"/>
<param name="mdDrill" value="6mil"/>
<param name="mdSmdStop" value="0mil"/>
<param name="msWidth" value="6mil"/>
<param name="msDrill" value="0.35mm"/>
<param name="msMicroVia" value="9.99mm"/>
<param name="msBlindViaRatio" value="0.5"/>
<param name="rvPadTop" value="0.25"/>
<param name="rvPadInner" value="0.25"/>
<param name="rvPadBottom" value="0.25"/>
<param name="rvViaOuter" value="0.25"/>
<param name="rvViaInner" value="0.25"/>
<param name="rvMicroViaOuter" value="0.25"/>
<param name="rvMicroViaInner" value="0.25"/>
<param name="rlMinPadTop" value="10mil"/>
<param name="rlMaxPadTop" value="20mil"/>
<param name="rlMinPadInner" value="10mil"/>
<param name="rlMaxPadInner" value="20mil"/>
<param name="rlMinPadBottom" value="10mil"/>
<param name="rlMaxPadBottom" value="20mil"/>
<param name="rlMinViaOuter" value="8mil"/>
<param name="rlMaxViaOuter" value="20mil"/>
<param name="rlMinViaInner" value="8mil"/>
<param name="rlMaxViaInner" value="20mil"/>
<param name="rlMinMicroViaOuter" value="4mil"/>
<param name="rlMaxMicroViaOuter" value="20mil"/>
<param name="rlMinMicroViaInner" value="4mil"/>
<param name="rlMaxMicroViaInner" value="20mil"/>
<param name="psTop" value="-1"/>
<param name="psBottom" value="-1"/>
<param name="psFirst" value="-1"/>
<param name="psElongationLong" value="100"/>
<param name="psElongationOffset" value="100"/>
<param name="mvStopFrame" value="1"/>
<param name="mvCreamFrame" value="0"/>
<param name="mlMinStopFrame" value="4mil"/>
<param name="mlMaxStopFrame" value="4mil"/>
<param name="mlMinCreamFrame" value="0mil"/>
<param name="mlMaxCreamFrame" value="0mil"/>
<param name="mlViaStopLimit" value="0mil"/>
<param name="srRoundness" value="0"/>
<param name="srMinRoundness" value="0mil"/>
<param name="srMaxRoundness" value="0mil"/>
<param name="slThermalIsolate" value="10mil"/>
<param name="slThermalsForVias" value="0"/>
<param name="dpMaxLengthDifference" value="10mm"/>
<param name="dpGapFactor" value="2.5"/>
<param name="checkGrid" value="0"/>
<param name="checkAngle" value="0"/>
<param name="checkFont" value="1"/>
<param name="checkRestrict" value="1"/>
<param name="useDiameter" value="13"/>
<param name="maxErrors" value="50"/>
</designrules>
<autorouter>
<pass name="Default">
<param name="RoutingGrid" value="50mil"/>
<param name="AutoGrid" value="1"/>
<param name="Efforts" value="0"/>
<param name="TopRouterVariant" value="1"/>
<param name="tpViaShape" value="round"/>
<param name="PrefDir.1" value="a"/>
<param name="PrefDir.2" value="0"/>
<param name="PrefDir.3" value="0"/>
<param name="PrefDir.4" value="0"/>
<param name="PrefDir.5" value="0"/>
<param name="PrefDir.6" value="0"/>
<param name="PrefDir.7" value="0"/>
<param name="PrefDir.8" value="0"/>
<param name="PrefDir.9" value="0"/>
<param name="PrefDir.10" value="0"/>
<param name="PrefDir.11" value="0"/>
<param name="PrefDir.12" value="0"/>
<param name="PrefDir.13" value="0"/>
<param name="PrefDir.14" value="0"/>
<param name="PrefDir.15" value="0"/>
<param name="PrefDir.16" value="0"/>
<param name="cfVia" value="8"/>
<param name="cfNonPref" value="5"/>
<param name="cfChangeDir" value="2"/>
<param name="cfOrthStep" value="2"/>
<param name="cfDiagStep" value="3"/>
<param name="cfExtdStep" value="0"/>
<param name="cfBonusStep" value="1"/>
<param name="cfMalusStep" value="1"/>
<param name="cfPadImpact" value="4"/>
<param name="cfSmdImpact" value="4"/>
<param name="cfBusImpact" value="0"/>
<param name="cfHugging" value="3"/>
<param name="cfAvoid" value="4"/>
<param name="cfPolygon" value="10"/>
<param name="cfBase.1" value="0"/>
<param name="cfBase.2" value="1"/>
<param name="cfBase.3" value="1"/>
<param name="cfBase.4" value="1"/>
<param name="cfBase.5" value="1"/>
<param name="cfBase.6" value="1"/>
<param name="cfBase.7" value="1"/>
<param name="cfBase.8" value="1"/>
<param name="cfBase.9" value="1"/>
<param name="cfBase.10" value="1"/>
<param name="cfBase.11" value="1"/>
<param name="cfBase.12" value="1"/>
<param name="cfBase.13" value="1"/>
<param name="cfBase.14" value="1"/>
<param name="cfBase.15" value="1"/>
<param name="cfBase.16" value="0"/>
<param name="mnVias" value="20"/>
<param name="mnSegments" value="9999"/>
<param name="mnExtdSteps" value="9999"/>
<param name="mnRipupLevel" value="10"/>
<param name="mnRipupSteps" value="100"/>
<param name="mnRipupTotal" value="100"/>
</pass>
<pass name="Follow-me" refer="Default" active="yes">
</pass>
<pass name="Busses" refer="Default" active="yes">
<param name="cfNonPref" value="4"/>
<param name="cfBusImpact" value="4"/>
<param name="cfHugging" value="0"/>
<param name="mnVias" value="0"/>
</pass>
<pass name="Route" refer="Default" active="yes">
</pass>
<pass name="Optimize1" refer="Default" active="yes">
<param name="cfVia" value="99"/>
<param name="cfExtdStep" value="10"/>
<param name="cfHugging" value="1"/>
<param name="mnExtdSteps" value="1"/>
<param name="mnRipupLevel" value="0"/>
</pass>
<pass name="Optimize2" refer="Optimize1" active="yes">
<param name="cfNonPref" value="0"/>
<param name="cfChangeDir" value="6"/>
<param name="cfExtdStep" value="0"/>
<param name="cfBonusStep" value="2"/>
<param name="cfMalusStep" value="2"/>
<param name="cfPadImpact" value="2"/>
<param name="cfSmdImpact" value="2"/>
<param name="cfHugging" value="0"/>
</pass>
<pass name="Optimize3" refer="Optimize2" active="yes">
<param name="cfChangeDir" value="8"/>
<param name="cfPadImpact" value="0"/>
<param name="cfSmdImpact" value="0"/>
</pass>
<pass name="Optimize4" refer="Optimize3" active="yes">
<param name="cfChangeDir" value="25"/>
</pass>
</autorouter>
<elements>
<element name="C1" library="00fab" package="C1206FAB" value="10u" x="13.716" y="13.97" smashed="yes" rot="R270">
<attribute name="NAME" x="12.319" y="10.287" size="1.016" layer="25" ratio="15" rot="R90"/>
<attribute name="VALUE" x="11.43" y="17.018" size="1.016" layer="27" ratio="15" rot="R270"/>
</element>
<element name="C2" library="00fab" package="C1206FAB" value="10n" x="24.765" y="11.938" rot="R270"/>
<element name="C3" library="00fab" package="C1206FAB" value="22p" x="16.256" y="4.826"/>
<element name="C4" library="00fab" package="C1206FAB" value="22p" x="36.449" y="4.826" smashed="yes" rot="R180">
<attribute name="NAME" x="35.687" y="7.366" size="1.016" layer="25" ratio="15" rot="R180"/>
<attribute name="VALUE" x="38.227" y="3.302" size="1.016" layer="27" ratio="15" rot="R180"/>
</element>
<element name="D1" library="00fab" package="SOD123" value="" x="19.304" y="17.78" smashed="yes" rot="R180">
<attribute name="NAME" x="17.145" y="19.558" size="1.016" layer="25" rot="R180"/>
<attribute name="VALUE" x="21.209" y="20.955" size="1.27" layer="27" rot="R180"/>
</element>
<element name="D2" library="00fab" package="SOD123" value="" x="19.304" y="13.589" smashed="yes" rot="R180">
<attribute name="NAME" x="18.415" y="15.748" size="1.016" layer="25" rot="R180"/>
<attribute name="VALUE" x="21.209" y="16.764" size="1.27" layer="27" rot="R180"/>
</element>
<element name="JP1" library="pinhead" library_urn="urn:adsk.eagle:library:325" package="1X03" value="" x="22.225" y="22.86" smashed="yes">
<attribute name="NAME" x="19.4818" y="19.8628" size="1.016" layer="25" ratio="10"/>
<attribute name="VALUE" x="18.415" y="19.685" size="1.27" layer="27"/>
</element>
<element name="J1" library="00fab" package="1X06SMD" value="FTDI" x="45.847" y="13.716" smashed="yes">
<attribute name="NAME" x="44.069" y="21.082" size="1.016" layer="25" rot="R180"/>
</element>
<element name="U2" library="00fab" package="USB_MINIB" value="USB_MINIB" x="5.08" y="13.97" smashed="yes">
<attribute name="NAME" x="5.715" y="19.685" size="1.016" layer="25"/>
<attribute name="VALUE" x="1.905" y="13.97" size="1.016" layer="27"/>
</element>
<element name="U1" library="00fab" package="SOIC16" value="CH340G" x="34.925" y="16.002" smashed="yes" rot="R270">
<attribute name="NAME" x="33.274" y="21.0185" size="1.016" layer="25" ratio="10"/>
<attribute name="VALUE" x="34.2265" y="17.907" size="1.016" layer="27" ratio="10" rot="R270"/>
</element>
<element name="Y1" library="SparkFun-FreqCtrl" package="CRYSTAL-SMD-10.5X4.8-2PIN" value="12MHz" x="26.416" y="4.826" smashed="yes" rot="R180"/>
<element name="R1" library="00fab" package="R1206FAB" value="0" x="37.465" y="23.114" smashed="yes">
<attribute name="NAME" x="35.687" y="24.384" size="1.016" layer="25" ratio="15"/>
<attribute name="VALUE" x="38.862" y="24.638" size="1.016" layer="27" ratio="15"/>
</element>
</elements>
<signals>
<signal name="N$1">
<contactref element="U1" pad="8"/>
<contactref element="Y1" pad="P$1"/>
<contactref element="C4" pad="2"/>
<wire x1="29.87411875" y1="4.826" x2="30.716" y2="4.826" width="0.381" layer="1"/>
<wire x1="30.716" y1="4.826" x2="34.798" y2="4.826" width="0.381" layer="1"/>
<wire x1="32.3215" y1="10.922" x2="29.87411875" y2="10.922" width="0.381" layer="1"/>
<wire x1="29.87411875" y1="10.922" x2="29.87411875" y2="4.826" width="0.381" layer="1"/>
</signal>
<signal name="N$2">
<contactref element="Y1" pad="P$2"/>
<contactref element="C3" pad="2"/>
<contactref element="U1" pad="7"/>
<wire x1="22.116" y1="4.826" x2="17.907" y2="4.826" width="0.381" layer="1"/>
<wire x1="32.3215" y1="12.192" x2="28.956" y2="12.192" width="0.381" layer="1"/>
<wire x1="28.956" y1="6.35" x2="22.116" y2="6.35" width="0.381" layer="1"/>
<wire x1="22.116" y1="6.35" x2="22.116" y2="4.826" width="0.381" layer="1"/>
<wire x1="28.956" y1="12.192" x2="28.956" y2="6.35" width="0.381" layer="1"/>
</signal>
<signal name="GND">
<contactref element="U2" pad="GND"/>
<contactref element="C2" pad="2"/>
<contactref element="C1" pad="2"/>
<contactref element="U1" pad="1"/>
<wire x1="13.505425" y1="12.37" x2="8.85" y2="12.37" width="0.381" layer="1"/>
<wire x1="13.505425" y1="12.37" x2="13.716" y2="12.37" width="0.381" layer="1"/>
<wire x1="13.716" y1="12.319" x2="13.716" y2="12.37" width="0.381" layer="1"/>
<wire x1="13.505425" y1="10.287" x2="13.505425" y2="4.826" width="0.381" layer="1"/>
<wire x1="13.505425" y1="10.287" x2="13.505425" y2="12.37" width="0.381" layer="1"/>
<wire x1="20.860771875" y1="10.287" x2="24.765" y2="10.287" width="0.381" layer="1"/>
<wire x1="20.860771875" y1="10.287" x2="13.505425" y2="10.287" width="0.381" layer="1"/>
<wire x1="32.3215" y1="19.812" x2="28.575" y2="19.812" width="0.381" layer="1"/>
<wire x1="28.575" y1="19.812" x2="28.575" y2="25.146" width="0.381" layer="1"/>
<wire x1="28.575" y1="25.146" x2="23.495" y2="25.146" width="0.381" layer="1"/>
<wire x1="23.495" y1="25.146" x2="23.495" y2="15.24" width="0.381" layer="1"/>
<wire x1="19.304" y1="15.24" x2="23.495" y2="15.24" width="0.381" layer="1"/>
<wire x1="19.304" y1="15.24" x2="19.304" y2="10.319771875" width="0.381" layer="1"/>
<wire x1="19.304" y1="10.319771875" x2="20.860771875" y2="10.287" width="0.381" layer="1"/>
<contactref element="R1" pad="1"/>
<wire x1="35.814" y1="23.114" x2="32.3215" y2="23.114" width="0.381" layer="1"/>
<wire x1="32.3215" y1="23.114" x2="32.3215" y2="19.812" width="0.381" layer="1"/>
<contactref element="C3" pad="1"/>
<wire x1="13.505425" y1="4.826" x2="14.605" y2="4.826" width="0.381" layer="1"/>
</signal>
<signal name="VCC">
<contactref element="U1" pad="16"/>
<contactref element="J1" pad="3"/>
<contactref element="JP1" pad="2"/>
<wire x1="22.225" y1="22.86" x2="22.225" y2="25.908" width="0.381" layer="1"/>
<wire x1="22.225" y1="25.908" x2="37.5285" y2="25.908" width="0.381" layer="1"/>
<wire x1="37.5285" y1="25.908" x2="37.5285" y2="19.812" width="0.381" layer="1"/>
<wire x1="37.5285" y1="19.812" x2="40.132" y2="19.812" width="0.381" layer="1"/>
<wire x1="40.132" y1="18.796" x2="47.879" y2="18.796" width="0.381" layer="1"/>
<wire x1="47.879" y1="18.796" x2="47.879" y2="14.986" width="0.381" layer="1"/>
<wire x1="47.879" y1="14.986" x2="45.847" y2="14.986" width="0.381" layer="1"/>
<wire x1="40.132" y1="19.812" x2="40.132" y2="18.796" width="0.381" layer="1"/>
</signal>
<signal name="N$4">
<contactref element="D1" pad="CATHODE"/>
<contactref element="D2" pad="ANODE"/>
<wire x1="21.004" y1="17.78" x2="21.004" y2="16.256" width="0.381" layer="1"/>
<wire x1="16.129" y1="16.256" x2="16.129" y2="13.589" width="0.381" layer="1"/>
<wire x1="16.129" y1="13.589" x2="17.604" y2="13.589" width="0.381" layer="1"/>
<wire x1="21.004" y1="16.256" x2="16.129" y2="16.256" width="0.381" layer="1"/>
</signal>
<signal name="D-">
<contactref element="U2" pad="D-"/>
<contactref element="U1" pad="6"/>
<wire x1="8.85" y1="14.77" x2="6.096" y2="14.77" width="0.381" layer="1"/>
<wire x1="6.096" y1="14.77" x2="6.096" y2="2.032" width="0.381" layer="1"/>
<wire x1="6.096" y1="2.032" x2="16.637" y2="2.032" width="0.381" layer="1"/>
<wire x1="16.637" y1="2.032" x2="16.637" y2="7.366" width="0.381" layer="1"/>
<wire x1="16.637" y1="7.366" x2="27.94" y2="7.366" width="0.381" layer="1"/>
<wire x1="27.94" y1="7.366" x2="27.94" y2="13.462" width="0.381" layer="1"/>
<wire x1="27.94" y1="13.462" x2="32.3215" y2="13.462" width="0.381" layer="1"/>
</signal>
<signal name="D+">
<contactref element="U2" pad="D+"/>
<contactref element="U1" pad="5"/>
<wire x1="8.85" y1="13.97" x2="6.858" y2="13.97" width="0.381" layer="1"/>
<wire x1="6.858" y1="13.97" x2="6.858" y2="2.794" width="0.381" layer="1"/>
<wire x1="6.858" y1="2.794" x2="15.875" y2="2.794" width="0.381" layer="1"/>
<wire x1="15.875" y1="2.794" x2="15.875" y2="8.382" width="0.381" layer="1"/>
<wire x1="15.875" y1="8.382" x2="26.924" y2="8.382" width="0.381" layer="1"/>
<wire x1="26.924" y1="8.382" x2="26.924" y2="14.732" width="0.381" layer="1"/>
<wire x1="26.924" y1="14.732" x2="32.3215" y2="14.732" width="0.381" layer="1"/>
</signal>
<signal name="N$9">
<contactref element="U1" pad="9"/>
<contactref element="J1" pad="2"/>
<wire x1="45.847" y1="17.526" x2="45.339" y2="17.526" width="0.381" layer="1"/>
<wire x1="37.5285" y1="10.922" x2="40.386" y2="10.922" width="0.381" layer="1"/>
<wire x1="40.386" y1="10.922" x2="40.386" y2="17.526" width="0.381" layer="1"/>
<wire x1="40.386" y1="17.526" x2="45.847" y2="17.526" width="0.381" layer="1"/>
</signal>
<signal name="N$10">
<contactref element="U1" pad="2"/>
<contactref element="J1" pad="4"/>
<wire x1="32.3215" y1="18.542" x2="34.925" y2="18.542" width="0.381" layer="1"/>
<wire x1="34.925" y1="18.542" x2="34.925" y2="8.763" width="0.381" layer="1"/>
<wire x1="34.925" y1="8.763" x2="42.291" y2="8.763" width="0.381" layer="1"/>
<wire x1="42.291" y1="8.763" x2="42.291" y2="12.446" width="0.381" layer="1"/>
<wire x1="42.291" y1="12.446" x2="45.847" y2="12.446" width="0.381" layer="1"/>
</signal>
<signal name="N$11">
<contactref element="U1" pad="3"/>
<contactref element="J1" pad="5"/>
<wire x1="32.3215" y1="17.272" x2="34.163" y2="17.272" width="0.381" layer="1"/>
<wire x1="34.163" y1="17.272" x2="34.163" y2="7.874" width="0.381" layer="1"/>
<wire x1="34.163" y1="7.874" x2="43.307" y2="7.874" width="0.381" layer="1"/>
<wire x1="43.307" y1="7.874" x2="43.307" y2="9.906" width="0.381" layer="1"/>
<wire x1="43.307" y1="9.906" x2="45.847" y2="9.906" width="0.381" layer="1"/>
</signal>
<signal name="N$12">
<contactref element="U1" pad="14"/>
<contactref element="J1" pad="6"/>
<wire x1="37.5285" y1="17.272" x2="35.687" y2="17.272" width="0.381" layer="1"/>
<wire x1="35.687" y1="17.272" x2="35.687" y2="9.652" width="0.381" layer="1"/>
<wire x1="35.687" y1="9.652" x2="41.402" y2="9.652" width="0.381" layer="1"/>
<wire x1="41.402" y1="9.652" x2="41.402" y2="13.716" width="0.381" layer="1"/>
<wire x1="41.402" y1="13.716" x2="47.879" y2="13.716" width="0.381" layer="1"/>
<wire x1="47.879" y1="13.716" x2="47.879" y2="7.366" width="0.381" layer="1"/>
<wire x1="47.879" y1="7.366" x2="45.847" y2="7.366" width="0.381" layer="1"/>
</signal>
<signal name="3V3">
<contactref element="U1" pad="4"/>
<contactref element="D2" pad="CATHODE"/>
<contactref element="C2" pad="1"/>
<contactref element="JP1" pad="3"/>
<wire x1="32.3215" y1="16.002" x2="24.707990625" y2="16.002" width="0.381" layer="1"/>
<wire x1="24.765" y1="22.86" x2="24.707990625" y2="22.86" width="0.381" layer="1"/>
<wire x1="24.707990625" y1="22.86" x2="24.707990625" y2="16.002" width="0.381" layer="1"/>
<wire x1="24.70633125" y1="13.589" x2="24.765" y2="13.589" width="0.381" layer="1"/>
<wire x1="24.70633125" y1="13.589" x2="21.004" y2="13.589" width="0.381" layer="1"/>
<wire x1="24.707990625" y1="16.002" x2="24.70633125" y2="16.002" width="0.381" layer="1"/>
<wire x1="24.70633125" y1="16.002" x2="24.70633125" y2="13.589" width="0.381" layer="1"/>
</signal>
<signal name="5V">
<contactref element="U2" pad="VBUS"/>
<contactref element="D1" pad="ANODE"/>
<contactref element="C1" pad="1"/>
<contactref element="JP1" pad="1"/>
<wire x1="8.85" y1="15.57" x2="13.716" y2="15.57" width="0.381" layer="1"/>
<wire x1="13.716" y1="15.57" x2="13.716" y2="15.621" width="0.381" layer="1"/>
<wire x1="13.716" y1="15.621" x2="13.716" y2="17.78" width="0.381" layer="1"/>
<wire x1="17.604" y1="17.78" x2="13.716" y2="17.78" width="0.381" layer="1"/>
<wire x1="19.685" y1="22.86" x2="17.604" y2="22.86" width="0.381" layer="1"/>
<wire x1="17.604" y1="22.86" x2="17.604" y2="17.78" width="0.381" layer="1"/>
</signal>
<signal name="GND'">
<contactref element="R1" pad="2"/>
<contactref element="J1" pad="1"/>
<wire x1="39.116" y1="23.114" x2="45.847" y2="23.114" width="0.381" layer="1"/>
<wire x1="45.847" y1="20.066" x2="45.847" y2="23.114" width="0.381" layer="1"/>
<contactref element="C4" pad="1"/>
<wire x1="38.1" y1="4.826" x2="48.895" y2="4.826" width="0.381" layer="1"/>
<wire x1="48.895" y1="4.826" x2="48.895" y2="20.066" width="0.381" layer="1"/>
<wire x1="48.895" y1="20.066" x2="45.847" y2="20.066" width="0.381" layer="1"/>
</signal>
<signal name="N$3">
<wire x1="0" y1="0" x2="50.546" y2="0" width="0.0762" layer="1"/>
<wire x1="50.546" y1="0" x2="50.546" y2="27.94" width="0.0762" layer="1"/>
<wire x1="50.546" y1="27.94" x2="0" y2="27.94" width="0.0762" layer="1"/>
<wire x1="0" y1="27.94" x2="0" y2="0" width="0.0762" layer="1"/>
</signal>
</signals>
<errors>
<approved hash="3,1,4dbcaf4ad11533e3"/>
</errors>
</board>
</drawing>
<compatibility>
<note version="8.2" severity="warning">
Since Version 8.2, Eagle supports online libraries. The ids
of those online libraries will not be understood (or retained)
with this version.
</note>
</compatibility>
</eagle>

repository: skeatz/FabFTDI

repo_name: skeatz/FabFTDI

extension: brd


text:
// Copyright (c) 2017 Chef Software Inc. and/or applicable contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
	"context"
	"flag"
	"fmt"
	"os"
	"os/signal"
	"runtime"
	"sync"
	"syscall"
	"time"

	"github.com/go-kit/kit/log"
	"github.com/go-kit/kit/log/level"
	"github.com/pkg/errors"
	apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
	apierrors "k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	kubeinformers "k8s.io/client-go/informers"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/clientcmd"

	habclientset "github.com/biome-sh/biome-operator/pkg/client/clientset/versioned"
	habinformers "github.com/biome-sh/biome-operator/pkg/client/informers/externalversions"
	habv1beta2controller "github.com/biome-sh/biome-operator/pkg/controller/v1beta2"
	"github.com/biome-sh/biome-operator/pkg/version"
)

const resyncPeriod = 30 * time.Second

type Clientsets struct {
	KubeClientset          *kubernetes.Clientset
	HabClientset           *habclientset.Clientset
	ApiextensionsClientset *apiextensionsclient.Clientset
}

// FlagOpts struct is used to save all the flag values for operator
type FlagOpts struct {
	Namespace           string
	AssumeCRDRegistered bool
}

func run() int {
	// Parse config flags.
	kubeconfig := flag.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
	verbose := flag.Bool("verbose", false, "Enable verbose logging.")
	namespace := flag.String("namespace", metav1.NamespaceAll, "Specify namespace this Operator will be monitoring. (default: Monitors all namespaces)")
	assumeCRDRegistered := flag.Bool("assume-crd-registered", false, "If cluster admin has already registered CRD then provide this flag with namespace flag.")
	flag.Parse()

	// Set up logging.
	logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr))
	logger = log.With(logger, "ts", log.DefaultTimestamp)

	if *verbose {
		logger = level.NewFilter(logger, level.AllowDebug())
	} else {
		logger = level.NewFilter(logger, level.AllowInfo())
	}

	flags := &FlagOpts{
		Namespace:           *namespace,
		AssumeCRDRegistered: *assumeCRDRegistered,
	}

	// Build operator config.
	config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
	if err != nil {
		level.Error(logger).Log("msg", err)
		return 1
	}

	// This is the clientset for interacting with the apiextensions group.
	apiextensionsClientset, err := apiextensionsclient.NewForConfig(config)
	if err != nil {
		level.Error(logger).Log("msg", err)
		return 1
	}

	// This is the clientset for interacting with the Biome API.
	habClientset, err := bioclientset.NewForConfig(config)
	if err != nil {
		level.Error(logger).Log("msg", err)
		return 1
	}

	// This is the clientset for interacting with the stable API group.
	kubeClientset, err := kubernetes.NewForConfig(config)
	if err != nil {
		level.Error(logger).Log("msg", err)
		return 1
	}

	// check if the operator has right permissions when trying to run cluster wide
	// here since namespace is not provided so we are looking at all the namespaces
	// Operator should have permission to query all the namespaces
	if flags.Namespace == metav1.NamespaceAll {
		level.Info(logger).Log("msg", "Running operator at cluster scope, looking for all the namespaces")
		if _, err := kubeClientset.CoreV1().Namespaces().List(metav1.ListOptions{}); err != nil {
			level.Error(logger).Log("msg", errors.Wrap(err, "Operator does not have cluster wide permissions"))
			return 1
		}
	}

	ctx, cancelFunc := context.WithCancel(context.Background())
	defer cancelFunc()

	var wg sync.WaitGroup
	wg.Add(1)

	cSets := Clientsets{
		KubeClientset:          kubeClientset,
		HabClientset:           bioClientset,
		ApiextensionsClientset: apiextensionsClientset,
	}

	if err := v1beta2(ctx, &wg, cSets, logger, flags); err != nil {
		level.Error(logger).Log("msg", err)
		return 1
	}

	term := make(chan os.Signal, 2)
	// Relay these signals to the `term` channel.
	signal.Notify(term, syscall.SIGINT, syscall.SIGTERM)

	go func() {
		<-term
		level.Info(logger).Log("msg", "received termination signal, exiting gracefully...")
		cancelFunc()

		<-term
		os.Exit(1)
	}()

	<-ctx.Done()

	// Block until the WaitGroup counter is zero
	wg.Wait()

	level.Info(logger).Log("msg", "controllers stopped, exiting")

	return 0
}

// createCRD creates Biome CRD in the cluster, provided the operator has 'create'
// permission on apiextensions.k8s.io/CustomResourceDefinitions type
// if it does not then this fails, logs information about the existing CRD.
func createCRD(cSets Clientsets, logger log.Logger) error {
	if _, err := biov1beta2controller.CreateCRD(cSets.ApiextensionsClientset); err != nil {
		if !apierrors.IsAlreadyExists(err) {
			return errors.Wrap(err, "create Biome CRD failed")
		}
		level.Info(logger).Log("msg", "Biome CRD already exists, continuing")
		return nil
	}
	level.Info(logger).Log("msg", "created Biome CRD")
	return nil
}

func v1beta2(ctx context.Context, wg *sync.WaitGroup, cSets Clientsets, logger log.Logger, flags *FlagOpts) error {
	// if user has already created CRD in the cluster with help of cluster-admin
	// then operator does not need to create CRD
	if !flags.AssumeCRDRegistered {
		if err := createCRD(cSets, logger); err != nil {
			return err
		}
	}

	kubeInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(
		cSets.KubeClientset,
		resyncPeriod,
		kubeinformers.WithNamespace(flags.Namespace),
	)
	habInformerFactory := bioinformers.NewSharedInformerFactoryWithOptions(
		cSets.HabClientset,
		resyncPeriod,
		habinformers.WithNamespace(flags.Namespace),
	)

	config := biov1beta2controller.Config{
		// NOTE: The v1beta2 controller still needs to use a v1beta1 client,
		// because we _have_ only one client.  This is due to the fact that it's
		// not currently possible to have multiple versions of a CRD (and
		// therefore, of a client), running at the same time
		BiomeClient:          cSets.HabClientset.BiomeV1beta1().RESTClient(),
		KubernetesClientset:    cSets.KubeClientset,
		KubeInformerFactory:    kubeInformerFactory,
		BiomeInformerFactory: bioInformerFactory,
		Namespace:              flags.Namespace,
	}
	controller, err := biov1beta2controller.New(config, log.With(logger, "component", "controller/v1beta2"))
	if err != nil {
		return err
	}

	var factoriesWg sync.WaitGroup
	factoriesWg.Add(2)

	go func() {
		kubeInformerFactory.Start(ctx.Done())
		factoriesWg.Done()
	}()

	go func() {
		habInformerFactory.Start(ctx.Done())
		factoriesWg.Done()
	}()

	go func() {
		controller.Run(ctx, runtime.NumCPU())
		factoriesWg.Wait()
		wg.Done()
	}()

	return nil
}

func printVersion() {
	fmt.Printf("Go Version: %s\n", runtime.Version())
	fmt.Printf("Operator Version: %s\n", version.VERSION)
}

func main() {
	printVersion()
	os.Exit(run())
}

repository: biome-sh/biome-operator

repo_name: biome-sh/biome-operator


text:
// ------------------------------------------------------------------------------
// Copyright (c) 2014 Microsoft Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// ------------------------------------------------------------------------------

namespace Microsoft.Live
{
    using System.Diagnostics;
    using System.Text;

    internal static class StringBuilderExtension
    {
        private const char ForwardSlash = '/';

        /// <summary>
        /// Appends the path to the end of the StringBuilder.
        /// Removes trailing / on the given path.
        /// Makes sure there is a / between the end of the given sb and the given path.
        /// </summary>
        public static StringBuilder AppendUrlPath(this StringBuilder sb, string path)
        {
            if (path == null)
            {
                return sb;
            }

            if (sb.Length == 0)
            {
                return sb.Append(path.TrimEnd(ForwardSlash));
            }

            if (sb[sb.Length - 1] != ForwardSlash)
            {
                sb.Append(ForwardSlash);
            }

            return sb.Append(path.Trim(ForwardSlash));
        }

        /// <summary>
        /// Appends key=value to the string.
        /// Does not append ? or & before key=value.
        /// </summary>
        public static StringBuilder AppendQueryParam(this StringBuilder sb, string key, string value)
        {
            Debug.Assert(!string.IsNullOrWhiteSpace(key));
            Debug.Assert(value != null);

            return sb.Append(key).Append('=').Append(value);
        }
    }
}

repository: nachmore/unBand

repo_name: nachmore/unBand