Documentation ¶
Index ¶
- func SendCustomPostRequest(ctx context.Context, adapter abstractions.RequestAdapter, ...) (s.Parsable, error)
- func SendCustomPostRequestNoContent(ctx context.Context, adapter abstractions.RequestAdapter, ...) error
- func SendCustomPutRequestByResourceId(ctx context.Context, adapter abstractions.RequestAdapter, ...) error
- type CustomPostRequestConfig
- type CustomPutRequestConfig
- type GraphAPIVersion
- type GraphClientInterface
- type GraphClients
- type MockBetaGraphServiceClient
- type MockGraphClients
- type MockStableGraphServiceClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SendCustomPostRequest ¶
func SendCustomPostRequest( ctx context.Context, adapter abstractions.RequestAdapter, config CustomPostRequestConfig, factory s.ParsableFactory, errorMappings abstractions.ErrorMappings, ) (s.Parsable, error)
SendCustomPostRequest performs a custom POST request using the Microsoft Graph SDK when the operation is not available in the generated SDK methods. This function supports both Beta and V1.0 Graph API versions and returns the parsed response model.
Parameters:
- ctx: The context for the request, which can be used for cancellation and timeout
- adapter: The RequestAdapter interface for making HTTP requests
- config: CustomPostRequestConfig containing:
- APIVersion: The Graph API version to use (Beta or V1.0)
- Endpoint: The resource endpoint path
- RequestBody: The body of the POST request implementing serialization.Parsable
- QueryParameters: Optional map of query parameters
- factory: The factory function to create the response model
- errorMappings: Optional error mappings for custom error handling
Returns:
- s.Parsable: The parsed response model
- error: Any error that occurred during the request
func SendCustomPostRequestNoContent ¶
func SendCustomPostRequestNoContent(ctx context.Context, adapter abstractions.RequestAdapter, config CustomPostRequestConfig) error
SendCustomPostRequestNoContent performs a custom POST request that doesn't expect a response body. This is useful for operations that return 204 No Content.
Parameters are the same as SendCustomPostRequest except it doesn't take a responseModel parameter and uses the SendNoContent method of the adapter.
Returns:
- error: Returns nil if the request was successful (204 No Content received), otherwise returns an error describing what went wrong
func SendCustomPutRequestByResourceId ¶
func SendCustomPutRequestByResourceId(ctx context.Context, adapter abstractions.RequestAdapter, config CustomPutRequestConfig) error
SendCustomPutRequestByResourceId performs a custom PUT request using the Microsoft Graph SDK when the operation is not available in the generated SDK methods. This function supports both Beta and V1.0 Graph API versions and expects a 204 No Content response from the server on success.
The function handles: - Construction of the Graph API URL with proper formatting - Setting up the PUT request with the provided request body - Sending the request with proper authentication - Error handling and return
Parameters:
- ctx: The context for the request, which can be used for cancellation and timeout
- clients: The GraphClients instance containing both Beta and V1.0 client configurations
- config: CustomPutRequestConfig containing:
- APIVersion: The Graph API version to use (Beta or V1.0)
- Endpoint: The resource endpoint path (e.g., "deviceManagement/configurationPolicies")
- ResourceID: The ID of the resource to update
- RequestBody: The body of the PUT request implementing serialization.Parsable
Returns:
- error: Returns nil if the request was successful (204 No Content received), otherwise returns an error describing what went wrong
Example Usage:
config := CustomPutRequestConfig{ APIVersion: GraphAPIBeta, Endpoint: "deviceManagement/configurationPolicies", ResourceID: "d557c813-b8e5-4efc-b00e-9c0bd5fd10df", RequestBody: myRequestBody, } err := SendCustomPutRequestByResourceId(ctx, clients, config)
Types ¶
type CustomPostRequestConfig ¶
type CustomPostRequestConfig struct { // The API version to use (beta or v1.0) APIVersion GraphAPIVersion // The base endpoint (e.g., "deviceManagement/configurationPolicies") Endpoint string // The request body RequestBody s.Parsable // Optional query parameters for the request QueryParameters map[string]string }
CustomPostRequestConfig contains the configuration for a custom POST request
type CustomPutRequestConfig ¶
type CustomPutRequestConfig struct { // The API version to use (beta or v1.0) APIVersion GraphAPIVersion // The base endpoint (e.g., "deviceManagement/configurationPolicies") Endpoint string // The ID of the resource ResourceID string // The request body RequestBody s.Parsable }
CustomPutRequestConfig contains the configuration for a custom PUT request
type GraphAPIVersion ¶
type GraphAPIVersion string
GraphAPIVersion represents Microsoft Graph API version
const ( GraphAPIBeta GraphAPIVersion = "beta" GraphAPIV1 GraphAPIVersion = "v1.0" )
type GraphClientInterface ¶
type GraphClientInterface interface { GetStableClient() *msgraphsdk.GraphServiceClient GetBetaClient() *msgraphbetasdk.GraphServiceClient }
GraphClientInterface defines the interface for GraphClients
type GraphClients ¶
type GraphClients struct { StableClient *msgraphsdk.GraphServiceClient BetaClient *msgraphbetasdk.GraphServiceClient }
GraphClients encapsulates both the stable and beta GraphServiceClients provided by the Microsoft Graph SDKs. These clients are used to interact with the Microsoft Graph API and its beta endpoints, respectively.
The stable client (StableClient) is used for making API calls to the stable Microsoft Graph endpoints, which are generally considered production-ready and have a higher level of reliability and support. The v1.0 endpoint of Microsoft Graph provides a stable and reliable API that is fully supported by Microsoft, ensuring that applications built on this endpoint have a solid foundation and offer the best possible user experience.
The beta client (BetaClient) is used for making API calls to the beta Microsoft Graph endpoints, which allow developers to test and experiment with new features before they are released to the general public. However, it is important to note that the beta endpoint is not intended for use in production environments. APIs and functionalities available in the beta endpoint are subject to change, and features might be modified or removed without notice, potentially causing disruptions or breaking changes to applications. Additionally, the beta endpoint might not have the same level of support, reliability, or performance as the v1.0 endpoint, and can be unexpectedly unavailable or have slower response times.
For these reasons, developers are strongly recommended to use the v1.0 endpoint when building production applications to ensure stability, reliability, and a better user experience.
Fields:
StableClient (*msgraphsdk.GraphServiceClient): The client for interacting with the stable Microsoft Graph API, providing access to well-supported and reliable endpoints suitable for production use. BetaClient (*msgraphbetasdk.GraphServiceClient): The client for interacting with the beta Microsoft Graph API, providing access to new and experimental features that are subject to change and should be used with caution in production environments.
Usage: The GraphClients struct is intended to be instantiated and configured by the provider during initialization, and then passed to the resources that need to interact with the Microsoft Graph API. This separation of stable and beta clients allows resources to choose the appropriate client based on the API features they require.
func (*GraphClients) GetBetaClient ¶
func (g *GraphClients) GetBetaClient() *msgraphbetasdk.GraphServiceClient
GetBetaClient returns the beta client
func (*GraphClients) GetStableClient ¶
func (g *GraphClients) GetStableClient() *msgraphsdk.GraphServiceClient
GetStableClient returns the stable client
type MockBetaGraphServiceClient ¶
MockBetaGraphServiceClient is a flexible mock of the beta GraphServiceClient
type MockGraphClients ¶
type MockGraphClients struct { mock.Mock MockStableClient *MockStableGraphServiceClient MockBetaClient *MockBetaGraphServiceClient }
MockGraphClients implements the GraphClientInterface
func NewMockGraphClients ¶
func NewMockGraphClients() *MockGraphClients
NewMockGraphClients creates a new instance of MockGraphClients
func (*MockGraphClients) GetBetaClient ¶
func (m *MockGraphClients) GetBetaClient() *msgraphbetasdk.GraphServiceClient
GetBetaClient returns the mock beta client
func (*MockGraphClients) GetStableClient ¶
func (m *MockGraphClients) GetStableClient() *msgraphsdk.GraphServiceClient
GetStableClient returns the mock stable client
type MockStableGraphServiceClient ¶
MockStableGraphServiceClient is a flexible mock of the stable GraphServiceClient