graph

package
v0.0.96 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

graph_api_error_messages.go

graph_api_exceptions.go

graph_api_handler.go

graph_api_handler_constants.go

graph_api_headers.go

graph_api_request.go

graph_api_response.go

graph_api_url.go

Index

Constants

View Source
const (
	APIName                            = "microsoft graph"     // APIName: represents the name of the API.
	DefaultBaseDomain                  = "graph.microsoft.com" // DefaultBaseDomain: represents the base domain for the graph instance.
	OAuthTokenEndpoint                 = "/oauth2/v2.0/token"  // OAuthTokenEndpoint: The endpoint to obtain an OAuth token.
	BearerTokenEndpoint                = ""                    // BearerTokenEndpoint: The endpoint to obtain a bearer token.
	TokenRefreshEndpoint               = "graph.microsoft.com" // TokenRefreshEndpoint: The endpoint to refresh an existing token.
	TokenInvalidateEndpoint            = "graph.microsoft.com" // TokenInvalidateEndpoint: The endpoint to invalidate an active token.
	BearerTokenAuthenticationSupport   = true                  // BearerTokenAuthSuppport: A boolean to indicate if the API supports bearer token authentication.
	OAuthAuthenticationSupport         = true                  // OAuthAuthSuppport: A boolean to indicate if the API supports OAuth authentication.
	OAuthWithCertAuthenticationSupport = true                  // OAuthWithCertAuthSuppport: A boolean to indicate if the API supports OAuth with client certificate authentication.
)

Endpoint constants represent the URL suffixes used for graph API token interactions.

Variables

This section is empty.

Functions

func ExtractErrorMessageFromHTML

func ExtractErrorMessageFromHTML(htmlContent string) string

ExtractErrorMessageFromHTML attempts to parse an HTML error page and extract a combined human-readable error message.

func ParseJSONErrorResponse

func ParseJSONErrorResponse(body []byte) (string, error)

ParseJSONErrorResponse parses the JSON error message from the response body.

Types

type APIHandlerError

type APIHandlerError struct {
	HTTPStatusCode int                    `json:"httpStatusCode"`
	ErrorType      string                 `json:"errorType"`
	ErrorMessage   string                 `json:"errorMessage"`
	ExtraDetails   map[string]interface{} `json:"extraDetails"`
}

APIHandlerError represents an error response from the graph API.

type ConfigMap

type ConfigMap map[string]EndpointConfig

ConfigMap is a map that associates endpoint URL patterns with their corresponding configurations. The map's keys are strings that identify the endpoint, and the values are EndpointConfig structs that hold the configuration for that endpoint.

type EndpointConfig

type EndpointConfig struct {
	Accept      string  `json:"accept"`       // Accept specifies the MIME type the endpoint can handle in responses.
	ContentType *string `json:"content_type"` // ContentType, if not nil, specifies the MIME type to set for requests sent to the endpoint. A pointer is used to distinguish between a missing field and an empty string.
}

EndpointConfig is a struct that holds configuration details for a specific API endpoint. It includes what type of content it can accept and what content type it should send.

type GraphAPIHandler

type GraphAPIHandler struct {
	OverrideBaseDomain string        // OverrideBaseDomain is used to override the base domain for URL construction.
	InstanceName       string        // InstanceName is the name of the graph instance.
	Logger             logger.Logger // Logger is the structured logger used for logging.
}

GraphAPIHandler implements the APIHandler interface for the graph Pro API.

func (*GraphAPIHandler) ConstructAPIAuthEndpoint

func (g *GraphAPIHandler) ConstructAPIAuthEndpoint(instanceName string, endpointPath string, log logger.Logger) string

ConstructAPIAuthEndpoint constructs the full URL for a graph API auth endpoint path and logs the URL.

func (*GraphAPIHandler) ConstructAPIResourceEndpoint

func (g *GraphAPIHandler) ConstructAPIResourceEndpoint(instanceName string, endpointPath string, log logger.Logger) string

ConstructAPIResourceEndpoint constructs the full URL for a graph API resource endpoint path and logs the URL.

func (*GraphAPIHandler) GetAPIBearerTokenAuthenticationSupportStatus

func (g *GraphAPIHandler) GetAPIBearerTokenAuthenticationSupportStatus() bool

GetAPIBearerTokenAuthenticationSupportStatus returns a boolean indicating if bearer token authentication is supported in the api handler.

func (*GraphAPIHandler) GetAPIOAuthAuthenticationSupportStatus

func (g *GraphAPIHandler) GetAPIOAuthAuthenticationSupportStatus() bool

GetAPIOAuthAuthenticationSupportStatus returns a boolean indicating if OAuth authentication is supported in the api handler.

func (*GraphAPIHandler) GetAPIOAuthWithCertAuthenticationSupportStatus

func (g *GraphAPIHandler) GetAPIOAuthWithCertAuthenticationSupportStatus() bool

GetAPIOAuthWithCertAuthenticationSupportStatus returns a boolean indicating if OAuth with client certificate authentication is supported in the api handler.

func (*GraphAPIHandler) GetAPIRequestHeaders

func (g *GraphAPIHandler) GetAPIRequestHeaders(endpoint string) map[string]string

GetAPIRequestHeaders returns a map of standard headers required for making API requests.

func (*GraphAPIHandler) GetAcceptHeader

func (g *GraphAPIHandler) GetAcceptHeader() string

GetAcceptHeader constructs and returns a weighted Accept header string for HTTP requests. The Accept header indicates the MIME types that the client can process and prioritizes them based on the quality factor (q) parameter. Higher q-values signal greater preference. This function specifies a range of MIME types with their respective weights, ensuring that the server is informed of the client's versatile content handling capabilities while indicating a preference for XML. The specified MIME types cover common content formats like images, JSON, XML, HTML, plain text, and certificates, with a fallback option for all other types.

func (*GraphAPIHandler) GetBearerTokenEndpoint

func (g *GraphAPIHandler) GetBearerTokenEndpoint() string

GetBearerTokenEndpoint returns the endpoint for obtaining a bearer token. Used for constructing API URLs for the http client.

func (*GraphAPIHandler) GetContentTypeHeader

func (g *GraphAPIHandler) GetContentTypeHeader(endpoint string, log logger.Logger) string

GetContentTypeHeader determines the appropriate Content-Type header for a given API endpoint. It attempts to find a content type that matches the endpoint prefix in the global configMap. If a match is found and the content type is defined (not nil), it returns the specified content type. If the endpoint does not match any of the predefined patterns, "application/json" is used as a fallback. This method logs the decision process at various stages for debugging purposes.

func (*GraphAPIHandler) GetDefaultBaseDomain

func (g *GraphAPIHandler) GetDefaultBaseDomain() string

GetDefaultBaseDomain returns the default base domain used for constructing API URLs to the http client.

func (*GraphAPIHandler) GetOAuthTokenEndpoint

func (g *GraphAPIHandler) GetOAuthTokenEndpoint() string

GetOAuthTokenEndpoint returns the endpoint for obtaining an OAuth token. Used for constructing API URLs for the http client.

func (*GraphAPIHandler) GetTokenInvalidateEndpoint

func (g *GraphAPIHandler) GetTokenInvalidateEndpoint() string

GetTokenInvalidateEndpoint returns the endpoint for invalidating an active token. Used for constructing API URLs for the http client.

func (*GraphAPIHandler) GetTokenRefreshEndpoint

func (g *GraphAPIHandler) GetTokenRefreshEndpoint() string

GetTokenRefreshEndpoint returns the endpoint for refreshing an existing token. Used for constructing API URLs for the http client.

func (*GraphAPIHandler) HandleAPIErrorResponse

func (g *GraphAPIHandler) HandleAPIErrorResponse(resp *http.Response, out interface{}, log logger.Logger) error

func (*GraphAPIHandler) HandleAPISuccessResponse

func (g *GraphAPIHandler) HandleAPISuccessResponse(resp *http.Response, out interface{}, log logger.Logger) error

Functions

func (*GraphAPIHandler) MarshalMultipartRequest

func (g *GraphAPIHandler) MarshalMultipartRequest(fields map[string]string, files map[string]string, log logger.Logger) ([]byte, string, error)

MarshalMultipartFormData takes a map with form fields and file paths and returns the encoded body and content type.

func (*GraphAPIHandler) MarshalRequest

func (g *GraphAPIHandler) MarshalRequest(body interface{}, method string, endpoint string, log logger.Logger) ([]byte, error)

MarshalRequest encodes the request body according to the endpoint for the API.

func (*GraphAPIHandler) ReturnAPIErrorResponse

func (g *GraphAPIHandler) ReturnAPIErrorResponse(resp *http.Response) *APIHandlerError

ReturnAPIErrorResponse parses an HTTP error response from the graph API.

func (*GraphAPIHandler) SetBaseDomain

func (g *GraphAPIHandler) SetBaseDomain() string

SetBaseDomain returns the appropriate base domain for URL construction. It uses j.OverrideBaseDomain if set, otherwise falls back to DefaultBaseDomain.

Jump to

Keyboard shortcuts

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