Documentation ¶
Index ¶
- Variables
- func AddExtendedSchema(r *schema.AuditLogRecordType, raw json.RawMessage, data *interface{})
- func Bool(v bool) *bool
- func CheckResponse(r *http.Response) error
- func Int(v int) *int
- func OAuthClient(ctx context.Context, c *Credentials) *http.Client
- func String(v string) *string
- type AuditService
- type Client
- type Content
- type ContentService
- type Credentials
- type Error
- type ErrorResponse
- type JSONHandler
- type JSONRecord
- type MemoryState
- type QueryParams
- type ResourceAudits
- type ResourceContent
- type ResourceHandler
- type ResourceSubscription
- type Response
- type State
- type StateData
- type Subscription
- type SubscriptionService
- func (s *SubscriptionService) List(ctx context.Context) (*Response, []Subscription, error)
- func (s *SubscriptionService) Start(ctx context.Context, ct *schema.ContentType, webhook *Webhook) (*Response, *Subscription, error)
- func (s *SubscriptionService) Stop(ctx context.Context, ct *schema.ContentType) (*Response, error)
- type SubscriptionWatcher
- type SubscriptionWatcherConfig
- type Watcher
- type Webhook
- type WebhookRequest
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBadRequest is a 400 http error. ErrBadRequest = errors.New("bad request") // ErrNotFound is a 404 http error. ErrNotFound = errors.New("not found") )
var ( RequestDateFormat = "2006-01-02" RequestDatetimeFormat = "2006-01-02T15:04" RequestDatetimeLargeFormat = "2006-01-02T15:04:05" CreatedDatetimeFormat = "2006-01-02T15:04:05.999Z" )
RequestFormats are the time.Format vars we must follow when providing datetime params to an API endpoint.
var ( ErrContentTypeRequired = errors.New("ContentType queryParam is required") ErrIntervalMismatch = errors.New("StartTime and EndTime must both be provided or not at all") ErrIntervalNegative = errors.New("interval given is 0 or negative") ErrIntervalDay = errors.New("interval given is more than 24 hours") ErrIntervalWeek = errors.New("StartTime given is more than 7 days in the past") )
error definition.
Functions ¶
func AddExtendedSchema ¶
func AddExtendedSchema(r *schema.AuditLogRecordType, raw json.RawMessage, data *interface{})
AddExtendedSchema .
func Bool ¶
Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.
func CheckResponse ¶
CheckResponse validates the response returned from an API call and returns an error, if any.
func Int ¶
Int is a helper routine that allocates a new int value to store v and returns a pointer to it.
func OAuthClient ¶
func OAuthClient(ctx context.Context, c *Credentials) *http.Client
OAuthClient returns an authenticated httpClient using the provided credentials.
Types ¶
type AuditService ¶
type AuditService service
AuditService .
func (*AuditService) List ¶
func (s *AuditService) List(ctx context.Context, contentID string, addExtendedSchema bool) (*Response, []interface{}, error)
List returns a list of events or actions.
Microsoft API Reference: https://docs.microsoft.com/en-us/office/office-365-management-api/office-365-management-activity-api-reference#retrieving-content To retrieve a content blob, make a GET request against the corresponding content URI that is included in the list of available content and in the notifications sent to a webhook. The returned content will be a collection of one more actions or events in JSON format.
type Client ¶
type Client struct { BaseURL *url.URL UserAgent string Subscription *SubscriptionService Content *ContentService Audit *AuditService // contains filtered or unexported fields }
A Client handles communication with the Microsoft Graph REST API.
func NewClient ¶
NewClient creates a Client using the provided httpClient. If nil is provided, a default httpClient with a default timeout value is created. Note that the default client has no way of authenticating itself against the Microsoft Office365 Management Activity API. A convenience function is provided just for that: NewClientAuthenticated.
func NewClientAuthenticated ¶
func NewClientAuthenticated(c *Credentials, pubIdentifier string) *Client
NewClientAuthenticated returns an authenticated Client. pubIdentifier is used on Microsoft side to group queries together in terms of quotas and limitations.
type Content ¶
type Content struct { ContentType string `json:"contentType"` ContentID string `json:"contentId"` ContentURI string `json:"contentUri"` ContentCreated string `json:"contentCreated"` ContentExpiration string `json:"contentExpiration"` }
Content represents metadata needed for retreiving aggregated data.
type ContentService ¶
type ContentService service
ContentService .
func (*ContentService) List ¶
func (s *ContentService) List(ctx context.Context, ct *schema.ContentType, startTime time.Time, endTime time.Time) ([]*Response, []Content, error)
List returns a list of content available for retrieval.
Microsoft API Reference: https://docs.microsoft.com/en-us/office/office-365-management-api/office-365-management-activity-api-reference#list-available-content
This operation lists the content currently available for retrieval for the specified content type. The content is an aggregation of actions and events harvested from multiple servers across multiple datacenters. The content will be listed in the order in which the aggregations become available, but the events and actions within the aggregations are not guaranteed to be sequential. An error is returned if the subscription status is disabled.
type Credentials ¶
Credentials are used by OAuthClient.
type Error ¶
type Error struct { Error struct { Code string `json:"code"` Message string `json:"message"` } `json:"error"` }
Error represents the json object returned in the body of the response when an error is encountered.
type ErrorResponse ¶
ErrorResponse encapsulates the http response as well as the error returned in the body of an API call.
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type JSONHandler ¶
type JSONHandler struct {
// contains filtered or unexported fields
}
JSONHandler implements the ResourceHandler interface. It writes json representation of a resource on the provided writer.
func NewJSONHandler ¶
NewJSONHandler returns a JSONHandler using the provided writer.
type JSONRecord ¶
JSONRecord is used for enriching AuditRecords with Request params.
type MemoryState ¶
type MemoryState struct {
// contains filtered or unexported fields
}
MemoryState is an in-memory State interface implementation.
type QueryParams ¶
QueryParams .
func (*QueryParams) AddContentType ¶
func (p *QueryParams) AddContentType(ct *schema.ContentType) error
AddContentType .
func (*QueryParams) AddPubIdentifier ¶
func (p *QueryParams) AddPubIdentifier(pubIdentifier string)
AddPubIdentifier .
func (*QueryParams) AddStartEndTime ¶
AddStartEndTime .
type ResourceAudits ¶
type ResourceAudits struct { ContentType *schema.ContentType RequestTime time.Time AuditRecord interface{} }
ResourceAudits .
type ResourceContent ¶
type ResourceContent struct { ContentType *schema.ContentType RequestTime time.Time Content Content }
ResourceContent .
type ResourceHandler ¶
type ResourceHandler interface {
Handle(<-chan ResourceAudits) error
}
ResourceHandler is an interface for handling streamed resources.
type ResourceSubscription ¶
type ResourceSubscription struct { ContentType *schema.ContentType RequestTime time.Time Subscription Subscription }
ResourceSubscription .
type State ¶
type State interface { Read(io.Reader) error Write(io.Writer) error // contains filtered or unexported methods }
State is an interface for storinm and retrievinm Watcher state.
type StateData ¶
type StateData struct { LastContentCreated map[schema.ContentType]time.Time LastRequestTime map[schema.ContentType]time.Time }
StateData holds the internal state of MemoryState.
type Subscription ¶
type Subscription struct { ContentType *string `json:"contentType"` Status *string `json:"status"` Webhook *Webhook `json:"webhook"` }
Subscription represents a response.
type SubscriptionService ¶
type SubscriptionService service
SubscriptionService .
func (*SubscriptionService) List ¶
func (s *SubscriptionService) List(ctx context.Context) (*Response, []Subscription, error)
List returns the list of subscriptions.
Microsoft API Reference: https://docs.microsoft.com/en-us/office/office-365-management-api/office-365-management-activity-api-reference#list-current-subscriptions
List current subscriptions This operation returns a collection of the current subscriptions together with the associated webhooks.
func (*SubscriptionService) Start ¶
func (s *SubscriptionService) Start(ctx context.Context, ct *schema.ContentType, webhook *Webhook) (*Response, *Subscription, error)
Start will start a subscription for the specified content type. A payload can optionnaly be provided to enable a webhook that will send notifications periodically about available content. See below webhgook section for details.
Microsoft API Reference: https://docs.microsoft.com/en-us/office/office-365-management-api/office-365-management-activity-api-reference#start-a-subscription
This operation starts a subscription to the specified content type. If a subscription to the specified content type already exists, this operation is used to: - Update the properties of an active webhook. - Enable a webhook that was disabled because of excessive failed notifications. - Re-enable an expired webhook by specifying a later or null expiration date. - Remove a webhook.
Webhook validation ¶
When the /start operation is called and a webhook is specified, we will send a validation notification to the specified webhook address to validate that an active listener can accept and process notifications.
If we do not receive an HTTP 200 OK response, the subscription will not be created. Or, if /start is being called to add a webhook to an existing subscription and a response of HTTP 200 OK is not received, the webhook will not be added and the subscription will remain unchanged.
func (*SubscriptionService) Stop ¶
func (s *SubscriptionService) Stop(ctx context.Context, ct *schema.ContentType) (*Response, error)
Stop stops a subscription for the provided ContentType.
Microsoft API Reference: https://docs.microsoft.com/en-us/office/office-365-management-api/office-365-management-activity-api-reference#stop-a-subscription
This operation stops a subscription to the specified content type. When a subscription is stopped, you will no longer receive notifications and you will not be able to retrieve available content. If the subscription is later restarted, you will have access to new content from that point forward. You will not be able to retrieve content that was available between the time the subscription was stopped and restarted.
type SubscriptionWatcher ¶
type SubscriptionWatcher struct { State Handler ResourceHandler // contains filtered or unexported fields }
SubscriptionWatcher implements the Watcher interface. It fetches current subscriptions, then queries content available for a given interval and proceed to query audit records.
func NewSubscriptionWatcher ¶
func NewSubscriptionWatcher(client *Client, conf SubscriptionWatcherConfig, s State, h ResourceHandler, l *logrus.Logger) (*SubscriptionWatcher, error)
NewSubscriptionWatcher returns a new watcher that uses the provided client for querying the API.
type SubscriptionWatcherConfig ¶
type SubscriptionWatcherConfig struct { LookBehindMinutes int TickerIntervalSeconds int AddExtendedSchemas bool }
SubscriptionWatcherConfig .
type Watcher ¶
type Watcher interface {
Run(context.Context) chan ResourceAudits
}
Watcher is an interface used by Watch for generating a stream of records.
type Webhook ¶
type Webhook struct { Status *string `json:"status,omitempty"` Address *string `json:"address"` AuthID *string `json:"authId,omitempty"` Expiration *string `json:"expiration,omitempty"` }
Webhook represents both a response and a request payload.
type WebhookRequest ¶
type WebhookRequest struct {
Webhook *Webhook `json:"webhook"`
}