-
-
Notifications
You must be signed in to change notification settings - Fork 47
feat(azure): add databases and split Cosmos NoSQL #149
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
Open
thomhurst
wants to merge
7
commits into
floci-io:main
Choose a base branch
from
thomhurst:agent/azure-sql
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
809a721
feat(azure): add SQL to cloud explorer
thomhurst 011ec98
fix(azure): isolate database list failures
thomhurst 5b8b7e9
refactor(azure): split Cosmos into NoSQL
thomhurst fb6dc85
fix(frontend): extend Azure SQL create timeout
thomhurst 730a2d5
fix(frontend): render structured metadata
thomhurst 788aa57
feat(azure): add SQL data explorer
thomhurst 6010b0a
feat(azure): support PostgreSQL explorer
thomhurst 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
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
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,126 @@ | ||
| import {describe, expect, test} from 'bun:test' | ||
| import type {AzureRuntimeClient, AzureRuntimeFetchOptions} from '../azure' | ||
| import {AzureSqlAdapter} from './AzureSqlAdapter' | ||
|
|
||
| const SERVERS_PATH = '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/floci-local/providers/Microsoft.Sql/servers' | ||
| const API_VERSION = '?api-version=2021-11-01' | ||
|
|
||
| describe('AzureSqlAdapter', () => { | ||
| test('normalizes Azure SQL servers as cloud database resources', async () => { | ||
| const adapter = new AzureSqlAdapter(testClient({ | ||
| [`${SERVERS_PATH}${API_VERSION}`]: { | ||
| value: [{ | ||
| id: `${SERVERS_PATH}/app-sql`, | ||
| name: 'app-sql', | ||
| type: 'Microsoft.Sql/servers', | ||
| location: 'eastus', | ||
| kind: 'v12.0', | ||
| tags: {environment: 'test'}, | ||
| properties: { | ||
| administratorLogin: 'sa', | ||
| version: '12.0', | ||
| state: 'Ready', | ||
| fullyQualifiedDomainName: 'localhost', | ||
| localPort: 14330, | ||
| publicNetworkAccess: 'Enabled', | ||
| }, | ||
| }], | ||
| }, | ||
| })) | ||
|
|
||
| await expect(adapter.list()).resolves.toEqual([{ | ||
| id: 'sql-server:app-sql', | ||
| name: 'app-sql', | ||
| cloud: 'azure', | ||
| service: 'database', | ||
| type: 'sql-server', | ||
| region: 'eastus', | ||
| createdAt: null, | ||
| status: 'Ready', | ||
| engine: 'azure-sql', | ||
| version: '12.0', | ||
| instanceClass: 'v12.0', | ||
| metadata: { | ||
| provider: 'azure', | ||
| databaseService: 'sql', | ||
| resourceKind: 'server', | ||
| armId: `${SERVERS_PATH}/app-sql`, | ||
| serverName: 'app-sql', | ||
| administratorLogin: 'sa', | ||
| fullyQualifiedDomainName: 'localhost', | ||
| publicNetworkAccess: 'Enabled', | ||
| minimalTlsVersion: undefined, | ||
| endpoint: {address: 'localhost', port: 14330}, | ||
| tags: [{key: 'environment', value: 'test'}], | ||
| }, | ||
| }]) | ||
| }) | ||
|
|
||
| test('creates an Azure SQL server through the ARM contract', async () => { | ||
| const calls: Array<{path: string; init: RequestInit}> = [] | ||
| const serverPath = `${SERVERS_PATH}/app-sql${API_VERSION}` | ||
| const adapter = new AzureSqlAdapter(testClient({ | ||
| [serverPath]: { | ||
| id: `${SERVERS_PATH}/app-sql`, | ||
| name: 'app-sql', | ||
| location: 'uksouth', | ||
| properties: {state: 'Ready', version: '12.0'}, | ||
| }, | ||
| }, calls)) | ||
|
|
||
| const resource = await adapter.create({values: { | ||
| serverName: 'app-sql', | ||
| location: 'uksouth', | ||
| administratorLogin: 'sqladmin', | ||
| administratorLoginPassword: 'StrongPassw0rd!', | ||
| }}) | ||
|
|
||
| expect(resource.id).toBe('sql-server:app-sql') | ||
| expect(calls).toHaveLength(1) | ||
| expect(calls[0].path).toBe(serverPath) | ||
| expect(calls[0].init.method).toBe('PUT') | ||
| expect(JSON.parse(String(calls[0].init.body))).toEqual({ | ||
| location: 'uksouth', | ||
| properties: { | ||
| administratorLogin: 'sqladmin', | ||
| administratorLoginPassword: 'StrongPassw0rd!', | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| test('gets and deletes a SQL server by its normalized id', async () => { | ||
| const calls: Array<{path: string; init: RequestInit}> = [] | ||
| const serverPath = `${SERVERS_PATH}/app-sql${API_VERSION}` | ||
| const adapter = new AzureSqlAdapter(testClient({ | ||
| [serverPath]: {name: 'app-sql', location: 'eastus', properties: {state: 'Ready'}}, | ||
| }, calls)) | ||
|
|
||
| await expect(adapter.get('sql-server:app-sql')).resolves.toMatchObject({name: 'app-sql', type: 'sql-server'}) | ||
| await adapter.delete('sql-server:app-sql') | ||
|
|
||
| expect(calls.map((call) => [call.init.method, call.path])).toEqual([ | ||
| ['GET', serverPath], | ||
| ['DELETE', serverPath], | ||
| ]) | ||
| }) | ||
|
|
||
| test('returns null when an Azure SQL server is not found', async () => { | ||
| const adapter = new AzureSqlAdapter(testClient({})) | ||
| await expect(adapter.get('sql-server:missing')).resolves.toBeNull() | ||
| }) | ||
| }) | ||
|
|
||
| function testClient(responses: Record<string, unknown>, calls: Array<{path: string; init: RequestInit}> = []): AzureRuntimeClient { | ||
| return { | ||
| endpoint: 'http://localhost:4577', | ||
| accountName: 'devstoreaccount1', | ||
| async fetch(path: string, init: RequestInit, options: AzureRuntimeFetchOptions = {}) { | ||
| calls.push({path, init}) | ||
| if (!(path in responses)) { | ||
| if (options.emptyOnNotFound) return null | ||
| throw new Error(`Unexpected Azure runtime request: ${path}`) | ||
| } | ||
| return new Response(JSON.stringify(responses[path]), {status: 200, headers: {'content-type': 'application/json'}}) | ||
| }, | ||
| } | ||
| } |
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.