Skip to content

Commit

Permalink
fix: License text can give 404 (#166)
Browse files Browse the repository at this point in the history
Closes #165
Signed-off-by: AlexNg <contact@ngjx.org>
  • Loading branch information
caffeine-addictt authored Oct 16, 2024
2 parents 3989133 + 65d8692 commit 4cd67a6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cmd/commands/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ var NewCmd = &cobra.Command{
ignoreRules = template.ResolveIncludes(ignoreRules, types.NewSet(".git/", "LICENSE"))
ignoredPaths := template.ResolveIncludes(types.NewSet(paths...), ignoreRules)

log.Debugf("resolved files to write: %v", ignoredPaths)
log.Debugf("resolved files to write: %v\n", ignoredPaths)

// Handle writing files
cmd.Println("writing files...")
log.Infoln("writing files...")
finalTmpl["Name"] = name
finalTmpl["License"] = license.Name
finalTmpl["Spdx"] = license.Spdx
Expand Down
13 changes: 8 additions & 5 deletions internal/license/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func GetLicenseFetchUrl() string {
} else {
url = fmt.Sprintf(BASE_URL, "v"+version.Version)
}
url += LICENSE_LIST
return url
}

Expand All @@ -38,8 +37,8 @@ func GetLicenses() (*[]License, error) {
return Licenses, nil
}

url := GetLicenseFetchUrl()
log.Infof("Fetching licenses from %s...\n", url)
url := GetLicenseFetchUrl() + LICENSE_LIST
log.Infof("fetching licenses from %s...\n", url)
req, err := http.NewRequest(http.MethodGet, url, http.NoBody)
if err != nil {
return nil, err
Expand All @@ -53,7 +52,11 @@ func GetLicenses() (*[]License, error) {
}
defer res.Body.Close()

log.Debugln("Reading http stream")
if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status code: %d", res.StatusCode)
}

log.Debugln("reading http stream")
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
Expand All @@ -63,7 +66,7 @@ func GetLicenses() (*[]License, error) {
Licenses []License `json:"licenses"`
}

log.Debugln("Unmarshalling license json")
log.Debugln("unmarshalling license json")
if err := json.Unmarshal(body, &l); err != nil {
return nil, err
}
Expand Down
12 changes: 11 additions & 1 deletion internal/license/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

"github.com/caffeine-addictt/waku/internal/log"
"github.com/goccy/go-json"
)

Expand All @@ -28,7 +29,10 @@ type License struct {
}

func (license *License) GetLicenseText() (string, error) {
req, err := http.NewRequest(http.MethodGet, GetLicenseFetchUrl()+license.Filename, http.NoBody)
url := GetLicenseFetchUrl() + license.Filename
log.Infof("fetching license text from %s...\n", url)

req, err := http.NewRequest(http.MethodGet, url, http.NoBody)
if err != nil {
return "", err
}
Expand All @@ -41,12 +45,18 @@ func (license *License) GetLicenseText() (string, error) {
}
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
return "", fmt.Errorf("unexpected status code: %d", res.StatusCode)
}

log.Debugln("reading http stream")
body, err := io.ReadAll(res.Body)
if err != nil {
return "", err
}

txt := string(body)
log.Debugln("replacing [year] with current year")
for i := range license.Wants {
if license.Wants[i] == "year" {
txt = strings.ReplaceAll(txt, "[year]", fmt.Sprintf("%d", time.Now().UTC().Year()))
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package version

// The current app version
const Version = "0.7.1"
const Version = "0.7.2"
4 changes: 2 additions & 2 deletions www/docs/configuration/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ for better editor support.
https://waku.ngjx.org/static/schema.json
```

Or you can pin a specific version like `v0.7.1`:
Or you can pin a specific version like `v0.7.2`:

```text
https://raw.githubusercontent.com/caffeine-addictt/waku/v0.7.1/www/docs/static/schema.json
https://raw.githubusercontent.com/caffeine-addictt/waku/v0.7.2/www/docs/static/schema.json
```

Simply add the `$schema` property to your `configuration` file:
Expand Down
10 changes: 5 additions & 5 deletions www/docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ All artifacts are checksummed, and the checksum file is signed with [cosign][].
and `checksums.txt.sig` files from the [releases][] page.

```sh
curl -O 'https://github.com/caffeine-addictt/waku/releases/download/v0.7.1/checksums.txt'
curl -O 'https://github.com/caffeine-addictt/waku/releases/download/v0.7.2/checksums.txt'
```

1. Verify checksums signature:

```bash
cosign verify-blob \
--certificate-identity 'https://github.com/caffeine-addictt/waku/.github/workflows/release.yml@refs/tags/v0.7.1' \
--certificate-identity 'https://github.com/caffeine-addictt/waku/.github/workflows/release.yml@refs/tags/v0.7.2' \
--certificate-oidc-issuer 'https://token.actions.githubusercontent.com' \
--cert 'https://github.com/caffeine-addictt/waku/releases/download/v0.7.1/checksums.txt.pem' \
--signature 'https://github.com/caffeine-addictt/waku/releases/download/v0.7.1/checksums.txt.sig' \
--cert 'https://github.com/caffeine-addictt/waku/releases/download/v0.7.2/checksums.txt.pem' \
--signature 'https://github.com/caffeine-addictt/waku/releases/download/v0.7.2/checksums.txt.sig' \
./checksums.txt
```

Expand All @@ -130,7 +130,7 @@ Verify the signature:

```sh
cosign verify \
--certificate-identity 'https://github.com/caffeine-addictt/waku/.github/workflows/release.yml@refs/tags/v0.7.1' \
--certificate-identity 'https://github.com/caffeine-addictt/waku/.github/workflows/release.yml@refs/tags/v0.7.2' \
--certificate-oidc-issuer 'https://token.actions.githubusercontent.com' \
caffeinec/waku
```
Expand Down

0 comments on commit 4cd67a6

Please sign in to comment.