-
Notifications
You must be signed in to change notification settings - Fork 82
Abstract the Postgres management client to allow both single and flexible server #1872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e59b5a5
Add flexible server to the package deps
tonybaloney dd449ba
reformat package json
tonybaloney a2a3c21
package updates
tonybaloney 30cc07a
Create an abstraction to list servers from both single and flexible
tonybaloney b959bca
Implement database listing
tonybaloney 0aee0c9
Implement the delete server method
tonybaloney 6f45fa8
Adapt the create server workflow to work with both single and flex
tonybaloney c82e084
Implement the firewall rule and server name APIs
tonybaloney c613c41
Update package lock
tonybaloney e9ac3af
Fix the single server password error
tonybaloney 9053fb3
Extend the base types
tonybaloney dbc4f71
Propagate client options to fix the API versioning errors
tonybaloney eaedf83
Remove the interface and update method names based on PR review
tonybaloney 27b5527
Document the storage sizes
tonybaloney 6c088fe
Add more skus
tonybaloney bb01e7a
Refactor from PR review
tonybaloney a653cb5
Update src/postgres/abstract/models.ts
tonybaloney 2e52481
Another round of PR revisions
tonybaloney c6244c5
Fix the abstract client listing
tonybaloney e3e9197
Update @azure/arm-postgresql-flexible to the patched version
tonybaloney 05f8b4a
Merge branch 'main' into postgres_patch_update
tonybaloney 4eaf7f1
Cleanup merge commit
tonybaloney 9626855
Switch server resoure on name lookup for resource type
tonybaloney cb353d4
Set default versions and mention preview to flexible
tonybaloney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { PostgreSQLManagementClient } from "@azure/arm-postgresql"; | ||
| import { PostgreSQLFlexibleManagementClient } from "@azure/arm-postgresql-flexible"; | ||
| import * as msRest from "@azure/ms-rest-js"; | ||
| import { IMinimumServiceClientOptions } from "vscode-azureextensionui"; | ||
| import { IAbstractPostgresClient } from "./IAbstractPostgresClient"; | ||
| import { asAbstractDatabase, asFlexibleParameters, asSingleParameters, flexibleAsAbstractServer, singleAsAbstractServer } from "./maps"; | ||
| import * as Models from "./models"; | ||
|
|
||
| export class AbstractPostgresClient implements IAbstractPostgresClient { | ||
|
tonybaloney marked this conversation as resolved.
Outdated
|
||
| private postgresFlexibleClient: PostgreSQLFlexibleManagementClient; | ||
| private postgresSingleClient: PostgreSQLManagementClient; | ||
|
|
||
| constructor(credentials: msRest.ServiceClientCredentials, subscriptionId: string, options?: IMinimumServiceClientOptions) { | ||
| this.postgresFlexibleClient = new PostgreSQLFlexibleManagementClient(credentials, subscriptionId, options); | ||
| this.postgresSingleClient = new PostgreSQLManagementClient(credentials, subscriptionId, options); | ||
| } | ||
|
|
||
| async checkNameAvailability(serverType: Models.PostgresServerType, name: string) : Promise<Models.AbstractNameAvailability> { | ||
| switch (serverType){ | ||
| case Models.PostgresServerType.Flexible: | ||
| return this.postgresFlexibleClient.checkNameAvailability.execute({name: name, type: "Microsoft.DBforPostgreSQL"}); | ||
| case Models.PostgresServerType.Single: | ||
| return this.postgresSingleClient.checkNameAvailability.execute({name: name, type: "Microsoft.DBforPostgreSQL"}); | ||
| default: | ||
| throw new Error("Service not implemented."); | ||
| } | ||
| } | ||
|
|
||
| async createFirewallRule(serverType: Models.PostgresServerType, resourceGroup: string, name: string, ruleName: string, rule: Models.AbstractFirewallRule): Promise<Models.AbstractFirewallRule> { | ||
|
tonybaloney marked this conversation as resolved.
Outdated
|
||
| switch (serverType){ | ||
| case Models.PostgresServerType.Flexible: | ||
| return this.postgresFlexibleClient.firewallRules.createOrUpdate(resourceGroup, name, ruleName, rule); | ||
| case Models.PostgresServerType.Single: | ||
| return this.postgresSingleClient.firewallRules.createOrUpdate(resourceGroup, name, ruleName, rule); | ||
| default: | ||
| throw new Error("Service not implemented."); | ||
| } | ||
| } | ||
|
|
||
| async createServer(serverType: Models.PostgresServerType, resourceGroup: string, name: string, parameters: Models.AbstractServerCreate): Promise<Models.PostgresAbstractServer> { | ||
|
tonybaloney marked this conversation as resolved.
Outdated
|
||
| switch (serverType){ | ||
| case Models.PostgresServerType.Flexible: | ||
| return flexibleAsAbstractServer(await this.postgresFlexibleClient.servers.create(resourceGroup, name, asFlexibleParameters(parameters))); | ||
| case Models.PostgresServerType.Single: | ||
| return singleAsAbstractServer(await this.postgresSingleClient.servers.create(resourceGroup, name, asSingleParameters(parameters))); | ||
| default: | ||
| throw new Error("Service not implemented."); | ||
| } | ||
| } | ||
|
|
||
| async deleteServer(serverType: Models.PostgresServerType, resourceGroup: string, name: string): Promise<msRest.RestResponse> { | ||
| switch (serverType){ | ||
| case Models.PostgresServerType.Flexible: | ||
| return this.postgresFlexibleClient.servers.deleteMethod(resourceGroup, name); | ||
| case Models.PostgresServerType.Single: | ||
| return this.postgresSingleClient.servers.deleteMethod(resourceGroup, name); | ||
| default: | ||
| throw new Error("Service not implemented."); | ||
| } | ||
| } | ||
|
|
||
| async listServers(): Promise<Models.PostgresAbstractServerList> { | ||
|
tonybaloney marked this conversation as resolved.
Outdated
|
||
| const flexServers = (await this.postgresFlexibleClient.servers.list()).map(flexibleAsAbstractServer); | ||
| const singleServers = (await this.postgresSingleClient.servers.list()).map(singleAsAbstractServer); | ||
| return Array<Models.PostgresAbstractServer>().concat(flexServers, singleServers); | ||
| } | ||
|
|
||
| async listDatabases(serverType: Models.PostgresServerType, resourceGroup: string, name: string): Promise<Models.PostgresAbstractDatabaseList> { | ||
| switch (serverType){ | ||
| case Models.PostgresServerType.Flexible: | ||
| return (await this.postgresFlexibleClient.databases.listByServer(resourceGroup, name)).map(asAbstractDatabase); | ||
| case Models.PostgresServerType.Single: | ||
| return (await this.postgresSingleClient.databases.listByServer(resourceGroup, name)).map(asAbstractDatabase); | ||
| default: | ||
| throw new Error("Service not implemented."); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import * as msRest from "@azure/ms-rest-js"; | ||
| import * as Models from './models'; | ||
|
|
||
| export interface IAbstractPostgresClient { | ||
| deleteServer(serverType: Models.PostgresServerType, resourceGroup: string, name: string): Promise<msRest.RestResponse>; | ||
| listDatabases(serverType: Models.PostgresServerType, resourceGroup: string, name: string): Promise<Models.PostgresAbstractDatabaseList>; | ||
| listServers(): Promise<Models.PostgresAbstractServerList>; | ||
| createServer(serverType: Models.PostgresServerType, resourceGroup: string, name: string, options: Models.AbstractServerCreate): Promise<Models.PostgresAbstractServer>; | ||
| checkNameAvailability(serverType: Models.PostgresServerType, name: string) : Promise<Models.AbstractNameAvailability>; | ||
| createFirewallRule(serverType: Models.PostgresServerType, resourceGroup: string, name: string, ruleName: string, rule: Models.AbstractFirewallRule) : Promise<Models.AbstractFirewallRule>; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.