96 lines
3.0 KiB
Swift
96 lines
3.0 KiB
Swift
// CxLLM Studio — macOS Application
|
|
// Services/AWSService.swift — AWS DevOps integration service
|
|
|
|
import Foundation
|
|
import CxAWS
|
|
import CxCode
|
|
|
|
@Observable
|
|
final class AWSService {
|
|
private(set) var isConnected = false
|
|
private(set) var healthStatus: AWSHealthStatus?
|
|
private(set) var repositories: [[String: Any]] = []
|
|
private(set) var pipelines: [[String: Any]] = []
|
|
private(set) var pullRequests: [[String: Any]] = []
|
|
private(set) var builds: [[String: Any]] = []
|
|
private(set) var error: String?
|
|
|
|
let client: CxAWSClient
|
|
|
|
init(config: CxAWSConfig) {
|
|
self.client = CxAWSClient(config: config)
|
|
}
|
|
|
|
func checkHealth() async {
|
|
let health = await client.healthCheck()
|
|
healthStatus = health
|
|
isConnected = health.status == "ok"
|
|
}
|
|
|
|
func loadRepositories() async {
|
|
do {
|
|
let result = try await client.codecommitListRepositories()
|
|
repositories = result["repositories"] as? [[String: Any]] ?? []
|
|
error = nil
|
|
} catch {
|
|
self.error = error.localizedDescription
|
|
}
|
|
}
|
|
|
|
func loadPipelines() async {
|
|
do {
|
|
let result = try await client.codepipelineListPipelines()
|
|
pipelines = result["pipelines"] as? [[String: Any]] ?? []
|
|
error = nil
|
|
} catch {
|
|
self.error = error.localizedDescription
|
|
}
|
|
}
|
|
|
|
func loadPullRequests(repo: String) async {
|
|
do {
|
|
let result = try await client.codecommitListPullRequests(repo)
|
|
pullRequests = (result["pullRequestIds"] as? [String])?.map { ["id": $0] } ?? []
|
|
error = nil
|
|
} catch {
|
|
self.error = error.localizedDescription
|
|
}
|
|
}
|
|
|
|
func startPipeline(_ name: String) async throws {
|
|
_ = try await client.codepipelineStartExecution(name)
|
|
}
|
|
|
|
func stopPipeline(_ name: String, executionId: String) async throws {
|
|
_ = try await client.codepipelineStopExecution(name, executionId: executionId)
|
|
}
|
|
|
|
func startBuild(_ project: String) async throws -> [String: Any] {
|
|
try await client.codebuildStartBuild(project)
|
|
}
|
|
|
|
func getBuildStatus(_ ids: [String]) async throws -> [String: Any] {
|
|
try await client.codebuildBatchGetBuilds(ids)
|
|
}
|
|
|
|
func getFile(repo: String, path: String, ref: String = "") async throws -> [String: Any] {
|
|
try await client.codecommitGetFile(repo, path: path, ref: ref)
|
|
}
|
|
|
|
func getPipelineState(_ name: String) async throws -> [String: Any] {
|
|
try await client.codepipelineGetPipelineState(name)
|
|
}
|
|
|
|
func getLogGroups() async throws -> [String: Any] {
|
|
try await client.logsDescribeLogGroups(prefix: "/aws/codebuild/")
|
|
}
|
|
|
|
func getLogStreams(logGroup: String) async throws -> [String: Any] {
|
|
try await client.logsDescribeLogStreams(logGroup: logGroup)
|
|
}
|
|
|
|
func getLogEvents(logGroup: String, logStream: String) async throws -> [String: Any] {
|
|
try await client.logsGetLogEvents(logGroup: logGroup, logStream: logStream)
|
|
}
|
|
}
|