office365

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadRequest is a 400 http error.
	ErrBadRequest = errors.New("bad request")
	// ErrNotFound is a 404 http error.
	ErrNotFound = errors.New("not found")
)
View Source
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.

View Source
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

func Bool(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse validates the response returned from an API call and returns an error, if any.

func Int

func Int(v int) *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.

func String

func String(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

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

func NewClient(httpClient *http.Client, tenantID string, pubIdentifier string) *Client

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.

func (*Client) Version

func (c *Client) Version() string

Version returns the client version.

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

type Credentials struct {
	ClientID     string
	ClientSecret string
	TenantDomain string
	TenantID     string
}

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

type ErrorResponse struct {
	Response *http.Response
	Err      *Error
}

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

func NewJSONHandler(w io.Writer, l *logrus.Logger, indent bool) *JSONHandler

NewJSONHandler returns a JSONHandler using the provided writer.

func (JSONHandler) Handle

func (h JSONHandler) Handle(in <-chan ResourceAudits) error

Handle .

type JSONRecord

type JSONRecord struct {
	ContentType string
	RequestTime time.Time
	Record      interface{}
}

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.

func NewMemoryState

func NewMemoryState() *MemoryState

NewMemoryState returns a new MemoryState.

func (*MemoryState) Read

func (m *MemoryState) Read(r io.Reader) error

Read will decode json from a reader and populate its state.

func (*MemoryState) Write

func (m *MemoryState) Write(w io.Writer) error

Write will encode its state as json to a writer.

type QueryParams

type QueryParams struct {
	url.Values
}

QueryParams .

func NewQueryParams

func NewQueryParams() *QueryParams

NewQueryParams .

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

func (p *QueryParams) AddStartEndTime(startTime time.Time, endTime time.Time) error

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 Response

type Response struct {
	Response *http.Response
}

Response encapsulates the http response received from a successful API call.

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

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

Start will start a subscription for the specified content type. A payload can optionally be provided to enable a webhook that will send notifications periodically about available content. See below webhook 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

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.

func (*SubscriptionWatcher) Run

Run implements the Watcher interface.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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