Skip to content

Commit 42a1597

Browse files
committed
Download license file and copy downloads to tmp files
1 parent e6e43eb commit 42a1597

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015-present, Rebilly, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

backend/internal/tools/pull-redoc/main.go

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,58 @@ func main() {
1515
flag.Parse()
1616

1717
// Pull Redoc script from Redocly CDN
18-
1918
redocCDNURL := fmt.Sprintf("https://cdn.redoc.ly/redoc/%s/bundles/redoc.standalone.js", version)
2019

2120
redocFileName := "redoc.standalone.js"
22-
redocFile, err := os.Create(fmt.Sprintf("server/%s", redocFileName))
21+
redocFile, err := os.Create("server/redoc.tmp")
2322
if err != nil {
24-
log.Print(err)
25-
os.Exit(1)
23+
log.Fatalf("err creating ReDoc script tmp file: %v", err)
2624
}
2725
defer redocFile.Close()
2826

2927
resp, err := http.Get(redocCDNURL)
28+
if err != nil {
29+
log.Fatalf("err downloading ReDoc script file: %v", err)
30+
}
31+
defer resp.Body.Close()
3032
if resp.StatusCode < 200 || resp.StatusCode > 299 {
3133
err = fmt.Errorf("err downloading ReDoc script file: %+v\n", resp)
32-
log.Print(err)
33-
os.Exit(1)
34+
log.Fatal(err)
3435
}
35-
defer resp.Body.Close()
3636

3737
if _, err = io.Copy(redocFile, resp.Body); err != nil {
38-
log.Print(err)
39-
os.Exit(1)
38+
log.Fatal(err)
39+
}
40+
41+
err = os.Rename("server/redoc.tmp", fmt.Sprintf("server/%s", redocFileName))
42+
if err != nil {
43+
log.Fatalf("Error renaming ReDoc script file: %v", err)
44+
}
45+
46+
// Pull ReDoc LICENSE file
47+
licenseFileURL := "https://raw.githubusercontent.com/Redocly/redoc/refs/heads/main/LICENSE"
48+
49+
licenseFile, err := os.Create("server/license.tmp")
50+
if err != nil {
51+
log.Fatalf("err creating ReDoc license tmp file: %v", err)
52+
}
53+
resp1, err := http.Get(licenseFileURL)
54+
if err != nil {
55+
log.Fatalf("err downloading ReDoc license file: %v", err)
56+
}
57+
58+
defer resp1.Body.Close()
59+
if resp1.StatusCode < 200 || resp1.StatusCode > 299 {
60+
err = fmt.Errorf("err downloading ReDoc license file: %+v\n", resp1)
61+
log.Fatal(err)
62+
}
63+
64+
if _, err = io.Copy(licenseFile, resp1.Body); err != nil {
65+
log.Fatal(err)
66+
}
67+
68+
err = os.Rename("server/license.tmp", "server/redoc.standalone.js.LICENSE.txt")
69+
if err != nil {
70+
log.Fatalf("Error renaming ReDoc license file: %v", err)
4071
}
4172
}

0 commit comments

Comments
 (0)