~emersion/hut-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] Make timeout configurable

Details
Message ID
<20220516145804.29991-1-blallo@autistici.org>
DKIM signature
pass
Download raw message
Patch: +14 -3
The http client used for interacting with the hut instance had a
hardcoded 30 seconds timeout. While this might be ok in most cases, I
happened to hit one of the corner cases when trying to push a tarball to
site.ht. This commit adds a global flag to set the value, defaulting to
the old one.
---
 config.go | 16 +++++++++++++---
 main.go   |  1 +
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/config.go b/config.go
index 1f9c786..21b3828 100644
--- a/config.go
+++ b/config.go
@@ -114,6 +114,11 @@ func createClient(service string, cmd *cobra.Command) *Client {
}

func createClientWithInstance(service string, cmd *cobra.Command, instanceName string) *Client {
	timeout, err := cmd.Flags().GetDuration("timeout")
	if err != nil {
		log.Fatal(err)
	}

	customConfigFile := true
	configFile, err := cmd.Flags().GetString("config")
	if err != nil {
@@ -184,10 +189,10 @@ func createClientWithInstance(service string, cmd *cobra.Command, instanceName s
	if baseURL == "" {
		log.Fatalf("failed to get origin for service %q in instance %q", service, inst.Name)
	}
	return createClientWithToken(baseURL, token)
	return createClientWithToken(baseURL, token, timeout)
}

func createClientWithToken(baseURL, token string) *Client {
func createClientWithToken(baseURL, token string, timeout time.Duration) *Client {
	gqlEndpoint := baseURL + "/query"
	tokenSrc := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
	httpClient := oauth2.NewClient(context.Background(), tokenSrc)
@@ -233,6 +238,11 @@ func newInitCommand() *cobra.Command {
	cmd.Run = func(cmd *cobra.Command, args []string) {
		ctx := cmd.Context()

		timeout, err := cmd.Flags().GetDuration("timeout")
		if err != nil {
			log.Fatal(err)
		}

		filename, err := cmd.Flags().GetString("config")
		if err != nil {
			log.Fatal(err)
@@ -263,7 +273,7 @@ func newInitCommand() *cobra.Command {

		config := fmt.Sprintf("instance %q {\n	access-token %q\n}\n", instance, token)

		c := createClientWithToken(baseURL, token)
		c := createClientWithToken(baseURL, token, timeout)
		user, err := metasrht.FetchMe(c.Client, ctx)
		if err != nil {
			log.Fatalf("failed to check OAuth2 token: %v", err)
diff --git a/main.go b/main.go
index cb548fa..398bb93 100644
--- a/main.go
+++ b/main.go
@@ -36,6 +36,7 @@ func main() {
	cmd.PersistentFlags().String("instance", "", "sr.ht instance to use")
	cmd.RegisterFlagCompletionFunc("instance", cobra.NoFileCompletions)
	cmd.PersistentFlags().String("config", "", "config file to use")
	cmd.PersistentFlags().Duration("timeout", 30*time.Second, "timeout to use")

	cmd.AddCommand(newBuildsCommand())
	cmd.AddCommand(newExportCommand())
-- 
2.36.1
Details
Message ID
<20220516150449.jsyfrjkantl2fqvq@rita>
In-Reply-To
<20220516145804.29991-1-blallo@autistici.org> (view parent)
DKIM signature
pass
Download raw message
Please, ignore this patch. I forgot to actually use the passed timeout
value. The correct patch is underway.

--
blallo
Reply to thread Export thread (mbox)