• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

astronomer / astro-cli / 404d654b-df7d-4e3a-87eb-25ed2c665b0b

20 Nov 2025 02:12AM UTC coverage: 33.062% (-5.6%) from 38.64%
404d654b-df7d-4e3a-87eb-25ed2c665b0b

Pull #1986

circleci

web-flow
Bump golang.org/x/crypto from 0.36.0 to 0.45.0

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.36.0 to 0.45.0.
- [Commits](https://github.com/golang/crypto/compare/v0.36.0...v0.45.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-version: 0.45.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #1986: Bump golang.org/x/crypto from 0.36.0 to 0.45.0

20778 of 62845 relevant lines covered (33.06%)

8.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pkg/httputil/http.go
1
package httputil
2

3
import (
4
        "bytes"
5
        httpContext "context"
6
        "encoding/json"
7
        "fmt"
8
        "io"
9
        "net/http"
10

11
        "github.com/astronomer/astro-cli/pkg/logger"
12

13
        "github.com/astronomer/astro-cli/pkg/fileutil"
14

15
        "github.com/pkg/errors"
16
        "golang.org/x/net/context/ctxhttp"
17
)
18

19
var ErrorBaseURL = errors.New("invalid baseurl")
20

21
const LastSuccessfulHTTPResponseCode = 299
22

23
// HTTPClient returns an HTTP Client struct that can execute HTTP requests
24
type HTTPClient struct {
25
        HTTPClient *http.Client
26
}
27

28
// HTTPResponse houses respnse object
29
type HTTPResponse struct {
30
        Raw  *http.Response
31
        Body string
32
}
33

34
// DoOptions are options passed to the HTTPClient.Do function
35
type DoOptions struct {
36
        Data    []byte
37
        Context httpContext.Context
38
        Headers map[string]string
39
        Method  string
40
        Path    string
41
}
42

43
// NewHTTPClient returns a new HTTP Client
44
func NewHTTPClient() *HTTPClient {
×
45
        return &HTTPClient{
×
46
                HTTPClient: &http.Client{},
×
47
        }
×
48
}
×
49

50
// Do executes the given HTTP request and returns the HTTP Response
51
func (c *HTTPClient) Do(doOptions *DoOptions) (*http.Response, error) {
×
52
        var body io.Reader
×
53
        if len(doOptions.Data) > 0 {
×
54
                body = bytes.NewBuffer(doOptions.Data)
×
55
        }
×
56

57
        ctx := httpContext.Background()
×
58
        ctx, cancel := httpContext.WithCancel(ctx)
×
59
        defer cancel()
×
60
        req, err := http.NewRequestWithContext(ctx, doOptions.Method, doOptions.Path, body)
×
61
        if err != nil {
×
62
                return nil, err
×
63
        }
×
64
        if len(doOptions.Data) > 0 {
×
65
                req.Header.Set("Content-Type", "application/json")
×
66
        }
×
67

68
        for k, v := range doOptions.Headers {
×
69
                req.Header.Set(k, v)
×
70
        }
×
71

72
        doCtx := doOptions.Context
×
73
        if doCtx == nil {
×
74
                doCtx = httpContext.Background()
×
75
        }
×
76

77
        resp, err := ctxhttp.Do(doCtx, c.HTTPClient, req)
×
78
        if err != nil {
×
79
                return nil, errors.Wrap(chooseError(doCtx, err), "HTTP DO Failed")
×
80
        }
×
81
        if resp.StatusCode < 200 || resp.StatusCode >= 400 {
×
82
                return nil, newError(resp)
×
83
        }
×
84
        return resp, nil
×
85
}
86

87
// if error in context, return that instead of generic http error
88
func chooseError(ctx httpContext.Context, err error) error {
×
89
        select {
×
90
        case <-ctx.Done():
×
91
                return ctx.Err()
×
92
        default:
×
93
                return err
×
94
        }
95
}
96

97
// Error is a custom HTTP error structure
98
type Error struct {
99
        Status  int
100
        Message string
101
}
102

103
func newError(resp *http.Response) *Error {
×
104
        defer resp.Body.Close()
×
105
        data, err := io.ReadAll(resp.Body)
×
106
        if err != nil {
×
107
                return &Error{Status: resp.StatusCode, Message: fmt.Sprintf("cannot read body, err: %v", err)}
×
108
        }
×
109
        return &Error{Status: resp.StatusCode, Message: string(data)}
×
110
}
111

112
// Error implemented to match Error interface
113
func (e *Error) Error() string {
×
114
        return fmt.Sprintf("API error (%d): %s", e.Status, e.Message)
×
115
}
×
116

117
func DownloadResponseToFile(sourceURL, path string) {
×
118
        file, err := fileutil.CreateFile(path)
×
119
        if err != nil {
×
120
                logger.Fatal(err)
×
121
        }
×
122

123
        client := http.Client{
×
124
                CheckRedirect: func(r *http.Request, via []*http.Request) error {
×
125
                        r.URL.Opaque = r.URL.Path
×
126
                        return nil
×
127
                },
×
128
        }
129
        resp, err := client.Get(sourceURL) //nolint
×
130
        if err != nil {
×
131
                logger.Fatal(err)
×
132
        }
×
133
        defer resp.Body.Close()
×
134

×
135
        err = fileutil.WriteToFile(path, resp.Body)
×
136
        if err != nil {
×
137
                logger.Fatal(err)
×
138
        }
×
139
        defer file.Close()
×
140
        logger.Infof("Downloaded %s from %s", path, sourceURL)
×
141
}
142

143
func RequestAndGetJSONBody(route string) map[string]interface{} {
×
144
        res, err := http.Get(route) //nolint
×
145
        if err != nil {
×
146
                logger.Fatal(err)
×
147
        }
×
148
        defer res.Body.Close()
×
149

×
150
        body, err := io.ReadAll(res.Body)
×
151
        if err != nil {
×
152
                logger.Fatal(err)
×
153
        }
×
154
        if res.StatusCode > LastSuccessfulHTTPResponseCode {
×
155
                logger.Fatalf("Response failed with status code: %d and\nbody: %s\n", res.StatusCode, body)
×
156
        }
×
157

158
        var bodyJSON map[string]interface{}
×
159
        err = json.Unmarshal(body, &bodyJSON)
×
160
        if err != nil {
×
161
                logger.Fatal(err)
×
162
        }
×
163
        logger.Debugf("%s - GET %s %s", res.Status, route, string(body))
×
164
        return bodyJSON
×
165
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc