From f4625f6c9c6db4d46a216079bdfe81e9227cfb10 Mon Sep 17 00:00:00 2001 From: Maxime Dufour Date: Fri, 14 Oct 2022 12:56:02 +0000 Subject: [PATCH] Set Default User-Agent --- .osc-patches/add_user_agent.patch | 22 ++++++++++++++++++++++ Makefile | 3 +++ dist/cjs/runtime.js | 7 +++++++ dist/esm/runtime.js | 7 +++++++ src/runtime.ts | 11 ++++++++++- 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .osc-patches/add_user_agent.patch diff --git a/.osc-patches/add_user_agent.patch b/.osc-patches/add_user_agent.patch new file mode 100644 index 00000000..cabb00f1 --- /dev/null +++ b/.osc-patches/add_user_agent.patch @@ -0,0 +1,22 @@ +diff --git a/src/runtime.ts b/src/runtime.ts +index 9465d6f..fe19573 100644 +--- a/src/runtime.ts ++++ b/src/runtime.ts +@@ -62,7 +62,16 @@ export class AwsV4Signer { + } + + export class Configuration { +- constructor(private configuration: ConfigurationParameters = {}) {} ++ constructor(private configuration: ConfigurationParameters = {}) { ++ if (typeof this.configuration.headers === "undefined") { ++ this.configuration.headers = {} ++ } ++ ++ const headers = this.configuration.headers ++ if (!("User-Agent" in headers)) { ++ headers["User-Agent"] = "osc-sdk-js/##SDK_VERSION##" ++ } ++ } + + set config(configuration: Configuration) { + this.configuration = configuration; diff --git a/Makefile b/Makefile index a4533262..ca92e7bd 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,9 @@ osc-generate: osc-api/outscale.yaml docker run -v $(PWD):/sdk --rm $(OPENAPI_IMG) sed -i "s/\"version\".*/\"version\": \"$(SDK_VERSION)\",/" /sdk/package.json docker run -v $(PWD):/sdk --rm $(OPENAPI_IMG) chown -R $(USER_ID).$(GROUP_ID) /sdk/.sdk mv .sdk/src ./ + (cd src && git apply ../.osc-patches/*) + # Set User-agent version + sed -i "s/##SDK_VERSION##/$(SDK_VERSION)/" src/runtime.ts @echo SDK generated @echo testing SDK build... @source ~/.nvm/nvm.sh; \ diff --git a/dist/cjs/runtime.js b/dist/cjs/runtime.js index def72393..9f5da97c 100644 --- a/dist/cjs/runtime.js +++ b/dist/cjs/runtime.js @@ -55,6 +55,13 @@ exports.AwsV4Signer = AwsV4Signer; class Configuration { constructor(configuration = {}) { this.configuration = configuration; + if (typeof this.configuration.headers === "undefined") { + this.configuration.headers = {}; + } + const headers = this.configuration.headers; + if (!("User-Agent" in headers)) { + headers["User-Agent"] = "osc-sdk-js/0.4.0"; + } } set config(configuration) { this.configuration = configuration; diff --git a/dist/esm/runtime.js b/dist/esm/runtime.js index a639bf67..1f556127 100644 --- a/dist/esm/runtime.js +++ b/dist/esm/runtime.js @@ -51,6 +51,13 @@ export class AwsV4Signer { export class Configuration { constructor(configuration = {}) { this.configuration = configuration; + if (typeof this.configuration.headers === "undefined") { + this.configuration.headers = {}; + } + const headers = this.configuration.headers; + if (!("User-Agent" in headers)) { + headers["User-Agent"] = "osc-sdk-js/0.4.0"; + } } set config(configuration) { this.configuration = configuration; diff --git a/src/runtime.ts b/src/runtime.ts index 9465d6fe..fe195735 100644 --- a/src/runtime.ts +++ b/src/runtime.ts @@ -62,7 +62,16 @@ export class AwsV4Signer { } export class Configuration { - constructor(private configuration: ConfigurationParameters = {}) {} + constructor(private configuration: ConfigurationParameters = {}) { + if (typeof this.configuration.headers === "undefined") { + this.configuration.headers = {} + } + + const headers = this.configuration.headers + if (!("User-Agent" in headers)) { + headers["User-Agent"] = "osc-sdk-js/0.4.0" + } + } set config(configuration: Configuration) { this.configuration = configuration;