Skip to content

Commit 02a1bd4

Browse files
committed
microsoft-graph: update SDK readme
1 parent f1ff901 commit 02a1bd4

File tree

2 files changed

+86
-4
lines changed

2 files changed

+86
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ At this time this SDK uses both [the base-layer within this repository](./sdk) a
1111
This repository contains:
1212

1313
* `./docs` - usage documentation.
14-
* `./microsoft-graph` - (WIP) the Microsoft Graph Services supported by this SDK.
14+
* `./microsoft-graph` - the Microsoft Graph Services supported by this SDK.
1515
* `./resource-manager` - the Resource Manager Services supported by this SDK.
1616
* `./sdk` - the base layer that's used in this repository.
1717

microsoft-graph/README.md

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,89 @@
1-
`github.com/hashicorp/go-azure-sdk/microsoft-graph`
1+
# `github.com/hashicorp/go-azure-sdk/microsoft-graph`
22

33
This SDK is an opinionated Go SDK for Microsoft Graph, primarily intended to be used in the [Terraform AzureAD Provider](https://github.com/hashicorp/terraform-provider-azuread).
44

5-
This SDK is coming soon - but will use exclusively use [the base-layer within this repository](../sdk).
5+
More information on this, and our Resource Manager SDK, can be found in [the main `README.md` file](../README.md).
66

7-
More information on this SDK, and how to use it, can be found in [the main `README.md` file](../README.md).
7+
## Overview
8+
9+
This SDK is published as a Go module, and makes use of the `github.com/hashicorp/go-azure-sdk/sdk` module for authentication, cloud environment configuration, and helper types. Packages within this SDK are organised in the structure `./microsoft-graph/{serviceName}/{apiVersion}/{resourceName}`, where:
10+
11+
* `{serviceName}` is a distinct Microsoft Graph service such as `applications`, `groups`, `policies` etc.
12+
* `{apiVersion}` corresponds to the v1.0 or beta Microsoft Graph API version, and is named either `stable` (for v1.0) or `beta`.
13+
* `{resourceName}` is a Terraform-centric grouping of endpoints that represent the same logical resource, and which comprise one or more distinct operations.
14+
15+
Additionally, the majority of models and constants (i.e. enums) can be found in the `stable` and `beta` packages within the `common-types` directory. Some resources also define their own models specifically for request/response payloads that are unique to that resource.
16+
17+
## Getting Started
18+
19+
We have designed this SDK to be as easy-to-use as possible, and you can get started with minimal boilerplate.
20+
21+
```go
22+
package main
23+
24+
import (
25+
"context"
26+
"log"
27+
"time"
28+
29+
"github.com/hashicorp/go-azure-sdk/microsoft-graph/applications/stable/application"
30+
"github.com/hashicorp/go-azure-sdk/microsoft-graph/common-types/stable"
31+
"github.com/hashicorp/go-azure-sdk/sdk/auth"
32+
"github.com/hashicorp/go-azure-sdk/sdk/environments"
33+
"github.com/hashicorp/go-azure-sdk/sdk/nullable"
34+
)
35+
36+
func main() {
37+
ctx, cancel := context.WithTimeout(context.Background(), 5 * time.Minute)
38+
defer cancel()
39+
40+
environment := environments.AzurePublic()
41+
credentials := auth.Credentials{
42+
Environment: *environment,
43+
EnableAuthenticatingUsingAzureCLI: true,
44+
// you can also authenticate using a Service Principal, Managed Identity, OIDC etc.
45+
}
46+
log.Printf("[DEBUG] Obtaining Credentials..")
47+
authorizer, err := auth.NewAuthorizerFromCredentials(ctx, credentials, environment.MicrosoftGraph)
48+
if err != nil {
49+
log.Fatalf("building authorizer from credentials: %+v", err)
50+
}
51+
52+
log.Printf("[DEBUG] Building Application Client..")
53+
client, err := application.NewApplicationClientWithBaseURI(environment.MicrosoftGraph)
54+
if err != nil {
55+
log.Fatalf("building Application client: %+v", err)
56+
}
57+
client.Client.SetAuthorizer(authorizer)
58+
59+
log.Printf("[DEBUG] Creating application..")
60+
payload := stable.Application{
61+
DisplayName: nullable.Value("My Application"),
62+
SignInAudience: nullable.Value("AzureADMultipleOrgs"),
63+
}
64+
65+
options := application.DefaultCreateApplicationOperationOptions()
66+
67+
resp, err := client.CreateApplication(ctx, payload, options)
68+
if err != nil {
69+
log.Fatalf("Creating application: %v", err)
70+
}
71+
72+
if resp.Model == nil {
73+
log.Fatalf("Creating application: response was empty")
74+
}
75+
if resp.Model.Id == nil {
76+
log.Fatalf("Creating application: no object ID returned")
77+
}
78+
79+
log.Printf("[DEBUG] Application created with object ID: %s", *resp.Model.Id)
80+
}
81+
```
82+
83+
For more usage examples, please refer to the [HashiCorp AzureAD Terraform Provider](https://github.com/hashicorp/terraform-provider-azuread).
84+
85+
## Contributing
86+
87+
This Microsoft Graph SDK is auto-generated using the [Pandora project](https://github.com/hashicorp/pandora), which obtains API definitions from [OpenAPI3 specs published by Microsoft](https://github.com/microsoftgraph/msgraph-metadata).
88+
89+
To add new services to this SDK, please amend the [`microsoft-graph.hcl`](https://github.com/hashicorp/pandora/tree/main/config) configuration file in the hashicorp/pandora repository, and open a pull request.

0 commit comments

Comments
 (0)