alkasir: github.com/alkasir/alkasir/pkg/central/db Index | Files

package db

import "github.com/alkasir/alkasir/pkg/central/db"

Index

Package Files

apicredentials.go db.go internet.go maxmind.go postgres.go sessionstoken.go

Constants

const PageLength = 1000

Variables

var SessionTokens = sessionTokenStore{
    sessions: make(map[shared.SuggestionToken]tokenData, 0),
}

type APICredentials Uses

type APICredentials struct {
    Username     string
    PasswordHash []byte
    Salt         []byte
    Enabled      bool
}

APICredentials is used for export api jwt authentication.

func (*APICredentials) IsValid Uses

func (a *APICredentials) IsValid(password string) (bool, error)

func (*APICredentials) SetPassword Uses

func (a *APICredentials) SetPassword(password string) error

type Clients Uses

type Clients struct {
    Internet InternetClient
    DB       DBClient
    Maxmind  MaxmindClient
}

Clients

type DB Uses

type DB struct {
    *sql.DB
    // contains filtered or unexported fields
}

DB .

func Open Uses

func Open(connectionString string) (*DB, error)

Open returns a wrapped *sql.DB and starts services

func (*DB) GetBlockedHosts Uses

func (d *DB) GetBlockedHosts(CountryCode string, ASN int) ([]string, error)

func (*DB) GetExportAPIAuthCredentials Uses

func (d *DB) GetExportAPIAuthCredentials(username string) (bool, APICredentials, error)

func (*DB) GetExportBlockedHosts Uses

func (d *DB) GetExportBlockedHosts(req shared.BlockedContentRequest) ([]shared.HostsPublishLog, string, error)

func (*DB) GetExportSamples Uses

func (d *DB) GetExportSamples(req shared.ExportSampleRequest) ([]shared.ExportSampleEntry, string, error)

func (*DB) GetExportSimpleSamples Uses

func (d *DB) GetExportSimpleSamples(req shared.ExportSimpleSampleRequest) ([]shared.ExportSimpleSampleEntry, string, error)

func (*DB) GetLastProcessedSampleID Uses

func (d *DB) GetLastProcessedSampleID() (uint64, error)

func (*DB) GetRelatedHosts Uses

func (d *DB) GetRelatedHosts() (map[string][]string, error)

func (*DB) GetSamples Uses

func (d *DB) GetSamples(fromID uint64, sampleType string) (chan Sample, error)

func (*DB) GetSessionSamples Uses

func (d *DB) GetSessionSamples(token shared.SuggestionToken) ([]Sample, error)

func (*DB) GetUpgrade Uses

func (d *DB) GetUpgrade(q GetUpgradeQuery) (UpgradeMeta, bool, error)

func (*DB) InsertExportAPICredentials Uses

func (d *DB) InsertExportAPICredentials(cred APICredentials) error

func (*DB) InsertSample Uses

func (d *DB) InsertSample(s Sample) error

InsertSample inserts a Sample into the samples table.

func (*DB) InsertSimpleSample Uses

func (d *DB) InsertSimpleSample(s SimpleSample) error

InsertSample inserts a Sample into the samples table.

func (*DB) InsertUpgrades Uses

func (d *DB) InsertUpgrades(u []UpgradeMeta) error

InsertUpgrades inserts a list of upgrade entreis into the database

func (*DB) IsURLAllowed Uses

func (d *DB) IsURLAllowed(url *url.URL, countryCode string) (bool, error)

IsURLAllowed returns true if the supplied URL is supported for circumenvtion with alkasir.

func (*DB) PublishHost Uses

func (d *DB) PublishHost(sample Sample) error

func (*DB) RecentSuggestionSessions Uses

func (d *DB) RecentSuggestionSessions(n uint64) ([]tokenData, error)

func (*DB) SetLastProcessedSampleID Uses

func (d *DB) SetLastProcessedSampleID(id uint64) error

type DBClient Uses

type DBClient interface {

    // internal house keeping
    GetLastProcessedSampleID() (uint64, error)
    SetLastProcessedSampleID(id uint64) error

    // client/server api
    IsURLAllowed(url *url.URL, countryCode string) (bool, error)
    RecentSuggestionSessions(n uint64) ([]tokenData, error)

    InsertSample(s Sample) error
    InsertSimpleSample(s SimpleSample) error
    GetSamples(fromID uint64, sampleType string) (chan Sample, error)
    PublishHost(sample Sample) error

    // GetURLSamples(URL string) ([]Sample, error)
    GetSessionSamples(Token shared.SuggestionToken) ([]Sample, error)

    GetBlockedHosts(CountryCode string, ASN int) ([]string, error)
    GetRelatedHosts() (map[string][]string, error)
    GetUpgrade(GetUpgradeQuery) (UpgradeMeta, bool, error)
    InsertUpgrades([]UpgradeMeta) error

    // Returns credentials for given user, if exists
    GetExportAPIAuthCredentials(username string) (bool, APICredentials, error)
    // create or update credentials, does not enable if disabled.
    InsertExportAPICredentials(credentials APICredentials) error

    // query for exporting data from logs...
    GetExportBlockedHosts(req shared.BlockedContentRequest) ([]shared.HostsPublishLog, string, error)
    GetExportSamples(req shared.ExportSampleRequest) ([]shared.ExportSampleEntry, string, error)
    GetExportSimpleSamples(req shared.ExportSimpleSampleRequest) ([]shared.ExportSimpleSampleEntry, string, error)
}

type GetUpgradeQuery Uses

type GetUpgradeQuery struct {
    Artifact        string
    Version         string
    AlsoUnpublished bool // include unpublished versions in results
}

GetUpgradeQuery .

type HostListEntry Uses

type HostListEntry struct {
    ID          uint64
    Host        string
    CountryCode string
    ASN         int
    CreatedAt   time.Time
    Sticky      bool
}

HostListEntry .

type Internet Uses

type Internet struct {
    *redis.Pool
}

Internet .

func NewInternetClient Uses

func NewInternetClient(pool *redis.Pool) *Internet

func (*Internet) IP2ASN Uses

func (i *Internet) IP2ASN(IP net.IP) (*internet.ASNResult, error)

type InternetClient Uses

type InternetClient interface {
    IP2ASN(IP net.IP) (*internet.ASNResult, error)
}

type Maxmind Uses

type Maxmind struct {
    // contains filtered or unexported fields
}

func NewMaxmindClient Uses

func NewMaxmindClient(countryDB, cityDB *maxminddb.Reader) *Maxmind

func (*Maxmind) IP2CityGeoNameID Uses

func (m *Maxmind) IP2CityGeoNameID(IP net.IP) uint

func (*Maxmind) IP2CountryCode Uses

func (m *Maxmind) IP2CountryCode(IP net.IP) string

IP2CountryCode resolves an IP address to ISO country code using an geoip database.

type MaxmindClient Uses

type MaxmindClient interface {
    IP2CityGeoNameID(IP net.IP) uint
    IP2CountryCode(IP net.IP) string
}

type Sample Uses

type Sample struct {
    ID          uint64
    Host        string
    CountryCode string
    ASN         int
    CreatedAt   time.Time
    Origin      string
    Type        string
    Token       shared.SuggestionToken
    Data        []byte
    ExtraData   []byte
}

Sample mirrors the samples postgres table

type SimpleSample Uses

type SimpleSample struct {
    ID          uint64
    CountryCode string
    ASN         int
    CreatedAt   time.Time
    Type        string
    OriginID    string
    Data        []byte
}

Sample mirrors the samples postgres table

type UpgradeMeta Uses

type UpgradeMeta struct {
    Artifact         string    `json:"artifact"`
    Version          string    `json:"version"`
    CreatedAt        time.Time `json:"createdAt"`
    SHA256Sum        string    `json:"sha256Sum"`
    ED25519Signature string    `json:"ed25519Sig"`
}

UpgradeMeta .

Package db imports 22 packages (graph) and is imported by 3 packages. Updated 2016-07-21. Refresh now. Tools for package owners.