-
Notifications
You must be signed in to change notification settings - Fork 12
Add support for datasources #246
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -597,6 +597,30 @@ service /graphql on graphqlListener { | |||||||||||||||
| return check storage:getDataServicesByEnvironmentAndComponent(environmentId, componentId); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Get Data Sources for a specific environment and component | ||||||||||||||||
| isolated resource function get dataSourcesByEnvironmentAndComponent(graphql:Context context, string environmentId, string componentId) returns types:DataSource[]|error { | ||||||||||||||||
| types:UserContextV2 userContext = check extractUserContext(context); | ||||||||||||||||
|
|
||||||||||||||||
| // Get project ID for the component (lightweight query for access control) | ||||||||||||||||
| string projectId = check storage:getProjectIdByComponentId(componentId); | ||||||||||||||||
|
|
||||||||||||||||
| // Build scope with project, integration, and environment | ||||||||||||||||
| types:AccessScope scope = { | ||||||||||||||||
| orgUuid: 1, | ||||||||||||||||
| projectUuid: projectId, | ||||||||||||||||
| integrationUuid: componentId, | ||||||||||||||||
| envUuid: environmentId | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| // Verify user has view, edit, or manage permission | ||||||||||||||||
| if !check auth:hasAnyPermission(userContext.userId, [auth:PERMISSION_INTEGRATION_VIEW, auth:PERMISSION_INTEGRATION_EDIT, auth:PERMISSION_INTEGRATION_MANAGE], scope) { | ||||||||||||||||
| log:printWarn("Attempt to access component data sources without permission", userId = userContext.userId, environmentId = environmentId, componentId = componentId); | ||||||||||||||||
| return []; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| return check storage:getDataSourcesByEnvironmentAndComponent(environmentId, componentId); | ||||||||||||||||
|
Comment on lines
+619
to
+621
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log Improvement Suggestion No: 2
Suggested change
|
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Get Registry Resources for a specific environment and component | ||||||||||||||||
| isolated resource function get registryResourcesByEnvironmentAndComponent(graphql:Context context, string environmentId, string componentId) returns types:RegistryResource[]|error { | ||||||||||||||||
| types:UserContextV2 userContext = check extractUserContext(context); | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -626,6 +626,44 @@ public isolated function getDataServicesByEnvironmentAndComponent(string environ | |||||||||||
| return dataServiceList; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Get Data Sources for a specific environment and component | ||||||||||||
| public isolated function getDataSourcesByEnvironmentAndComponent(string environmentId, string componentId) returns types:DataSource[]|error { | ||||||||||||
|
Comment on lines
+629
to
+630
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log Improvement Suggestion No: 3
Suggested change
|
||||||||||||
| types:DataSource[] sourceList = []; | ||||||||||||
| map<string[]> sourceRuntimeMap = {}; | ||||||||||||
|
|
||||||||||||
| // Get all runtime IDs for this environment and component | ||||||||||||
| string[] runtimeIds = check getRuntimeIdsByEnvironmentAndComponent(environmentId, componentId); | ||||||||||||
|
|
||||||||||||
| // If no runtimes found, return empty array | ||||||||||||
| if runtimeIds.length() == 0 { | ||||||||||||
|
Comment on lines
+637
to
+638
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log Improvement Suggestion No: 4
Suggested change
|
||||||||||||
| return sourceList; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Get all Data Sources for these runtimes | ||||||||||||
| foreach string runtimeId in runtimeIds { | ||||||||||||
| types:DataSource[] runtimeSources = check getDataSourcesForRuntime(runtimeId); | ||||||||||||
| foreach types:DataSource ds in runtimeSources { | ||||||||||||
| string key = ds.name; | ||||||||||||
| string[] existing = sourceRuntimeMap[key] ?: []; | ||||||||||||
| if existing.length() == 0 { | ||||||||||||
| sourceRuntimeMap[key] = [runtimeId]; | ||||||||||||
| sourceList.push(ds); | ||||||||||||
| } else { | ||||||||||||
| existing.push(runtimeId); | ||||||||||||
| sourceRuntimeMap[key] = existing; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| foreach int i in 0..<(sourceList.length()) { | ||||||||||||
| types:DataSource ds = sourceList[i]; | ||||||||||||
| ds.runtimeIds = sourceRuntimeMap[ds.name] ?: []; | ||||||||||||
| sourceList[i] = ds; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return sourceList; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Get Registry Resources for a specific environment and component | ||||||||||||
| public isolated function getRegistryResourcesByEnvironmentAndComponent(string environmentId, string componentId) returns types:RegistryResource[]|error { | ||||||||||||
| types:RegistryResource[] resourceList = []; | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -695,10 +695,10 @@ isolated function insertAdditionalMIArtifacts(types:Heartbeat heartbeat) returns | |||||||||||||
| foreach types:DataSource dataSource in <types:DataSource[]>heartbeat.artifacts.dataSources { | ||||||||||||||
| _ = check dbClient->execute(` | ||||||||||||||
| INSERT INTO runtime_data_sources ( | ||||||||||||||
|
Comment on lines
695
to
697
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log Improvement Suggestion No: 5
Suggested change
|
||||||||||||||
| runtime_id, datasource_name, driver, url, state | ||||||||||||||
| runtime_id, datasource_name, datasource_type, driver, url, username, state | ||||||||||||||
| ) VALUES ( | ||||||||||||||
| ${heartbeat.runtime}, ${dataSource.name}, ${dataSource.driver}, | ||||||||||||||
| ${dataSource.url}, ${dataSource.state} | ||||||||||||||
| ${heartbeat.runtime}, ${dataSource.name}, ${dataSource.'type}, ${dataSource.driver}, | ||||||||||||||
| ${dataSource.url}, ${dataSource.username}, ${dataSource.state} | ||||||||||||||
| ) | ||||||||||||||
| `); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -524,7 +524,7 @@ isolated function parseCarbonAppArtifacts(json j) returns types:CarbonAppArtifac | |||||||||||
| public isolated function getDataSourcesForRuntime(string runtimeId) returns types:DataSource[]|error { | ||||||||||||
| types:DataSource[] sourceList = []; | ||||||||||||
| stream<types:DataSource, sql:Error?> sourceStream = dbClient->query(` | ||||||||||||
|
Comment on lines
525
to
526
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log Improvement Suggestion No: 6
Suggested change
|
||||||||||||
| SELECT datasource_name, driver, url, state | ||||||||||||
| SELECT datasource_name, datasource_type, driver, url, username, state | ||||||||||||
| FROM runtime_data_sources | ||||||||||||
| WHERE runtime_id = ${runtimeId} | ||||||||||||
| `); | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log Improvement Suggestion No: 1