{"id":21517823,"url":"https://github.com/brokenhandsio/swift-azure-sdk","last_synced_at":"2025-04-24T07:40:31.926Z","repository":{"id":215650357,"uuid":"734617853","full_name":"brokenhandsio/swift-azure-sdk","owner":"brokenhandsio","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-26T17:51:57.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-19T17:33:22.570Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brokenhandsio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-12-22T06:38:53.000Z","updated_at":"2024-12-26T17:52:01.000Z","dependencies_parsed_at":"2024-02-16T12:24:17.193Z","dependency_job_id":"3f3f8575-2ed0-4539-9626-524b72de4994","html_url":"https://github.com/brokenhandsio/swift-azure-sdk","commit_stats":null,"previous_names":["brokenhandsio/swift-azure-sdk"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brokenhandsio%2Fswift-azure-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brokenhandsio%2Fswift-azure-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brokenhandsio%2Fswift-azure-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brokenhandsio%2Fswift-azure-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brokenhandsio","download_url":"https://codeload.github.com/brokenhandsio/swift-azure-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235383724,"owners_count":18981199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T00:45:29.693Z","updated_at":"2025-01-24T03:47:17.146Z","avatar_url":"https://github.com/brokenhandsio.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swift Azure SDK\n\nCurrently this library only supports generating presigned URLs (\"SAS\") for Azure Storage\n\n## Vapor Setup\n\n`AzureClient` caches requested authentication tokens and needs to be shutdown properly, so it makes sense to\nextend `Application` with `AzureClient` to avoid recreating `AzureClient`s:\n\n```swift\nimport Vapor\n\npublic extension Application {\n    var azure: Azure {\n        .init(application: self)\n    }\n\n    struct Azure {\n        struct ClientKey: StorageKey {\n            typealias Value = AzureClient \n        }\n\n        public var client: AzureClient {\n            get {\n                guard let client = self.application.storage[ClientKey.self] else {\n                    fatalError(\"AzureClient not setup. Use application.azure.client = ...\")\n                }\n                return client\n            }\n            nonmutating set {\n                self.application.storage.set(ClientKey.self, to: newValue) {\n                    try $0.client.shutdown().wait()\n                }            \n            }\n        }\n\n        let application: Application\n    }\n}\n\npublic extension Request {\n    var azure: Azure {\n        .init(request: self)\n    }\n\n    struct Azure {\n        var client: AzureClient {\n            return request.application.azure.client\n        }\n\n        let request: Request\n    }\n}\n\n```\n\nThen in your `configure(_ app: Application)`:\n\n```swift\napp.azure.client = AzureClient(\n    client: client,\n    logger: app.logger,\n    tenantID: \u003ctenantID goes here\u003e,\n    clientID: \u003cclientID goes here\u003e,\n    clientSecret: \u003cclientSecret goes here\u003e\n) \n```\n\nOptionally: Extend our new `Application.Azure` struct with `Storage`:\n\n```swift\nextension Application.Azure {\n    struct StorageKey: StorageKey {\n        typealias Value = AzureStorage\n    }\n\n    public var storage: AzureStorage {\n        get {\n            guard let storage = self.application.storage[StorageKey.self] else {\n                fatalError(\"AzureStorage not setup. Use application.azure.storage = ...\")\n            }\n            return storage\n        }\n        nonmutating set {\n            self.application.storage[StorageKey.self] = newValue\n        }\n    }\n}\n\npublic extension Request.Azure {\n    var storage: AzureStorage {\n        return request.application.azure.storage\n    }\n}\n```\n\nDon't forget to set up the storage service in your `configure(_ app: Application)`:\n\n```swift\napp.azure.storage = AzureStorage(client: app.azure.client, accountURL: \"https://brokenhandstest.blob.core.windows.net\")\n```\n\n## Generate SAS (\"presigned URLs\")\n\nE.g. in your request handler:\n\n```swift\nfunc getSAS(_ req: Request) async throws -\u003e String {\n    let userDelegationKey = try await req.azure.storage.requestUserDelegationKey(\n        keyExpiryTime: Date(timeIntervalSinceNow: 60 * 15)\n    )\n\n    let sas = storage.constructUserDelegationSAS(\n        accountName: \"brokenhandstest\",\n        containerName: \"test-container\",\n        blobName: \"123\",\n        userDelegationKey: userDelegationKey\n    )\n\n    return sas\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrokenhandsio%2Fswift-azure-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrokenhandsio%2Fswift-azure-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrokenhandsio%2Fswift-azure-sdk/lists"}