|
1 |
| -## Azure PostgreSQLManagementClient SDK for JavaScript |
| 1 | +# Azure PostgreSQLManagement client library for JavaScript |
2 | 2 |
|
3 |
| -This package contains an isomorphic SDK for PostgreSQLManagementClient. |
| 3 | +This package contains an isomorphic SDK (runs both in Node.js and in browsers) for Azure PostgreSQLManagement client. |
| 4 | + |
| 5 | +The Microsoft Azure management API provides create, read, update, and delete functionality for Azure PostgreSQL resources including servers, databases, firewall rules, VNET rules, security alert policies, log files and configurations with new business model. |
| 6 | + |
| 7 | +[Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/postgresql/arm-postgresql) | |
| 8 | +[Package (NPM)](https://www.npmjs.com/package/@azure/arm-postgresql) | |
| 9 | +[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/arm-postgresql) | |
| 10 | +[Samples](https://github.com/Azure-Samples/azure-samples-js-management) |
| 11 | + |
| 12 | +## Getting started |
4 | 13 |
|
5 | 14 | ### Currently supported environments
|
6 | 15 |
|
7 | 16 | - [LTS versions of Node.js](https://nodejs.org/about/releases/)
|
8 |
| -- Latest versions of Safari, Chrome, Edge, and Firefox. |
| 17 | +- Latest versions of Safari, Chrome, Edge and Firefox. |
| 18 | + |
| 19 | +### Prerequisites |
| 20 | + |
| 21 | +- An [Azure subscription][azure_sub]. |
9 | 22 |
|
10 |
| -### How to Install |
| 23 | +### Install the `@azure/arm-postgresql` package |
| 24 | + |
| 25 | +Install the Azure PostgreSQLManagement client library for JavaScript with `npm`: |
11 | 26 |
|
12 | 27 | ```bash
|
13 | 28 | npm install @azure/arm-postgresql
|
14 | 29 | ```
|
15 | 30 |
|
16 |
| -### How to use |
| 31 | +### Create and authenticate a `PostgreSQLManagementClient` |
| 32 | + |
| 33 | +To create a client object to access the Azure PostgreSQLManagement API, you will need the `endpoint` of your Azure PostgreSQLManagement resource and a `credential`. The Azure PostgreSQLManagement client can use Azure Active Directory credentials to authenticate. |
| 34 | +You can find the endpoint for your Azure PostgreSQLManagement resource in the [Azure Portal][azure_portal]. |
17 | 35 |
|
18 |
| -#### nodejs - client creation and get servers as an example written in TypeScript. |
| 36 | +You can authenticate with Azure Active Directory using a credential from the [@azure/identity][azure_identity] library or [an existing AAD Token](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-a-pre-fetched-access-token). |
19 | 37 |
|
20 |
| -##### Install @azure/ms-rest-nodeauth |
| 38 | +To use the [DefaultAzureCredential][defaultazurecredential] provider shown below, or other credential providers provided with the Azure SDK, please install the `@azure/identity` package: |
21 | 39 |
|
22 |
| -- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`. |
23 | 40 | ```bash
|
24 |
| -npm install @azure/ms-rest-nodeauth@"^3.0.0" |
| 41 | +npm install @azure/identity |
25 | 42 | ```
|
26 | 43 |
|
27 |
| -##### Sample code |
| 44 | +You will also need to **register a new AAD application and grant access to Azure PostgreSQLManagement** by assigning the suitable role to your service principal (note: roles such as `"Owner"` will not grant the necessary permissions). |
| 45 | +Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`. |
| 46 | + |
| 47 | +For more information about how to create an Azure AD Application check out [this guide](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal). |
28 | 48 |
|
29 |
| -While the below sample uses the interactive login, other authentication options can be found in the [README.md file of @azure/ms-rest-nodeauth](https://www.npmjs.com/package/@azure/ms-rest-nodeauth) package |
30 |
| -```typescript |
31 |
| -const msRestNodeAuth = require("@azure/ms-rest-nodeauth"); |
| 49 | +```javascript |
32 | 50 | const { PostgreSQLManagementClient } = require("@azure/arm-postgresql");
|
33 |
| -const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; |
34 |
| - |
35 |
| -msRestNodeAuth.interactiveLogin().then((creds) => { |
36 |
| - const client = new PostgreSQLManagementClient(creds, subscriptionId); |
37 |
| - const resourceGroupName = "testresourceGroupName"; |
38 |
| - const serverName = "testserverName"; |
39 |
| - client.servers.get(resourceGroupName, serverName).then((result) => { |
40 |
| - console.log("The result is:"); |
41 |
| - console.log(result); |
42 |
| - }); |
43 |
| -}).catch((err) => { |
44 |
| - console.error(err); |
45 |
| -}); |
| 51 | +const { DefaultAzureCredential } = require("@azure/identity"); |
| 52 | +const subscriptionId = "00000000-0000-0000-0000-000000000000"; |
| 53 | +const client = new PostgreSQLManagementClient(new DefaultAzureCredential(), subscriptionId); |
46 | 54 | ```
|
47 | 55 |
|
48 |
| -#### browser - Authentication, client creation and get servers as an example written in JavaScript. |
| 56 | +## Key concepts |
49 | 57 |
|
50 |
| -##### Install @azure/ms-rest-browserauth |
| 58 | +### PostgreSQLManagementClient |
51 | 59 |
|
52 |
| -```bash |
53 |
| -npm install @azure/ms-rest-browserauth |
54 |
| -``` |
| 60 | +`PostgreSQLManagementClient` is the primary interface for developers using the Azure PostgreSQLManagement client library. Explore the methods on this client object to understand the different features of the Azure PostgreSQLManagement service that you can access. |
55 | 61 |
|
56 |
| -##### Sample code |
57 |
| - |
58 |
| -See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser. |
59 |
| - |
60 |
| -- index.html |
61 |
| -```html |
62 |
| -<!DOCTYPE html> |
63 |
| -<html lang="en"> |
64 |
| - <head> |
65 |
| - <title>@azure/arm-postgresql sample</title> |
66 |
| - <script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script> |
67 |
| - <script src="node_modules/@azure/ms-rest-azure-js/dist/msRestAzure.js"></script> |
68 |
| - <script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script> |
69 |
| - <script src="node_modules/@azure/arm-postgresql/dist/arm-postgresql.js"></script> |
70 |
| - <script type="text/javascript"> |
71 |
| - const subscriptionId = "<Subscription_Id>"; |
72 |
| - const authManager = new msAuth.AuthManager({ |
73 |
| - clientId: "<client id for your Azure AD app>", |
74 |
| - tenant: "<optional tenant for your organization>" |
75 |
| - }); |
76 |
| - authManager.finalizeLogin().then((res) => { |
77 |
| - if (!res.isLoggedIn) { |
78 |
| - // may cause redirects |
79 |
| - authManager.login(); |
80 |
| - } |
81 |
| - const client = new Azure.ArmPostgresql.PostgreSQLManagementClient(res.creds, subscriptionId); |
82 |
| - const resourceGroupName = "testresourceGroupName"; |
83 |
| - const serverName = "testserverName"; |
84 |
| - client.servers.get(resourceGroupName, serverName).then((result) => { |
85 |
| - console.log("The result is:"); |
86 |
| - console.log(result); |
87 |
| - }).catch((err) => { |
88 |
| - console.log("An error occurred:"); |
89 |
| - console.error(err); |
90 |
| - }); |
91 |
| - }); |
92 |
| - </script> |
93 |
| - </head> |
94 |
| - <body></body> |
95 |
| -</html> |
| 62 | +## Troubleshooting |
| 63 | + |
| 64 | +### Logging |
| 65 | + |
| 66 | +Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`: |
| 67 | + |
| 68 | +```javascript |
| 69 | +const { setLogLevel } = require("@azure/logger"); |
| 70 | +setLogLevel("info"); |
96 | 71 | ```
|
97 | 72 |
|
| 73 | +For more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger). |
| 74 | + |
| 75 | +## Next steps |
| 76 | + |
| 77 | +Please take a look at the [samples](https://github.com/Azure-Samples/azure-samples-js-management) directory for detailed examples on how to use this library. |
| 78 | + |
| 79 | +## Contributing |
| 80 | + |
| 81 | +If you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code. |
| 82 | + |
98 | 83 | ## Related projects
|
99 | 84 |
|
100 |
| -- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js) |
| 85 | +- [Microsoft Azure SDK for JavaScript](https://github.com/Azure/azure-sdk-for-js) |
| 86 | + |
| 87 | + |
101 | 88 |
|
102 |
| - |
| 89 | +[azure_cli]: https://docs.microsoft.com/cli/azure |
| 90 | +[azure_sub]: https://azure.microsoft.com/free/ |
| 91 | +[azure_sub]: https://azure.microsoft.com/free/ |
| 92 | +[azure_portal]: https://portal.azure.com |
| 93 | +[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity |
| 94 | +[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential |
0 commit comments