Skip to content

Commit

Permalink
Download license file and copy downloads to tmp files
Browse files Browse the repository at this point in the history
  • Loading branch information
Zanda256 committed Feb 8, 2025
1 parent e6e43eb commit 42a1597
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 9 deletions.
22 changes: 22 additions & 0 deletions backend/internal/server/redoc.standalone.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015-present, Rebilly, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

49 changes: 40 additions & 9 deletions backend/internal/tools/pull-redoc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,58 @@ func main() {
flag.Parse()

// Pull Redoc script from Redocly CDN

redocCDNURL := fmt.Sprintf("https://cdn.redoc.ly/redoc/%s/bundles/redoc.standalone.js", version)

redocFileName := "redoc.standalone.js"
redocFile, err := os.Create(fmt.Sprintf("server/%s", redocFileName))
redocFile, err := os.Create("server/redoc.tmp")
if err != nil {
log.Print(err)
os.Exit(1)
log.Fatalf("err creating ReDoc script tmp file: %v", err)
}
defer redocFile.Close()

resp, err := http.Get(redocCDNURL)
if err != nil {
log.Fatalf("err downloading ReDoc script file: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode > 299 {
err = fmt.Errorf("err downloading ReDoc script file: %+v\n", resp)
log.Print(err)
os.Exit(1)
log.Fatal(err)
}
defer resp.Body.Close()

if _, err = io.Copy(redocFile, resp.Body); err != nil {
log.Print(err)
os.Exit(1)
log.Fatal(err)
}

err = os.Rename("server/redoc.tmp", fmt.Sprintf("server/%s", redocFileName))
if err != nil {
log.Fatalf("Error renaming ReDoc script file: %v", err)
}

// Pull ReDoc LICENSE file
licenseFileURL := "https://raw.githubusercontent.com/Redocly/redoc/refs/heads/main/LICENSE"

licenseFile, err := os.Create("server/license.tmp")
if err != nil {
log.Fatalf("err creating ReDoc license tmp file: %v", err)
}
resp1, err := http.Get(licenseFileURL)
if err != nil {
log.Fatalf("err downloading ReDoc license file: %v", err)
}

defer resp1.Body.Close()
if resp1.StatusCode < 200 || resp1.StatusCode > 299 {
err = fmt.Errorf("err downloading ReDoc license file: %+v\n", resp1)
log.Fatal(err)
}

if _, err = io.Copy(licenseFile, resp1.Body); err != nil {
log.Fatal(err)
}

err = os.Rename("server/license.tmp", "server/redoc.standalone.js.LICENSE.txt")
if err != nil {
log.Fatalf("Error renaming ReDoc license file: %v", err)
}
}

0 comments on commit 42a1597

Please sign in to comment.