network

package
v0.0.0-...-5f8c1fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2023 License: BSD-2-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAuthyDisabled = errors.New("authy is not enabled in this environment")

ErrAuthyDisabled means authy isn't enabled here. You can change that in the .env file.

Functions

This section is empty.

Types

type AuthyClient

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

func (*AuthyClient) AwaitOneTouch

func (ac *AuthyClient) AwaitOneTouch(userEmail, authyID string) (bool, error)

AwaitOneTouch sends a OneTouch login request via Authy and awaits the user's response. Param authyID is the user's AuthyID. Param userEmail is used for logging.

This is a blocking request that waits up to 45 seconds for a user to approve the one-touch push notification.

If request is approved, this returns true. Otherwise, false.

func (*AuthyClient) RegisterUser

func (ac *AuthyClient) RegisterUser(userEmail string, countryCode int, phone string) (string, error)

RegisterUser registers a user with Authy for this app. Note that users need separate registrations for each environment (dev, demo, prod, etc.).

On success, this returns the user's new AuthyID. The caller is responsible for attaching that ID to the user object and saving it to the database.

Use user.CountryCodeAndPhone() to get country code and phone number, as these need to be separate. Do not pass user.PhoneNumber in format "+<country_code><number>" because that won't work.

type AuthyClientInterface

type AuthyClientInterface interface {
	AwaitOneTouch(string, string) (bool, error)
	RegisterUser(string, int, string) (string, error)
}

func NewAuthyClient

func NewAuthyClient(authyEnabled bool, authyAPIKey string, log zerolog.Logger) AuthyClientInterface

func NewMockAuthyClient

func NewMockAuthyClient() AuthyClientInterface

NewMockAuthyClient returns a mock authy client for testing.

type MockAuthyClient

type MockAuthyClient struct{}

MockAuthyClient is used in testing.

func (*MockAuthyClient) AwaitOneTouch

func (m *MockAuthyClient) AwaitOneTouch(userEmail, authyID string) (bool, error)

AwaitOneTouch for unit tests. Returns true unless param authyID == "fail".

func (*MockAuthyClient) RegisterUser

func (m *MockAuthyClient) RegisterUser(userEmail string, countryCode int, phone string) (string, error)

RegisterUser for unit testing. Always succeeds.

type NSQClient

type NSQClient struct {
	URL string
	// contains filtered or unexported fields
}

func NewNSQClient

func NewNSQClient(url string, logger zerolog.Logger) *NSQClient

NewNSQClient returns a new NSQ client that will connect to the NSQ server and the specified url. The URL is typically available through Config.NsqdHttpAddress, and usually ends with :4151. This is the URL to which we post items we want to queue, and from which our workers read.

Note that this client provides write access to queue, so we can add things. It does not provide read access. The workers do the reading.

func (*NSQClient) CreateChannel

func (client *NSQClient) CreateChannel(topicName, channelName string) error

CreateChannel creates a channel in the specified topic. This is used only in testing.

func (*NSQClient) CreateTopic

func (client *NSQClient) CreateTopic(topicName string) error

CreateTopic creates a topic. This is used only in testing.

func (*NSQClient) DeleteAllChannels

func (client *NSQClient) DeleteAllChannels() error

DeleteAllChannels deletes all channels

func (*NSQClient) DeleteAllTopics

func (client *NSQClient) DeleteAllTopics() error

DeleteAllTopics deletes all topics

func (*NSQClient) DeleteChannel

func (client *NSQClient) DeleteChannel(topicName, channelName string) error

DeleteChannel deletes a channel in the specified topic. This is used only in testing.

func (*NSQClient) DeleteTopic

func (client *NSQClient) DeleteTopic(topicName string) error

DeleteTopic deletes a topic. This is used only in testing.

func (*NSQClient) EmptyAllChannels

func (client *NSQClient) EmptyAllChannels() error

EmptyAllChannels empties all channels.

func (*NSQClient) EmptyAllTopics

func (client *NSQClient) EmptyAllTopics() error

EmptyAllTopics empties all topics.

func (*NSQClient) EmptyChannel

func (client *NSQClient) EmptyChannel(topicName, channelName string) error

EmptyChannel empties the specified channel.

func (*NSQClient) EmptyTopic

func (client *NSQClient) EmptyTopic(topicName string) error

EmptyTopic empties the specified topic.

func (*NSQClient) Enqueue

func (client *NSQClient) Enqueue(topic string, workItemID int64) error

Enqueue posts data to NSQ, which essentially means putting it into a work topic. Param topic is the topic under which you want to queue something. For example, prepare_topic, fixity_topic, etc. Param workItemId is the id of the WorkItem record in Pharos we want to queue.

func (*NSQClient) EnqueueString

func (client *NSQClient) EnqueueString(topic string, data string) error

EnqueueString posts string data to the specified NSQ topic

func (*NSQClient) GetInfo

func (client *NSQClient) GetInfo() (*NSQInfo, error)

GetInfo returns basic info about nsqd, including hostname and port numbers.

func (*NSQClient) GetStats

func (client *NSQClient) GetStats() (*NSQStatsData, error)

GetStats allows us to get some basic stats from NSQ. The NSQ /stats endpoint returns a richer set of stats than what this fuction returns, but we only need some basic data for integration tests, so that's all we're parsing. The return value is a map whose key is the topic name and whose value is an NSQTopicStats object. NSQ is supposed to support topic_name as a query param, but this doesn't seem to be working in NSQ 0.3.0, so we're just returning stats for all topics right now. Also note that requests to /stats/ (with trailing slash) produce a 404.

func (*NSQClient) PauseAllChannels

func (client *NSQClient) PauseAllChannels() error

PauseAllChannels pauses all channels.

func (*NSQClient) PauseAllTopics

func (client *NSQClient) PauseAllTopics() error

PauseAllTopics pauses all topics.

func (*NSQClient) PauseChannel

func (client *NSQClient) PauseChannel(topicName, channelName string) error

PauseChannel pauses the specified channel.

func (*NSQClient) PauseTopic

func (client *NSQClient) PauseTopic(topicName string) error

PauseTopic pauses the topic with the specified name.

func (*NSQClient) UnpauseAllChannels

func (client *NSQClient) UnpauseAllChannels() error

UnpauseAllChannels unpauses all channels.

func (*NSQClient) UnpauseAllTopics

func (client *NSQClient) UnpauseAllTopics() error

UnpauseAllTopics unpauses all topics.

func (*NSQClient) UnpauseChannel

func (client *NSQClient) UnpauseChannel(topicName, channelName string) error

UnpauseChannel unpauses the specified channel.

func (*NSQClient) UnpauseTopic

func (client *NSQClient) UnpauseTopic(topicName string) error

UnpauseTopic unpauses the specified topic.

type NSQInfo

type NSQInfo struct {
	Version          string `json:"version"`
	BroadcastAddress string `json:"broadcast_address"`
	Hostname         string `json:"hostname"`
	HttpPort         int    `json:"http_port"`
	TcpPort          int    `json:"tcp_port"`
	StartTime        int64  `json:"start_time"`
}

type NSQStatsData

type NSQStatsData struct {
	Version   string             `json:"version"`
	Health    string             `json:"health"`
	StartTime uint64             `json:"start_time"`
	Topics    []*nsqd.TopicStats `json:"topics"`
	Info      *NSQInfo           `json:"info"`
}

NSQStatsData contains the important info returned by a call to NSQ's /stats endpoint, including the number of items in each topic and queue.

func (*NSQStatsData) GetChannel

func (data *NSQStatsData) GetChannel(topicName, channelName string) *nsqd.ChannelStats

func (*NSQStatsData) GetTopic

func (data *NSQStatsData) GetTopic(name string) *nsqd.TopicStats

type RedisClient

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

RedisClient is a crude and deliberately limited implementation that returns JSON only. The JSON is intended for human consumption, primarily for APTrust admins to view when debugging problems.

The JSON represents internal state information from the ingest and restoration workers. The structure of the data may change over time, so this client simply uses map[string]interface{} structures to accomodate arbitrary JSON structures.

func NewRedisClient

func NewRedisClient(address, password string, db int) *RedisClient

NewRedisClient creates a new RedisClient. Param address is the net address of the Redis server. Param password is the password required to connect. It may be blank, but shouldn't be in production. Param db is the id of the Redis database.

func (*RedisClient) IngestObjectGet

func (c *RedisClient) IngestObjectGet(workItemID int64, objIdentifier string) (string, error)

IngestObjectGet returns a JSON string representing an ingest object and its associated work results.

func (*RedisClient) KeyExists

func (c *RedisClient) KeyExists(workItemID int64) bool

KeyExists returns true if the specified key exists in our Redis DB.

func (*RedisClient) List

func (c *RedisClient) List(pattern string) ([]string, error)

List returns up to the first 500 keys in the Redis DB matching the specified pattern. The 500 limit is to prevent overload if our Redis DB fills up with lots of entries.

Realistically, we will almost never have more than a few dozen keys at any given time, since Redis data is deleted as soon as processing completes. Each key is a WorkItem.ID in string form.

func (*RedisClient) Ping

func (c *RedisClient) Ping() (string, error)

Ping pings the Redis server. It should return "PONG" if the server is running and we can connect.

func (*RedisClient) RestorationObjectGet

func (c *RedisClient) RestorationObjectGet(workItemID int64, objIdentifier string) (string, error)

RestorationObjectGet returns a JSON string representing the specified restoration object.

func (*RedisClient) SaveItem

func (c *RedisClient) SaveItem(workItemID int64, field, value string) error

SaveItem saves value to Redis. This is used only for testing.

func (*RedisClient) WorkItemDelete

func (c *RedisClient) WorkItemDelete(workItemID int64) (int64, error)

WorkItemDelete deletes the Redis copy (NOT the Registry copy) of a WorkItem, along with its associated IngestObject and IngestFile records. This is dangerous and should be called only in two cases:

  1. We want to delete old ingest data from Redis after a failed ingest that we know we will never retry. This is essentially a cleanup operation.
  1. We are forcing an item back to the very first step of ingest or restoration, and we want the workers to redo all work from scratch instead of relying on the already completed work recorded in Redis. This is extremely rare, but it will come up a few times a year.

type SESClient

type SESClient struct {
	FromAddress    string
	ServiceEnabled bool
	Session        *session.Session
	Service        *ses.SES
	// contains filtered or unexported fields
}

func NewSESClient

func NewSESClient(serviceEnabled bool, awsRegion, sesUser, sesPassword, fromAddress string, logger zerolog.Logger) *SESClient

func (*SESClient) Send

func (client *SESClient) Send(emailAddress, subject, message string) error

Send sends an email to the specified address.

type SNSClient

type SNSClient struct {
	ServiceEnabled bool
	Session        *session.Session
	Service        *sns.SNS
	// contains filtered or unexported fields
}

func NewSNSClient

func NewSNSClient(serviceEnabled bool, awsRegion, sesUser, sesPassword string, logger zerolog.Logger) *SNSClient

func (*SNSClient) SendSMS

func (client *SNSClient) SendSMS(phoneNumber, message string) error

SendSMS sends an SMS message the specified phone number. Phone should begin with +1 for US.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL