From 80c69d57f89dddd3b3f91ed7bc52247bd8ecebda Mon Sep 17 00:00:00 2001 From: abdelDriowya <111757332+abdelDriowya@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:39:12 +0200 Subject: [PATCH 1/7] fix file encoding --- chocolatey/update-version.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chocolatey/update-version.ps1 b/chocolatey/update-version.ps1 index 4010cceb2..83767e941 100644 --- a/chocolatey/update-version.ps1 +++ b/chocolatey/update-version.ps1 @@ -16,10 +16,10 @@ Write-Verbose "getting checksum from $checksumURL to $tmpFile" ### replace hash $hash = (Get-Content $tmpFile | where {$_ -like "*windows_amd64.zip"}).split(" ")[0] $installerPath = ".\circleci-cli\tools\chocolateyinstall.ps1" -(Get-Content $installerPath).Replace('$HASH',$hash) | Out-File $installerPath -Force +(Get-Content $installerPath).Replace('$HASH',$hash) | Out-File $installerPath -Force -Encoding ASCII $downloadURL = "https://github.com/CircleCI-Public/circleci-cli/releases/download/v$curVersion/circleci-cli_$($curVersion)_windows_amd64.zip" -(Get-Content $installerPath).Replace('$DOWNLOAD_URL',$downloadURL) | Out-File $installerPath -Force +(Get-Content $installerPath).Replace('$DOWNLOAD_URL',$downloadURL) | Out-File $installerPath -Force -Encoding ASCII $nuspecPath = "./circleci-cli/circleci-cli.nuspec" -(Get-Content $nuspecPath).Replace('$VER',$curVersion) | Out-File $nuspecPath -Force +(Get-Content $nuspecPath).Replace('$VER',$curVersion) | Out-File $nuspecPath -Force -Encoding ASCII From cfda6a4e961c7daf2864a4f9185e67e42a7b8d5c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Oct 2023 10:08:36 +0200 Subject: [PATCH 2/7] chore(deps): bump golang.org/x/net from 0.12.0 to 0.17.0 (#1010) Bumps [golang.org/x/net](https://github.com/golang/net) from 0.12.0 to 0.17.0. - [Commits](https://github.com/golang/net/compare/v0.12.0...v0.17.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 710386a9d..2374ce2b9 100644 --- a/go.mod +++ b/go.mod @@ -41,7 +41,7 @@ require ( github.com/spf13/afero v1.9.5 github.com/stretchr/testify v1.8.3 golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 - golang.org/x/term v0.10.0 + golang.org/x/term v0.13.0 ) require ( @@ -111,10 +111,10 @@ require ( go.opentelemetry.io/otel/metric v1.16.0 // indirect go.opentelemetry.io/otel/sdk v1.16.0 // indirect go.opentelemetry.io/otel/trace v1.16.0 // indirect - golang.org/x/crypto v0.11.0 // indirect - golang.org/x/net v0.12.0 // indirect - golang.org/x/sys v0.10.0 // indirect - golang.org/x/text v0.11.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect google.golang.org/genproto v0.0.0-20230724170836-66ad5b6ff146 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect diff --git a/go.sum b/go.sum index 4d5d49640..00cb5ea45 100644 --- a/go.sum +++ b/go.sum @@ -432,8 +432,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= -golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -509,8 +509,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= -golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -592,15 +592,15 @@ golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c= -golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= +golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -611,8 +611,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= -golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From c16c285f413d73154c62fc3623b1b5707a59348a Mon Sep 17 00:00:00 2001 From: JulesFaucherre Date: Tue, 17 Oct 2023 10:36:31 +0200 Subject: [PATCH 3/7] chore: Update code of conduct (#1011) --- CODE_OF_CONDUCT.md | 129 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 108 insertions(+), 21 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 924e8effd..f92a887ab 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -2,45 +2,132 @@ ## Our Pledge -In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. ## Our Standards -Examples of behavior that contributes to creating a positive environment include: +Examples of behavior that contributes to a positive environment for our +community include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community -Examples of unacceptable behavior by participants include: +Examples of unacceptable behavior include: -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting -## Our Responsibilities +## Enforcement Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. ## Scope -This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at foss@circleci.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[INSERT CONTACT METHOD]. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. -Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ From 26fb5a679f8e0fef5906a33260cce1838a0c87de Mon Sep 17 00:00:00 2001 From: or-shachar Date: Thu, 26 Oct 2023 15:31:23 +0300 Subject: [PATCH 4/7] feat: default http client timeout override --- api/rest/client.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/api/rest/client.go b/api/rest/client.go index 1e8e9e6bb..075dc7d22 100644 --- a/api/rest/client.go +++ b/api/rest/client.go @@ -8,6 +8,7 @@ import ( "io" "net/http" "net/url" + "os" "strings" "time" @@ -16,6 +17,8 @@ import ( "github.com/CircleCI-Public/circleci-cli/version" ) +const defaultTimeout = 10 * time.Second + type Client struct { BaseURL *url.URL circleToken string @@ -38,9 +41,17 @@ func NewFromConfig(host string, config *settings.Config) *Client { } baseURL, _ := url.Parse(host) + timeout := defaultTimeout + if timeoutEnv, ok := os.LookupEnv("HTTP_TIMEOUT"); ok { + if parsedTimeout, err := time.ParseDuration(timeoutEnv); err == nil { + timeout = parsedTimeout + } else { + fmt.Printf("failed to parse HTTP_TIMEOUT_SECONDS: %s\n", err.Error()) + } + } client := config.HTTPClient - client.Timeout = 10 * time.Second + client.Timeout = timeout return New( baseURL.ResolveReference(&url.URL{Path: endpoint}), From b35e35d1c698906da9c511077a3f4bde0e112afd Mon Sep 17 00:00:00 2001 From: Or Shachar Date: Thu, 2 Nov 2023 18:51:33 +0200 Subject: [PATCH 5/7] Update client.go --- api/rest/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/rest/client.go b/api/rest/client.go index 075dc7d22..89dfb4149 100644 --- a/api/rest/client.go +++ b/api/rest/client.go @@ -42,7 +42,7 @@ func NewFromConfig(host string, config *settings.Config) *Client { baseURL, _ := url.Parse(host) timeout := defaultTimeout - if timeoutEnv, ok := os.LookupEnv("HTTP_TIMEOUT"); ok { + if timeoutEnv, ok := os.LookupEnv("CIRCLECI_CLI_TIMEOUT"); ok { if parsedTimeout, err := time.ParseDuration(timeoutEnv); err == nil { timeout = parsedTimeout } else { From 7ab86345fc9af5ba62f616d40648c2ea490d0eba Mon Sep 17 00:00:00 2001 From: abdelDriowya <111757332+abdelDriowya@users.noreply.github.com> Date: Mon, 6 Nov 2023 18:17:31 +0100 Subject: [PATCH 6/7] use same timeout value for http client & graphql --- api/header/global.go | 8 ++++++++ api/rest/client.go | 4 +--- settings/settings.go | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/api/header/global.go b/api/header/global.go index a3470c15d..49bcebe15 100644 --- a/api/header/global.go +++ b/api/header/global.go @@ -1,5 +1,7 @@ package header +import "time" + // When the CLI is initialized, we set this to a string of the current CLI subcommand // (e.g. `circleci orb list`) with no args or flags, so we include it as a header in API requests. var cliCommandStr string = "" @@ -11,3 +13,9 @@ func SetCommandStr(commandStr string) { func GetCommandStr() string { return cliCommandStr } + +const defaultTimeout = 60 * time.Second + +func GetDefaultTimeout() time.Duration { + return defaultTimeout +} diff --git a/api/rest/client.go b/api/rest/client.go index 89dfb4149..3a3cb9954 100644 --- a/api/rest/client.go +++ b/api/rest/client.go @@ -17,8 +17,6 @@ import ( "github.com/CircleCI-Public/circleci-cli/version" ) -const defaultTimeout = 10 * time.Second - type Client struct { BaseURL *url.URL circleToken string @@ -41,7 +39,7 @@ func NewFromConfig(host string, config *settings.Config) *Client { } baseURL, _ := url.Parse(host) - timeout := defaultTimeout + timeout := header.GetDefaultTimeout() if timeoutEnv, ok := os.LookupEnv("CIRCLECI_CLI_TIMEOUT"); ok { if parsedTimeout, err := time.ParseDuration(timeoutEnv); err == nil { timeout = parsedTimeout diff --git a/settings/settings.go b/settings/settings.go index 7a9e7f0e4..162235543 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -16,6 +16,7 @@ import ( yaml "gopkg.in/yaml.v3" + "github.com/CircleCI-Public/circleci-cli/api/header" "github.com/CircleCI-Public/circleci-cli/data" "github.com/spf13/afero" ) @@ -287,7 +288,7 @@ func (cfg *Config) WithHTTPClient() error { customTransport.TLSClientConfig = tlsConfig cfg.HTTPClient = &http.Client{ - Timeout: 60 * time.Second, + Timeout: header.GetDefaultTimeout(), Transport: customTransport, } From 9dc48a4266c66ef8c39662eadd68776e284e1191 Mon Sep 17 00:00:00 2001 From: abdelDriowya <111757332+abdelDriowya@users.noreply.github.com> Date: Tue, 7 Nov 2023 12:00:41 +0100 Subject: [PATCH 7/7] add test --- api/rest/client.go | 2 +- api/rest/client_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/api/rest/client.go b/api/rest/client.go index 3a3cb9954..d35363d91 100644 --- a/api/rest/client.go +++ b/api/rest/client.go @@ -44,7 +44,7 @@ func NewFromConfig(host string, config *settings.Config) *Client { if parsedTimeout, err := time.ParseDuration(timeoutEnv); err == nil { timeout = parsedTimeout } else { - fmt.Printf("failed to parse HTTP_TIMEOUT_SECONDS: %s\n", err.Error()) + fmt.Printf("failed to parse CIRCLECI_CLI_TIMEOUT: %s\n", err.Error()) } } diff --git a/api/rest/client_test.go b/api/rest/client_test.go index 30f552092..805a37414 100644 --- a/api/rest/client_test.go +++ b/api/rest/client_test.go @@ -6,15 +6,37 @@ import ( "net/http" "net/http/httptest" "net/url" + "os" "sync" "testing" + "time" "github.com/stretchr/testify/assert" + "github.com/CircleCI-Public/circleci-cli/api/header" "github.com/CircleCI-Public/circleci-cli/settings" "github.com/CircleCI-Public/circleci-cli/version" ) +func TestNewFromConfigTimeout(t *testing.T) { + cfg := &settings.Config{ + Debug: false, + Token: "fake-token", + RestEndpoint: "api/v2", + Endpoint: "api/v2", + HTTPClient: http.DefaultClient, + } + t.Run("create new client without custom timeout", func(t *testing.T) { + api := NewFromConfig("host", cfg) + assert.Equal(t, api.client.Timeout, header.GetDefaultTimeout()) + }) + t.Run("create new client with custom timeout", func(t *testing.T) { + customTimeout := 20 * time.Second + os.Setenv("CIRCLECI_CLI_TIMEOUT", customTimeout.String()) + api := NewFromConfig("host", cfg) + assert.Equal(t, api.client.Timeout, customTimeout) + }) +} func TestClient_DoRequest(t *testing.T) { t.Run("PUT with req and resp", func(t *testing.T) { fix := &fixture{}