diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..1305de8 --- /dev/null +++ b/.envrc @@ -0,0 +1,4 @@ +if ! has nix_direnv_version || ! nix_direnv_version 2.2.0; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.0/direnvrc" "sha256-5EwyKnkJNQeXrRkYbwwRBcXbibosCJqyIUuz9Xq+LRc=" +fi +use flake diff --git a/.gitignore b/.gitignore index 979847d..8a90e75 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ _obj _test bin vendor/ +/.direnv/ # Architecture specific extensions/prefixes *.[568vq] diff --git a/.mailmap b/.mailmap index b99c3fa..7543547 100644 --- a/.mailmap +++ b/.mailmap @@ -3,3 +3,6 @@ Seán C McCord Ulexus Sheena Artrip sheenobu Sharon Allsup system_user Laurel Lawson llccs +Torrey Searle tsearle +Torrey Searle tsearle +Michael Hall mikehall76 diff --git a/CONTRIBUTORS b/CONTRIBUTORS index ff0db02..ad9f0d8 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -9,13 +9,11 @@ Seán C McCord Sharon Allsup Sheena Artrip Stamkulov Sattar +Torrey Searle Vipul William Edward Lee goharahmed -mikehall76 mtryfoss realrainer <18657361+realrainer@users.noreply.github.com> seanchann serfreeman1337 -tsearle -tsearle diff --git a/application.go b/application.go index a05996a..2054531 100644 --- a/application.go +++ b/application.go @@ -3,7 +3,6 @@ package ari // Application represents a communication path interacting with an Asterisk // server for application-level resources type Application interface { - // List returns the list of applications in Asterisk, optionally using the key for filtering List(*Key) ([]*Key, error) @@ -72,10 +71,10 @@ func (ah *ApplicationHandle) Data() (ad *ApplicationData, err error) { // Subscribe subscribes the application to an event source // event source may be one of: -// - channel: -// - bridge: -// - endpoint:/ (e.g. SIP/102) -// - deviceState: +// - channel: +// - bridge: +// - endpoint:/ (e.g. SIP/102) +// - deviceState: func (ah *ApplicationHandle) Subscribe(eventSource string) (err error) { err = ah.a.Subscribe(ah.key, eventSource) return diff --git a/ari.proto b/ari.proto index 0cbe4e2..d431bd8 100644 --- a/ari.proto +++ b/ari.proto @@ -4,20 +4,16 @@ package asterisk.ari; option go_package = "ari"; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; // Key identifies a unique resource in the system message Key { - // NOTE: we build our own stringer - option (gogoproto.goproto_stringer) = false; - // Kind indicates the type of resource the Key points to. e.g., "channel", // "bridge", etc. string kind = 1; // ID indicates the unique identifier of the resource - string id = 2 [(gogoproto.customname) = "ID"]; + string id = 2; // Node indicates the unique identifier of the Asterisk node on which the // resource exists or will be created @@ -32,9 +28,6 @@ message Key { // CallerID describes the name and number which identifies the caller to other endpoints message CallerID { - // NOTE: we build our own stringer - option (gogoproto.goproto_stringer) = false; - // Name is the name of the party string name = 1; @@ -48,7 +41,7 @@ message ChannelData { Key key = 1; // Id is the unique ID for this channel (AMI-style) - string id = 2 [(gogoproto.customname) = "ID"]; + string id = 2; // Name is the name of this channel (tect/name-id) string name = 3; @@ -75,7 +68,7 @@ message ChannelData { string language = 10; // ChannelVars is the list of channel variables set on this channel - map channelvars = 11 [(gogoproto.customname) = "ChannelVars"]; + map channel_vars = 11; } diff --git a/asterisk.go b/asterisk.go index b259350..6f842db 100644 --- a/asterisk.go +++ b/asterisk.go @@ -3,7 +3,6 @@ package ari // Asterisk represents a communication path for // the Asterisk server for system-level resources type Asterisk interface { - // Info gets data about the asterisk system Info(key *Key) (*AsteriskInfo, error) @@ -41,7 +40,7 @@ type BuildInfo struct { // ConfigInfo describes information about the Asterisk configuration type ConfigInfo struct { DefaultLanguage string `json:"default_language"` - MaxChannels int `json:"max_channels,omitempty"` //omitempty denotes an optional field, meaning the field may not be present if no value is assigned. + MaxChannels int `json:"max_channels,omitempty"` // omitempty denotes an optional field, meaning the field may not be present if no value is assigned. MaxLoad float64 `json:"max_load,omitempty"` MaxOpenFiles int `json:"max_open_files,omitempty"` Name string `json:"name"` // Asterisk system name @@ -68,7 +67,6 @@ type SystemInfo struct { // AsteriskVariables is an interface to interact with Asterisk global variables type AsteriskVariables interface { - // Get returns the value of the given variable; the ID field of the Key is the variable name Get(key *Key) (string, error) diff --git a/bridge.go b/bridge.go index 6e5f6dc..c7c6f3c 100644 --- a/bridge.go +++ b/bridge.go @@ -3,7 +3,6 @@ package ari // Bridge represents a communication path to an // Asterisk server for working with bridge resources type Bridge interface { - // Create creates a bridge Create(key *Key, btype string, name string) (*BridgeHandle, error) @@ -78,7 +77,6 @@ type BridgeData struct { // BridgeAddChannelOptions describes additional options to be applied to a channel when it is joined to a bridge type BridgeAddChannelOptions struct { - // AbsorbDTMF indicates that DTMF coming from this channel will not be passed through to the bridge AbsorbDTMF bool diff --git a/callerid.go b/callerid.go index 7be713d..20fce49 100644 --- a/callerid.go +++ b/callerid.go @@ -2,7 +2,7 @@ package ari import "errors" -//NOTE: Direct translation from ARI client 2.0 +// NOTE: Direct translation from ARI client 2.0 // CallerIDFromString interprets the provided string // as a CallerID. Usually, this string will be of the following forms: @@ -10,7 +10,7 @@ import "errors" // - // - "Name" number func CallerIDFromString(src string) (*CallerID, error) { - //TODO: implement complete callerid parser + // TODO: implement complete callerid parser return nil, errors.New("CallerIDFromString not yet implemented") } diff --git a/client.go b/client.go index 6f469f2..6e14b9c 100644 --- a/client.go +++ b/client.go @@ -4,7 +4,6 @@ package ari // with an Asterisk ARI server. It is agnostic to transport // and implementation. type Client interface { - // ApplicationName returns the ARI application name by which this client is connected ApplicationName() string diff --git a/client/native/application.go b/client/native/application.go index e8ccbec..213b75d 100644 --- a/client/native/application.go +++ b/client/native/application.go @@ -3,8 +3,9 @@ package native import ( "fmt" - "github.com/CyCoreSystems/ari/v6" "github.com/rotisserie/eris" + + "github.com/CyCoreSystems/ari/v6" ) // Application is a native implementation of ARI's Application functions diff --git a/client/native/asterisk.go b/client/native/asterisk.go index cd06971..86a4a33 100644 --- a/client/native/asterisk.go +++ b/client/native/asterisk.go @@ -3,8 +3,9 @@ package native import ( "fmt" - "github.com/CyCoreSystems/ari/v6" "github.com/rotisserie/eris" + + "github.com/CyCoreSystems/ari/v6" ) // Asterisk provides the ARI Asterisk accessors for a native client diff --git a/client/native/client.go b/client/native/client.go index 2727ea3..dd0b421 100644 --- a/client/native/client.go +++ b/client/native/client.go @@ -9,20 +9,20 @@ import ( "sync" "time" + "github.com/inconshreveable/log15" + "github.com/rotisserie/eris" + "golang.org/x/net/websocket" + "github.com/CyCoreSystems/ari/v6" "github.com/CyCoreSystems/ari/v6/rid" "github.com/CyCoreSystems/ari/v6/stdbus" - "github.com/rotisserie/eris" - - "github.com/inconshreveable/log15" - "golang.org/x/net/websocket" ) // Logger defaults to a discard handler (null output). // If you wish to enable logging, you can set your own // handler like so: -// ari.Logger.SetHandler(log15.StderrHandler) // +// ari.Logger.SetHandler(log15.StderrHandler) var Logger = log15.New() func init() { diff --git a/client/native/config.go b/client/native/config.go index 03fb885..a67af4a 100644 --- a/client/native/config.go +++ b/client/native/config.go @@ -1,8 +1,9 @@ package native import ( - "github.com/CyCoreSystems/ari/v6" "github.com/rotisserie/eris" + + "github.com/CyCoreSystems/ari/v6" ) // Config provides the ARI Configuration accessors for a native client diff --git a/client/native/logging.go b/client/native/logging.go index 230f995..53e97d2 100644 --- a/client/native/logging.go +++ b/client/native/logging.go @@ -1,8 +1,9 @@ package native import ( - "github.com/CyCoreSystems/ari/v6" "github.com/rotisserie/eris" + + "github.com/CyCoreSystems/ari/v6" ) // Logging provides the ARI Logging accessors for a native client diff --git a/config.go b/config.go index 91b1fcf..d067734 100644 --- a/config.go +++ b/config.go @@ -9,7 +9,6 @@ import ( // Config represents a transport to the asterisk // config ARI resource. type Config interface { - // Get gets the reference to a config object Get(key *Key) *ConfigHandle @@ -40,7 +39,7 @@ func (cd *ConfigData) ID() string { return fmt.Sprintf("%s/%s/%s", cd.Class, cd.Type, cd.Name) } -//ConfigTupleList wrap a list for asterisk ari require. +// ConfigTupleList wrap a list for asterisk ari require. type ConfigTupleList struct { Fields []ConfigTuple `json:"fields"` } diff --git a/datetime_test.go b/datetime_test.go index 76cef74..d8f1b66 100644 --- a/datetime_test.go +++ b/datetime_test.go @@ -16,7 +16,7 @@ var dtMarshalTests = []struct { Output string HasError bool }{ - {dtTest{DateTime(time.Date(2005, 02, 04, 13, 12, 6, 0, time.UTC))}, `{"dt":"2005-02-04T13:12:06.000+0000"}`, false}, + {dtTest{DateTime(time.Date(2005, 0o2, 0o4, 13, 12, 6, 0, time.UTC))}, `{"dt":"2005-02-04T13:12:06.000+0000"}`, false}, } var dtUnmarshalTests = []struct { @@ -24,7 +24,7 @@ var dtUnmarshalTests = []struct { Output dtTest HasError bool }{ - {`{"dt":"2005-02-04T13:12:06.000+0000"}`, dtTest{DateTime(time.Date(2005, 02, 04, 13, 12, 6, 0, time.UTC))}, false}, + {`{"dt":"2005-02-04T13:12:06.000+0000"}`, dtTest{DateTime(time.Date(2005, 0o2, 0o4, 13, 12, 6, 0, time.UTC))}, false}, {`{"dt":"2x05-02-04T13:12:06.000+0000"}`, dtTest{}, true}, {`{"dt": 0 }`, dtTest{}, true}, } diff --git a/endpoint.go b/endpoint.go index cf5fbbe..7f4a255 100644 --- a/endpoint.go +++ b/endpoint.go @@ -11,7 +11,6 @@ const EndpointIDSeparator = "|" // TODO: confirm separator isn't terrible // Endpoint represents a communication path to an Asterisk server // for endpoint resources type Endpoint interface { - // List lists the endpoints List(filter *Key) ([]*Key, error) diff --git a/events_gen.go b/events_gen.go index 47b416b..74756b5 100644 --- a/events_gen.go +++ b/events_gen.go @@ -100,7 +100,6 @@ func init() { Events.StasisEnd = "StasisEnd" Events.StasisStart = "StasisStart" Events.TextMessageReceived = "TextMessageReceived" - } // DecodeEvent converts a JSON-encoded event to an ARI event. diff --git a/ext/bridgemon/bridgemon.go b/ext/bridgemon/bridgemon.go index adf8e18..7e84f7a 100644 --- a/ext/bridgemon/bridgemon.go +++ b/ext/bridgemon/bridgemon.go @@ -135,7 +135,6 @@ func (m *Monitor) Key() *ari.Key { // destoyed. // // NOTE: the user should NEVER close this channel directly. -// func (m *Monitor) Watch() <-chan *ari.BridgeData { ch := make(chan *ari.BridgeData) diff --git a/ext/play/logger.go b/ext/play/logger.go index 572b06e..4b8da3c 100644 --- a/ext/play/logger.go +++ b/ext/play/logger.go @@ -5,8 +5,8 @@ import "github.com/inconshreveable/log15" // Logger defaults to a discard handler (null output). // If you wish to enable logging, you can set your own // handler like so: -// ari.Logger.SetHandler(log15.StderrHandler) // +// ari.Logger.SetHandler(log15.StderrHandler) var Logger = log15.New() func init() { diff --git a/ext/play/options.go b/ext/play/options.go index c6db62f..f491731 100644 --- a/ext/play/options.go +++ b/ext/play/options.go @@ -332,12 +332,11 @@ func PlaybackStartTimeout(timeout time.Duration) OptionFunc { // DigitTimeouts sets the digit timeouts. Passing a negative value to any of these indicates that the default value (shown in parentheses below) should be used. // -// - First digit timeout (4 sec): The time (after the stop of the audio) to wait for the first digit to be received +// - First digit timeout (4 sec): The time (after the stop of the audio) to wait for the first digit to be received // -// - Inter digit timeout (3 sec): The time (after receiving a digit) to wait for the _next_ digit to be received -// -// - Overall digit timeout (3 min): The maximum amount of time to wait (after the stop of the audio) for digits to be received, regardless of the digit frequency +// - Inter digit timeout (3 sec): The time (after receiving a digit) to wait for the _next_ digit to be received // +// - Overall digit timeout (3 min): The maximum amount of time to wait (after the stop of the audio) for digits to be received, regardless of the digit frequency func DigitTimeouts(first, inter, overall time.Duration) OptionFunc { return func(o *Options) error { if first >= 0 { diff --git a/ext/play/play_test.go b/ext/play/play_test.go index d2d7248..aaafd01 100644 --- a/ext/play/play_test.go +++ b/ext/play/play_test.go @@ -6,10 +6,10 @@ import ( "testing" "time" + "github.com/stretchr/testify/mock" + "github.com/CyCoreSystems/ari/v6" "github.com/CyCoreSystems/ari/v6/client/arimocks" - - "github.com/stretchr/testify/mock" ) type playStagedTest struct { diff --git a/ext/play/sequence.go b/ext/play/sequence.go index 5a26b23..2091197 100644 --- a/ext/play/sequence.go +++ b/ext/play/sequence.go @@ -4,9 +4,10 @@ import ( "context" "time" + "github.com/rotisserie/eris" + "github.com/CyCoreSystems/ari/v6" "github.com/CyCoreSystems/ari/v6/rid" - "github.com/rotisserie/eris" ) // sequence represents an audio sequence playback session diff --git a/ext/play/sequence_test.go b/ext/play/sequence_test.go index 3b015a6..6b517a4 100644 --- a/ext/play/sequence_test.go +++ b/ext/play/sequence_test.go @@ -6,10 +6,10 @@ import ( "testing" "time" + "github.com/stretchr/testify/mock" + "github.com/CyCoreSystems/ari/v6" "github.com/CyCoreSystems/ari/v6/client/arimocks" - - "github.com/stretchr/testify/mock" ) type sequenceTest struct { diff --git a/ext/play/session.go b/ext/play/session.go index b2a8640..45d9d92 100644 --- a/ext/play/session.go +++ b/ext/play/session.go @@ -242,7 +242,7 @@ func (s *playSession) Stop() { } s.mu.Lock() - + if !s.closed { s.closed = true close(s.done) diff --git a/ext/record/logger.go b/ext/record/logger.go index b69526c..bc2d7f8 100644 --- a/ext/record/logger.go +++ b/ext/record/logger.go @@ -5,8 +5,8 @@ import "github.com/inconshreveable/log15" // Logger defaults to a discard handler (null output). // If you wish to enable logging, you can set your own // handler like so: -// ari.Logger.SetHandler(log15.StderrHandler) // +// ari.Logger.SetHandler(log15.StderrHandler) var Logger = log15.New() func init() { diff --git a/ext/record/record.go b/ext/record/record.go index 67e4254..27b0b15 100644 --- a/ext/record/record.go +++ b/ext/record/record.go @@ -7,9 +7,10 @@ import ( "sync" "time" + "github.com/rotisserie/eris" + "github.com/CyCoreSystems/ari/v6" "github.com/CyCoreSystems/ari/v6/rid" - "github.com/rotisserie/eris" ) var ( diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c5ab91b --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1693663421, + "narHash": "sha256-ImMIlWE/idjcZAfxKK8sQA7A1Gi/O58u5/CJA+mxvl8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e56990880811a451abd32515698c712788be5720", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..2640263 --- /dev/null +++ b/flake.nix @@ -0,0 +1,66 @@ +{ + description = "mono devshell"; + inputs = { + #nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }@inputs: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + write-mailmap = pkgs.buildGoModule rec { + name = "write_mailmap"; + src = pkgs.fetchFromGitHub { + owner = "CyCoreSystems"; + repo = "write_mailmap"; + rev = "v0.3.0"; + sha256 = "sha256-LzLLEtsWLeIOnlY1pygAOhTsGiWfISnuVF/jeoHHzaw="; + }; + + # There are no upstream packages, so vendor hash is null. + vendorHash = null; + }; + + gci = pkgs.buildGoModule rec { + name = "gci"; + src = pkgs.fetchFromGitHub { + owner = "daixiang0"; + repo = "gci"; + rev = "v0.10.1"; + sha256 = "sha256-/YR61lovuYw+GEeXIgvyPbesz2epmQVmSLWjWwKT4Ag="; + }; + + # Switch to fake vendor sha for upgrades: + #vendorSha256 = pkgs.lib.fakeSha256; + vendorSha256 = "sha256-g7htGfU6C2rzfu8hAn6SGr0ZRwB8ZzSf9CgHYmdupE8="; + }; + + cclint = pkgs.writeScriptBin "lint" '' + cd $(git rev-parse --show-toplevel) + write_mailmap > CONTRIBUTORS + gofumpt -w . + gci write --skip-generated -s standard -s default -s "Prefix(github.com/CyCoreSystems)" . + golangci-lint run + ''; + + ccmocks = pkgs.writeScriptBin "gen-mocks" '' + rm -Rf vendor/ client/arimocks + mockery --name . --outpkg arimocks --output client/arimocks + ''; + in + { + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + buf + cclint + ccmocks + gci + go-tools + write-mailmap + ]; + }; + }); +} diff --git a/liveRecording.go b/liveRecording.go index 5aefd9e..001f9af 100644 --- a/liveRecording.go +++ b/liveRecording.go @@ -5,7 +5,6 @@ import "sync" // LiveRecording represents a communication path interacting with an Asterisk // server for live recording resources type LiveRecording interface { - // Get gets the Recording by type Get(key *Key) *LiveRecordingHandle diff --git a/logger.go b/logger.go index 4b1ef17..fcd3221 100644 --- a/logger.go +++ b/logger.go @@ -5,8 +5,8 @@ import "github.com/inconshreveable/log15" // Logger defaults to a discard handler (null output). // If you wish to enable logging, you can set your own // handler like so: -// ari.Logger.SetHandler(log15.StderrHandler) // +// ari.Logger.SetHandler(log15.StderrHandler) var Logger = log15.New() func init() { diff --git a/logging.go b/logging.go index f70a151..0ec1467 100644 --- a/logging.go +++ b/logging.go @@ -3,7 +3,6 @@ package ari // Logging represents a communication path to an // Asterisk server for working with logging resources type Logging interface { - // Create creates a new log. The levels are a comma-separated list of // logging levels on which this channel should operate. The name of the // channel should be the key's ID. @@ -43,7 +42,7 @@ type LogData struct { Status string `json:"status"` } -// NewLogHandle builds a new log handle given the `Key` and `Logging`` client +// NewLogHandle builds a new log handle given the `Key` and `Logging` client func NewLogHandle(key *Key, l Logging) *LogHandle { return &LogHandle{ key: key, diff --git a/mailbox.go b/mailbox.go index 3c85ff0..0471fdd 100644 --- a/mailbox.go +++ b/mailbox.go @@ -3,7 +3,6 @@ package ari // Mailbox is the communication path to an Asterisk server for // operating on mailbox resources type Mailbox interface { - // Get gets a handle to the mailbox for further operations Get(key *Key) *MailboxHandle diff --git a/originate.go b/originate.go index 5e86349..b433fed 100644 --- a/originate.go +++ b/originate.go @@ -2,7 +2,6 @@ package ari // OriginateRequest defines the parameters for the creation of a new Asterisk channel type OriginateRequest struct { - // Endpoint is the name of the Asterisk resource to be used to create the // channel. The format is tech/resource. // diff --git a/playback.go b/playback.go index 1251bf7..09e4d22 100644 --- a/playback.go +++ b/playback.go @@ -3,7 +3,6 @@ package ari // Playback represents a communication path for interacting // with an Asterisk server for playback resources type Playback interface { - // Get gets the handle to the given playback ID Get(key *Key) *PlaybackHandle diff --git a/sound.go b/sound.go index 1592523..3660e5f 100644 --- a/sound.go +++ b/sound.go @@ -3,7 +3,6 @@ package ari // Sound represents a communication path to // the asterisk server for Sound resources type Sound interface { - // List returns available sounds limited by the provided filters. // Valid filters are "lang", "format", and nil (no filter) List(filters map[string]string, keyFilter *Key) ([]*Key, error) diff --git a/storedRecording.go b/storedRecording.go index 093b709..b50cf2f 100644 --- a/storedRecording.go +++ b/storedRecording.go @@ -3,7 +3,6 @@ package ari // StoredRecording represents a communication path interacting with an Asterisk // server for stored recording resources type StoredRecording interface { - // List lists the recordings List(filter *Key) ([]*Key, error) diff --git a/textMessage.go b/textMessage.go index 372b0d7..6983002 100644 --- a/textMessage.go +++ b/textMessage.go @@ -2,7 +2,6 @@ package ari // TextMessage needs some verbiage here type TextMessage interface { - // Send() sends a text message to an endpoint Send(from, tech, resource, body string, vars map[string]string) error