Documentation ¶
Overview ¶
Package arc provides the necessary calls to publish notifications to the arc system Basic Usage sample:
Create a new client and set the base url for the service client := arc.NewClient("https://example.com") You also have the ability to set the URL and path by using SetBaseURL and SetPath Create a request, replace with the appropriate values for eventCode and publishKey req := arc.CreateArcsignalEventPublishRequest("eventCode", "publishKey", err) Add at least one request, can add several client.AddRequest(req) Send the request if err := client.Send(); err != nil { return err }
Index ¶
- Constants
- func CleanExpiredGrants(db *sql.Connection, c *Client) (err error)
- func DataProcessorSkip(db *sql.Connection, d *model.Data) (err error)
- func GetGrant(db *sql.Connection, token string) (dg *model.DeploymentGrant, err error)
- func GetMigrationList() (ml *migration.List)
- type Client
- func (c *Client) AddRequest(req RequestItem)
- func (c *Client) ArcimedesUserGetByUsername(username string) (cu *model.CoreUser, err error)
- func (c *Client) CartGetCustomerByUsername(storeCode, username string) (cust *model.CoreUser, err error)
- func (c *Client) Close() (err error)
- func (c *Client) Connect() (err error)
- func (c *Client) CoreUserGetByUsername(username string) (cu *model.CoreUser, err error)
- func (c *Client) Flush() (resList *ResponseList, err error)
- func (c *Client) GetDeployment() (d *Deployment)
- func (c *Client) GrantLogin(credentialID int, username, password string) (g *Grant, err error)
- func (c *Client) GrantRevoke(accessToken string) (err error)
- func (c *Client) GrantUserinfo(accessToken string) (gui *GrantUserinfo, err error)
- func (c *Client) Log(ee *e.ExtendedError)
- func (c *Client) RegisterArcimedesUser(iu *model.CoreUser, password string, retry bool) (cu *model.CoreUser, err error)
- func (c *Client) RegisterCartCustomer(storeCode string, iu *model.CoreUser, password string, retry bool) (cust *model.CoreUser, err error)
- func (c *Client) RegisterCoreUser(iu *model.CoreUser, password string, retry bool) (cu *model.CoreUser, err error)
- func (c *Client) Send(reqItemList []*RequestItem) (resList *ResponseList, err error)
- func (c *Client) SendArcsignalEventPublish(eventCode, publishKey string, eventErr interface{}) (err error)
- func (c *Client) SetBaseURL(url string)
- func (c *Client) SetID(id int)
- func (c *Client) SetPath(path string)
- func (c *Client) SetStoreCode(storeCode string)
- func (c *Client) SetToken(token string)
- func (c *Client) SetUsername(username string)
- func (c *Client) SetVersion(version int)
- type DataHandler
- type DataProcessor
- type Deployment
- type DeploymentNotify
- type Grant
- type GrantUserinfo
- type RequestItem
- type RequestItemOption
- type RequestList
- type Response
- type ResponseList
Constants ¶
const ( // DefaultPath is the default path to the arc notification service DefaultPath = "/services/" // DefaultVersion is the default version number to use in the request DefaultVersion = 1 // DefaultID is the default id number to use in the request DefaultID = 0 ECode040101 = e.Code0401 + "01" ECode040102 = e.Code0401 + "02" ECode040103 = e.Code0401 + "03" ECode040104 = e.Code0401 + "04" ECode040105 = e.Code0401 + "05" ECode040106 = e.Code0401 + "06" ECode040107 = e.Code0401 + "07" ECode040108 = e.Code0401 + "08" ECode040109 = e.Code0401 + "09" ECode04010A = e.Code0401 + "0A" ECode04010B = e.Code0401 + "0B" ECode04010C = e.Code0401 + "0C" ECode04010D = e.Code0401 + "0D" ECode04010E = e.Code0401 + "0E" ECode04010F = e.Code0401 + "0F" ECode04010G = e.Code0401 + "0G" ECode04010H = e.Code0401 + "0H" ECode04010I = e.Code0401 + "0I" ECode04010J = e.Code0401 + "0J" ECode04010K = e.Code0401 + "0K" )
const ( ECode040201 = e.Code0402 + "01" ECode040202 = e.Code0402 + "02" ECode040203 = e.Code0402 + "03" ECode040204 = e.Code0402 + "04" ECode040205 = e.Code0402 + "05" ECode040206 = e.Code0402 + "06" ECode040207 = e.Code0402 + "07" ECode040208 = e.Code0402 + "08" )
const ( ECode040301 = e.Code0403 + "01" ECode040302 = e.Code0403 + "02" ECode040303 = e.Code0403 + "03" ECode040304 = e.Code0403 + "04" ECode040305 = e.Code0403 + "05" ECode040306 = e.Code0403 + "06" ECode040307 = e.Code0403 + "07" ECode040308 = e.Code0403 + "08" )
const ( ECode040401 = e.Code0404 + "01" ECode040402 = e.Code0404 + "02" ECode040403 = e.Code0404 + "03" ECode040404 = e.Code0404 + "04" ECode040405 = e.Code0404 + "05" ECode040406 = e.Code0404 + "06" ECode040407 = e.Code0404 + "07" ECode040408 = e.Code0404 + "08" )
const ( ECode040701 = e.Code0407 + "01" ECode040702 = e.Code0407 + "02" ECode040703 = e.Code0407 + "03" )
const ( ECode040501 = e.Code0405 + "01" ECode040502 = e.Code0405 + "02" ECode040503 = e.Code0405 + "03" ECode040504 = e.Code0405 + "04" ECode040505 = e.Code0405 + "05" ECode040506 = e.Code0405 + "06" )
const ( ECode040601 = e.Code0406 + "01" ECode040602 = e.Code0406 + "02" ECode040603 = e.Code0406 + "03" ECode040604 = e.Code0406 + "04" )
const ( ECode040901 = e.Code0409 + "01" ECode040902 = e.Code0409 + "02" ECode040903 = e.Code0409 + "03" ECode040904 = e.Code0409 + "04" ECode040905 = e.Code0409 + "05" ECode040906 = e.Code0409 + "06" ECode040907 = e.Code0409 + "07" ECode040908 = e.Code0409 + "08" ECode040909 = e.Code0409 + "09" ECode04090A = e.Code0409 + "0A" ECode04090B = e.Code0409 + "0B" ECode04090C = e.Code0409 + "0C" )
const ( ECode040801 = e.Code0408 + "01" ECode040802 = e.Code0408 + "02" ECode040803 = e.Code0408 + "03" ECode040804 = e.Code0408 + "04" ECode040805 = e.Code0408 + "05" ECode040806 = e.Code0408 + "06" ECode040807 = e.Code0408 + "07" ECode040808 = e.Code0408 + "08" ECode040809 = e.Code0408 + "09" ECode04080A = e.Code0408 + "0A" ECode04080B = e.Code0408 + "0B" )
const ( E01FAAE_UserAlreadyExists = "E01FAAE" E01F1A8_AuthorizationFailed = "E01F1A8" // Not logged in error E01FWA8_InvalidGrant = "E01FWA8" // Invalid grant error E01FAAP_InvalidGrantLogin = "E01FAAP" // Invalid user for oauth2.Grant.login )
These constants refer to some possible error codes that come from an arc deployment API call (not within this library)
const CHANNEL_ARC_DEPLOYMENT_NOTIFY = "arc_deployment_notify"
const (
ECode040A01 = e.Code040A + "01"
)
const (
MIGRATION_CODE = "arc"
)
Variables ¶
This section is empty.
Functions ¶
func CleanExpiredGrants ¶
func CleanExpiredGrants(db *sql.Connection, c *Client) (err error)
CleanExpiredGrants removes all grants where the refresh token has expired and is no longer usable. Note, the token should also be unusable as refresh tokens are periodically rotated when fetching new tokens
func DataProcessorSkip ¶
func DataProcessorSkip(db *sql.Connection, d *model.Data) (err error)
DataProcessorSkip marks the arc_data record as pending (skipping so it will process again)
func GetGrant ¶
func GetGrant(db *sql.Connection, token string) (dg *model.DeploymentGrant, err error)
GetGrant returns the grant associated with the token if it exists
func GetMigrationList ¶
GetMigrationList returns this packages migration list
Types ¶
type Client ¶
type Client struct { BaseURL string Path string Version int ID int Username string Token string RequestList []*RequestItem // contains filtered or unexported fields }
Client handles the posting/making arc requests to an arc API server
func NewClientFromDeployment ¶
NewClientFromDeployment initializes a client from the arc_deployments table
func (*Client) AddRequest ¶
func (c *Client) AddRequest(req RequestItem)
AddRequest adds a request to the list of requests to send to arc
func (*Client) ArcimedesUserGetByUsername ¶
ArcimedesUserGetByUsername fetches the arcimedes user by username
func (*Client) CartGetCustomerByUsername ¶
func (c *Client) CartGetCustomerByUsername(storeCode, username string) ( cust *model.CoreUser, err error)
CartGetCustomerByUsername fetches the customer by username from the specified store
func (*Client) CoreUserGetByUsername ¶
CoreUserGetByUsername fetches the core user by username
func (*Client) Flush ¶
func (c *Client) Flush() (resList *ResponseList, err error)
Flush sends whatever is in the current queue
func (*Client) GetDeployment ¶
func (c *Client) GetDeployment() (d *Deployment)
GetDeployment return the currently set deployment
func (*Client) GrantLogin ¶
GrantLogin makes a call to login on behalf of an arc user. If successful, it will return a grant, with an access token and, if configured to use, a refresh token. The clientId used in this call must be from the configured arc deployment and will be tied to one of the arc apps (core, cart or arcimedes). Thus, if successful, the user that the grant is for will also be tied to that app (i.e. a core user, a cart customer or an arcimedes user). The grant will also be stored in the arc_deployment_grant table, along with a unique session so that a user in the same session can re-use the grant and the system can refresh the access token as needed (instead of generating new ones every time).
func (*Client) GrantRevoke ¶
GrantRevoke removes the access token from the arc_deployment_grant table and makes a call to the associated arc deployment to revoke the grant (access token)
func (*Client) GrantUserinfo ¶
func (c *Client) GrantUserinfo(accessToken string) (gui *GrantUserinfo, err error)
GrantUserinfo makes a call oauth2.Grant.userinfo with the specified access token to fetch the user info associated with the oauth access token
func (*Client) Log ¶
func (c *Client) Log(ee *e.ExtendedError)
Log sends the extended error to the configured arc log. If not configured does nothing
func (*Client) RegisterArcimedesUser ¶
func (c *Client) RegisterArcimedesUser(iu *model.CoreUser, password string, retry bool) (cu *model.CoreUser, err error)
RegisterArcimedesUser attempts to create the arcimedes user in arc. If the user already exists in arc, will fetch the arc user id (by the passed username) and then make the call to update it. This should only be called when registering a new arcimedes user, as it will reset the password
func (*Client) RegisterCartCustomer ¶
func (c *Client) RegisterCartCustomer(storeCode string, iu *model.CoreUser, password string, retry bool) (cust *model.CoreUser, err error)
RegisterCartCustomer attempts to create the cart customer in arc. If the customer already exists in arc, will fetch the arc user id (by the passed username) and then make the call to update it. This should only be called when registering a new cart customer, as it will reset the password
func (*Client) RegisterCoreUser ¶
func (c *Client) RegisterCoreUser(iu *model.CoreUser, password string, retry bool) (cu *model.CoreUser, err error)
RegisterCoreUser attempts to create the core user in arc. If the user already exists in arc, will fetch the arc user id (by the passed username) and then make the call to update it. This should only be called when registering a new core user, as it will reset the password
func (*Client) Send ¶
func (c *Client) Send(reqItemList []*RequestItem) (resList *ResponseList, err error)
Send performs the actual publish requet to the arc notification service
func (*Client) SendArcsignalEventPublish ¶
func (c *Client) SendArcsignalEventPublish(eventCode, publishKey string, eventErr interface{}) (err error)
SendArcsignalEventPublish creates and sends an arcsignal event publish API call
func (*Client) SetBaseURL ¶
SetBaseURL deprecated - sets the base URL to the notification service
func (*Client) SetStoreCode ¶
SetStoreCode sets the deployment's store code
func (*Client) SetUsername ¶
SetUsername sets the usename to use
func (*Client) SetVersion ¶
SetVersion sets the version for the request to the notification service
type DataHandler ¶
type DataHandler struct { Err error // contains filtered or unexported fields }
DataHandler handler for deployment data events
func NewDataHandler ¶
func NewDataHandler(db *sql.Connection, client *Client) (adh *DataHandler)
NewDataHandler creates a new Data Handler for saving arc data events into the arc_data table
func (*DataHandler) Publish ¶
Publish attempts to save the published data. It will first authorize the call and if authorized, will save the data into the arc_data table. If it returns an error, then something bad happened and the calling method should log the error. If it returns anything but an empty message, then something was wrong with the call
type DataProcessor ¶
type DataProcessor struct {
// contains filtered or unexported fields
}
DataProcessor reads all pending records in the arc_data table and calls the app specific function to process it, then marks them all as processed.
func NewDataProcessor ¶
func NewDataProcessor(db *sql.Connection, f func(*model.Data) error, orderList []model.DataType) (dp *DataProcessor)
NewDataProcess returns a new instance of a data processor
f: defines the function that will be called to handle each record orderList: if specified, defines the order in which to fetch the records based on the type
func (*DataProcessor) Run ¶
func (dp *DataProcessor) Run() (err error)
Run iterates through all pending records in the arc_data table and calls the passed data handling function. Then marks all of the read records as processed.
type Deployment ¶
type Deployment struct { DB *sql.Connection Model *model.Deployment Listener *DeploymentNotify StoreCode string }
func NewDeployment ¶
func NewDeployment(db *sql.Connection, cp *sql.ConnParam, deploymentCode string) (d *Deployment, err error)
NewDeployment initializes a new deployment and returns it
func (*Deployment) Refresh ¶
func (d *Deployment) Refresh()
Refresh updates this objects properties from the corresponding record in the database
func (*Deployment) UpdateGrant ¶
func (d *Deployment) UpdateGrant(g *Grant) (err error)
UpdateGrant updates this deployment's database record with the new grant info (token/expiry and refresh token/expiry)
type DeploymentNotify ¶
type DeploymentNotify struct { Listener *pq.Listener Failed chan error Notify func(deploymentCode string) }
DeploymentNotify use to listen for change events to records in the arc_deployment table. If an insert or update occurs, the event will be triggered with the deployment code passed as the event data. It is the responsibility of the creater of this to do something with that deployment code (i.e. lookup the new data if it is using that code and update accordingly)
func NewDeploymentNotify ¶
func NewDeploymentNotify(cp *sql.ConnParam) (dn *DeploymentNotify, err error)
NewDeploymentNotify create a new deployment notify instance
func (*DeploymentNotify) Close ¶
func (dn *DeploymentNotify) Close() (err error)
func (*DeploymentNotify) Listen ¶
func (dn *DeploymentNotify) Listen() (err error)
func (*DeploymentNotify) Log ¶
func (dn *DeploymentNotify) Log(ev pq.ListenerEventType, err error)
Log handles logging errors
type Grant ¶
type Grant struct { Token string `json:"accessToken"` TokenExpiry int `json:"tokenExpiry"` Scope string `json:"scope"` RefreshToken string `json:"refreshToken"` RefreshTokenExpiry int `json:"refreshTokenExpiry"` TokenType string `json:"tokenType"` ArcUserID int `json:"userId"` }
Grant
func GrantRefresh ¶
func GrantRefresh(db *sql.Connection, c *Client, credentialID int, token string) (g *Grant, err error)
Refresh calls refresh internally and saves to the DB
func SQLDeploymentGrantToGrant ¶
func SQLDeploymentGrantToGrant(dg *model.DeploymentGrant) (g *Grant)
func (*Grant) IsAboutToExpireExpire ¶
IsAboutToExpireExpire returns true if this grant's token is about to expire (within 60 seconds)
type GrantUserinfo ¶
type GrantUserinfo struct { ID int `json:"id"` Username string `json:"username"` Email string `json:"email"` FirstName string `json:"firstName"` MiddleName string `json:"middleName"` LastName string `json:"lastName"` TypeCode string `json:"typeCode"` StatusCode string `json:"statusCode"` Created int `json:"created"` }
GrantUserinfo
type RequestItem ¶
type RequestItem struct { Service string `json:"service"` Action string `json:"action"` Params []interface{} `json:"params"` Options RequestItemOption `json:"options"` }
RequestItem is an item from a RequestList
type RequestItemOption ¶
type RequestItemOption struct { Value map[string]interface{} `json:"value"` Flag map[string]bool `json:"flag"` Filter map[string]interface{} `json:"filter"` }
RequestItemOption defines possible options for a request item
type RequestList ¶
type RequestList struct { Format string `json:"format"` Version int `json:"version"` ID int `json:"id"` Requests []*RequestItem `json:"requests"` Token string `json:"token"` Username string `json:"username"` AccessToken string `json:"accessToken"` }
RequestList formats a request to send to an arc API server