This repository was archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Create database route, endpoint and service #288
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4970148
:sparkles: Add database route, endpoint + getters
rudream 30393f8
:sparkles: Create makeDB & instantiate service
rudream 4d58936
:memo: Split up formatProtocol and formatType
rudream 8f6273a
:memo: Change service to class
rudream 3fa5b24
:memo: Combine protocol and type fields
rudream 949a8dc
:memo: Display 'Self-hosted' type
rudream cd457ab
:white_check_mark: Add unit test
rudream c868450
:memo: Move DatabaseList component folder
rudream 8dba737
:art: Update DatabaseList table formatting
rudream 945b984
:memo: Remove uri field
rudream 8917045
:white_check_mark: Add tests for type/protocol
rudream f98b173
:memo: Add better test logging, remove json.items
rudream cf00b68
:white_check_mark: Add test for null response
rudream 7780bd5
:memo: Rename services/database folder
rudream 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
File renamed without changes.
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,74 @@ | ||
/* | ||
Copyright 2021 Gravitational, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import DatabaseService from './databases'; | ||
import api from 'teleport/services/api'; | ||
|
||
test('correct formatting of database fetch response', async () => { | ||
jest.spyOn(api, 'get').mockResolvedValue(mockResponse); | ||
|
||
const database = new DatabaseService(); | ||
const response = await database.fetchDatabases('im-a-cluster'); | ||
|
||
expect(response).toEqual([ | ||
{ | ||
name: 'aurora', | ||
desc: 'PostgreSQL 11.6: AWS Aurora', | ||
type: 'RDS PostgreSQL', | ||
tags: ['cluster: root', 'env: aws'], | ||
}, | ||
]); | ||
}); | ||
|
||
describe('correct formatting of all type and protocol combos', () => { | ||
test.each` | ||
type | protocol | combined | ||
${'self-hosted'} | ${'mysql'} | ${'Self-hosted MySQL'} | ||
${'rds'} | ${'mysql'} | ${'RDS MySQL'} | ||
${'gcp'} | ${'mysql'} | ${'Cloud SQL MySQL'} | ||
${'redshift'} | ${'mysql'} | ${'Redshift MySQL'} | ||
${'self-hosted'} | ${'postgres'} | ${'Self-hosted PostgreSQL'} | ||
${'rds'} | ${'postgres'} | ${'RDS PostgreSQL'} | ||
${'gcp'} | ${'postgres'} | ${'Cloud SQL PostgreSQL'} | ||
${'redshift'} | ${'postgres'} | ${'Redshift PostgreSQL'} | ||
${'some other type'} | ${'some other protocol'} | ${'some other type some other protocol'} | ||
`( | ||
'should combine type: $type and protocol: $protocol correctly', | ||
async ({ type, protocol, combined }) => { | ||
jest.spyOn(api, 'get').mockResolvedValue([{ type, protocol }]); | ||
|
||
const database = new DatabaseService(); | ||
const response = await database.fetchDatabases('im-a-cluster'); | ||
|
||
expect(response[0].type).toBe(combined); | ||
} | ||
); | ||
}); | ||
|
||
const mockResponse = [ | ||
rudream marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
name: 'aurora', | ||
desc: 'PostgreSQL 11.6: AWS Aurora', | ||
protocol: 'postgres', | ||
type: 'rds', | ||
uri: | ||
'postgres-aurora-instance-1.c1xpjrob56xs.us-west-1.rds.amazonaws.com:5432', | ||
labels: [ | ||
{ name: 'cluster', value: 'root' }, | ||
{ name: 'env', value: 'aws' }, | ||
], | ||
}, | ||
]; |
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,30 @@ | ||
/* | ||
Copyright 2021 Gravitational, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { map } from 'lodash'; | ||
import api from 'teleport/services/api'; | ||
import cfg from 'teleport/config'; | ||
import makeDatabase from './makeDatabase'; | ||
|
||
class DatabaseService { | ||
fetchDatabases(clusterId?: string) { | ||
return api | ||
.get(cfg.getDatabasesRoute(clusterId)) | ||
.then(json => map(json, makeDatabase)); | ||
} | ||
} | ||
|
||
export default DatabaseService; |
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,54 @@ | ||
/* | ||
Copyright 2021 Gravitational, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { Database } from './types'; | ||
|
||
export default function makeDatabase(json): Database { | ||
const { name, desc, protocol, type, labels = [] } = json; | ||
|
||
return { | ||
name, | ||
desc, | ||
type: `${formatType(type)} ${formatProtocol(protocol)}`, | ||
tags: labels.map(label => `${label.name}: ${label.value}`), | ||
}; | ||
} | ||
|
||
const formatType = (input: string) => { | ||
switch (input) { | ||
case 'self-hosted': | ||
return 'Self-hosted'; | ||
case 'rds': | ||
return 'RDS'; | ||
case 'gcp': | ||
return 'Cloud SQL'; | ||
case 'redshift': | ||
return 'Redshift'; | ||
default: | ||
return input; | ||
} | ||
}; | ||
|
||
const formatProtocol = (input: string) => { | ||
switch (input) { | ||
case 'postgres': | ||
return 'PostgreSQL'; | ||
case 'mysql': | ||
return 'MySQL'; | ||
default: | ||
return input; | ||
} | ||
}; |
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
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.