Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Swift 3,4,5...) AWS Secrets Manager - List SecretsSee more AWS Secrets Manager ExamplesLists the secrets that are stored by Secrets Manager in the AWS account. Lists the secrets that are stored by Secrets Manager in the AWS account. For more information, see https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_ListSecrets.html
func chilkatTest() { // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Sends the following sample request. // Note: Chilkat will automatically add Content-Length, X-Amz-Date, Accept-Encoding, and Authorization // POST / HTTP/1.1 // Host: secretsmanager.region.domain // Accept-Encoding: identity // X-Amz-Target: secretsmanager.ListSecrets // Content-Type: application/x-amz-json-1.1 // X-Amz-Date: <date> // Authorization: AWS4-HMAC-SHA256 Credential=<credentials>,SignedHeaders=<headers>, Signature=<signature> // Content-Length: <payload-size-bytes> // // {} let rest = CkoRest()! // Connect to the Amazon AWS REST server. // such as https://secretsmanager.us-west-2.amazonaws.com/ var bTls: Bool = true var port: Int = 443 var bAutoReconnect: Bool = true var success: Bool = rest.connect("secretsmanager.us-west-2.amazonaws.com", port: port, tls: bTls, autoReconnect: bAutoReconnect) // Provide AWS credentials for the REST call. let authAws = CkoAuthAws()! authAws.accessKey = "AWS_ACCESS_KEY" authAws.secretKey = "AWS_SECRET_KEY" // the region should match our URL above.. authAws.region = "us-west-2" authAws.serviceName = "secretsmanager" rest.setAuthAws(authAws) rest.addHeader("Content-Type", value: "application/x-amz-json-1.1") rest.addHeader("X-Amz-Target", value: "secretsmanager.ListSecrets") var strResponse: String? = rest.fullRequest("POST", uriPath: "/", bodyText: "{}") if rest.lastMethodSuccess == false { print("\(rest.lastErrorText!)") return } var respStatusCode: Int = rest.responseStatusCode.intValue print("response status code = \(respStatusCode)") let jResp = CkoJsonObject()! jResp.emitCompact = false jResp.load(strResponse) if respStatusCode >= 400 { print("Response Status Code = \(respStatusCode)") print("Response Header:") print("\(rest.responseHeader!)") print("Response Body:") print("\(jResp.emit()!)") return } print("Response Body:") print("\(jResp.emit()!)") // Sample response body: // { // "SecretList":[ // { // "ARN":"arn:aws:secretsmanager:us-west-2:123456789012:secret:MyTestDatabaseSecret-a1b2c3", // "Description":"My test database secret", // "LastChangedDate":1.523477145729E9, // "Name":"MyTestDatabaseSecret", // "SecretVersionsToStages":{ // "EXAMPLE2-90ab-cdef-fedc-ba987EXAMPLE":["AWSCURRENT"] // } // }, // { // "ARN":"arn:aws:secretsmanager:us-west-2:123456789012:secret:AnotherDatabaseSecret-d4e5f6", // "Description":"Another secret created for a different database", // "LastChangedDate":1.523482025685E9, // "Name":"AnotherDatabaseSecret", // "SecretVersionsToStages":{ // "EXAMPLE3-90ab-cdef-fedc-ba987EXAMPLE":["AWSCURRENT"] // } // } // ] // } var ARN: String? var Description: String? var LastChangedDate: String? var Name: String? var strVal: String? var i: Int = 0 var count_i: Int = jResp.size(ofArray: "SecretList").intValue while i < count_i { jResp.i = i ARN = jResp.string(of: "SecretList[i].ARN") Description = jResp.string(of: "SecretList[i].Description") LastChangedDate = jResp.string(of: "SecretList[i].LastChangedDate") Name = jResp.string(of: "SecretList[i].Name") var json2: CkoJsonObject? = jResp.object(of: "SecretList[i].SecretVersionsToStages") var count: Int = json2!.size.intValue var j: Int = 0 while j < count { var versionName: String? = json2!.name(at: j) var jarr: CkoJsonArray? = json2!.array(of: versionName) var stage: String? = jarr!.string(at: 0) print("versionName = \(versionName!)") print("stage = \(stage!)") j = j + 1 jarr = nil } json2 = nil i = i + 1 } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.