Skip to content

Commit b69aaf2

Browse files
authored
chore(python): add user agent suffix to kms requests (#1686)
1 parent bb0ec0c commit b69aaf2

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

.releaserc.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,15 @@ module.exports = {
372372
),
373373
countMatches: true,
374374
},
375+
376+
// Update the version in ComAmazonawsKms/src/Index.dfy DafnyUserAgentSuffix function
377+
{
378+
files: ["ComAmazonawsKms/src/Index.dfy"],
379+
from: 'var version := ".*"',
380+
to: 'var version := "${nextRelease.version}"',
381+
results: [CheckResults("ComAmazonawsKms/src/Index.dfy")],
382+
countMatches: true,
383+
},
375384
],
376385
},
377386
],
@@ -389,6 +398,7 @@ module.exports = {
389398
{
390399
assets: [
391400
"CHANGELOG.md",
401+
"ComAmazonawsKms/src/Index.dfy",
392402
...Object.values(Runtimes).flatMap((r) => Object.keys(r)),
393403
...Object.values(Runtimes.net).flatMap((r) => r.assemblyInfo),
394404
"**/runtimes/python/**/*.dtr",

ComAmazonawsKms/runtimes/python/src/aws_cryptography_internal_kms/internaldafny/extern/Com_Amazonaws_Kms.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
13
import boto3
24
import _dafny
35

@@ -25,15 +27,22 @@ class default__(aws_cryptography_internal_kms.internaldafny.generated.Com_Amazon
2527
def KMSClient(boto_client = None, region = None):
2628
if boto_client is None:
2729
if region is not None and region in get_available_aws_regions():
28-
boto_config = Config(
29-
region_name=region
30-
)
30+
boto_config = Config(region_name=region)
3131
boto_client = boto3.client("kms", config=boto_config)
3232
else:
3333
# If no region is provided,
3434
# boto_client will use the default region provided by boto3
3535
boto_client = boto3.client("kms")
3636
region = boto_client.meta.region_name
37+
38+
# Generate user agent suffix: AwsCryptographicMPL/Python/{version}
39+
runtime = _dafny.Seq("Python")
40+
user_agent_suffix = _dafny.string_of(aws_cryptography_internal_kms.internaldafny.generated.Com_Amazonaws_Kms.default__.DafnyUserAgentSuffix(runtime))
41+
if boto_client.meta.config.user_agent_extra is None:
42+
boto_client.meta.config.user_agent_extra = user_agent_suffix
43+
elif user_agent_suffix not in boto_client.meta.config.user_agent_extra:
44+
boto_client.meta.config.user_agent_extra += " " + user_agent_suffix
45+
3746
wrapped_client = KMSClientShim(boto_client, region)
3847
return Wrappers.Result_Success(wrapped_client)
3948

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
13
from . import (
24
Com_Amazonaws_Kms,
35
)

ComAmazonawsKms/src/Index.dfy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module {:extern "software.amazon.cryptography.services.kms.internaldafny"} Com.A
3030

3131
function method DafnyUserAgentSuffix(runtime: string): string
3232
{
33+
// This version is automatically updated by semantic-release
3334
var version := "1.11.0";
3435
"AwsCryptographicMPL/" + runtime + "/" + version
3536
}

0 commit comments

Comments
 (0)