Skip to content

Commit b37c80c

Browse files
julienrbrtmergify[bot]
authored andcommitted
feat(cosmosgen): fetch fallback buf token (#4805)
* feat(cosmosgen): fetch fallback buf token * package refactor * fix `CaptureException called with nil error` * cl * updates * updates * feedback (cherry picked from commit 3919d6b) # Conflicts: # ignite/cmd/bubblemodel/chain_serve.go # ignite/cmd/cmd.go # ignite/internal/analytics/analytics.go # ignite/internal/announcements/announcement_test.go # ignite/pkg/cosmosgen/generate_typescript.go # ignite/pkg/gocmd/gocmd_test.go # ignite/templates/app/files/{{protoDir}}/buf.gen.gogo.yaml # ignite/templates/app/files/{{protoDir}}/buf.gen.swagger.yaml
1 parent 18c30cf commit b37c80c

File tree

18 files changed

+519
-35
lines changed

18 files changed

+519
-35
lines changed

changelog.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,212 @@
22

33
## Unreleased
44

5+
### Changes
6+
7+
- [#4807](https://github.com/ignite/cli/pull/4807) Improve unconfigured path message when building a chain.
8+
- [#4805](https://github.com/ignite/cli/pull/4805) Fetch fallback buf token.
9+
10+
## [`v29.4.0`](https://github.com/ignite/cli/releases/tag/v29.4.0)
11+
12+
### Features
13+
14+
- [#4790](https://github.com/ignite/cli/pull/4790) Remove global vars and struct placeholders.
15+
- [#4797](https://github.com/ignite/cli/pull/4797) Add `xast` function to append new switch clause.
16+
- [#4804](https://github.com/ignite/cli/pull/4804) Add `BroadcastAsync` to `cosmosclient` package.
17+
18+
### Changes
19+
20+
- [#4794](https://github.com/ignite/cli/pull/4794) Update `cosmossdk.io/log` version to `v1.6.1` and remove `bytedance/sonic` version override from template.
21+
22+
### Fixes
23+
24+
- [#4803](https://github.com/ignite/cli/pull/4803) Fix simulations for custom address prefix.
25+
26+
## [`v29.3.1`](https://github.com/ignite/cli/releases/tag/v29.3.1)
27+
28+
### Fixes
29+
30+
- [#4793](https://github.com/ignite/cli/pull/4793) Use latest `bytedance/sonic` version to support Go 1.25.
31+
32+
## [`v29.3.0`](https://github.com/ignite/cli/releases/tag/v29.3.0)
33+
34+
### Features
35+
36+
- [#4786](https://github.com/ignite/cli/pull/4786) Add all types to the documentation and disclaimer for multiple coin types.
37+
38+
### Changes
39+
40+
- [#4780](https://github.com/ignite/cli/pull/4780) Fallback to local generation when possible in `generate ts-client` command.
41+
- [#4779](https://github.com/ignite/cli/pull/4779) Do not re-gen openapi spec each time the `ts-client` or the `composables` are generated.
42+
- [#4784](https://github.com/ignite/cli/pull/4784) Remove unused message initialization.
43+
44+
### Fixes
45+
46+
- [#4779](https://github.com/ignite/cli/pull/4779) Find proto dir in non conventional repo structure.
47+
48+
## [`v29.2.0`](https://github.com/ignite/cli/releases/tag/v29.2.0)
49+
50+
### Features
51+
52+
- [#4676](https://github.com/ignite/cli/issues/4676) Add Decimal Coin Type.
53+
- [#4765](https://github.com/ignite/cli/pull/4765) Create `scaffold type-list` command.
54+
- [#4770](https://github.com/ignite/cli/pull/4770) Add `--output-file` flag to `chain serve` command to improve running `chain serve` in the background.
55+
56+
### Changes
57+
58+
- [#4759](https://github.com/ignite/cli/pull/4759) Remove undocumented RPC address override in services chainer.
59+
- [#4760](https://github.com/ignite/cli/pull/4760) Bump Cosmos SDK to `v0.53.3`.
60+
61+
### Fixes
62+
63+
- [#4757](https://github.com/ignite/cli/pull/4757) Always delete temp folder from open api generation.
64+
65+
## [`v29.1.0`](https://github.com/ignite/cli/releases/tag/v29.1.0)
66+
67+
### Features
68+
69+
- [#4728](https://github.com/ignite/cli/pull/4728) Ask before overwriting a `xgenny` file.
70+
- [#4731](https://github.com/ignite/cli/pull/4731) Complete IBC v2 wiring.
71+
- [#4732](https://github.com/ignite/cli/pull/4732) Add `ignite chain modules list` command to list all modules in the chain.
72+
73+
### Changes
74+
75+
- [#4717](https://github.com/ignite/cli/pull/4717) Bump Cosmos SDK to `v0.53.2`.
76+
- [#4718](https://github.com/ignite/cli/pull/4718) Bump default Ignite Apps.
77+
- [#4741](https://github.com/ignite/cli/pull/4741) Let `generate openapi` generate external modules OpenAPI spec.
78+
- [#4747](https://github.com/ignite/cli/pull/4747) Improve Ignite UI.
79+
- [#4751](https://github.com/ignite/cli/pull/4751) Improve cache speed and limit duplicate I/O.
80+
81+
### Fixes
82+
83+
- [#4691](https://github.com/ignite/cli/pull/4691), [#4706](https://github.com/ignite/cli/pull/4706), [#4725](https://github.com/ignite/cli/pull/4725), [#4737](https://github.com/ignite/cli/pull/4737) Fix ts-client query template and solely Go template for `ts-client` generation.
84+
- [#4742](https://github.com/ignite/cli/pull/4742) Updates Vue composables template for new ts-client and tanstack/vue-query v5
85+
- [#4744](https://github.com/ignite/cli/pull/4744) Remove `react` frontend generation via `s react` command. Use the [Ignite CCA App](https://github.com/ignite/apps) instead.
86+
87+
## [`v29.0.0`](https://github.com/ignite/cli/releases/tag/v29.0.0)
88+
89+
### Features
90+
91+
- [#4614](https://github.com/ignite/cli/pull/4614) Improve integration tests and add query tests.
92+
- [#4683](https://github.com/ignite/cli/pull/4683) Allow to change default denom via flag.
93+
- [#4687](https://github.com/ignite/cli/pull/4687) Add address type with `scalar` annotations, and add `scalar` type to signer field.
94+
95+
### Changes
96+
97+
- [#4689](https://github.com/ignite/cli/pull/4689) Revert `HasGenesis` implementation from retracted `core` v1 to SDK `HasGenesis` interface.
98+
- [#4701](https://github.com/ignite/cli/pull/4701) Improve `ignite doctor` by removing manual migration step. Additionally, remove protoc to buf migrations logic.
99+
- [#4703](https://github.com/ignite/cli/pull/4703) Remove testutil.Register function.
100+
- [#4702](https://github.com/ignite/cli/pull/4702) Improve app detection by checking for inheritance instead of interface implementation.
101+
- [#4707](https://github.com/ignite/cli/pull/4707) Show `buf` version in `ignite version` only when in a go module.
102+
- [#4709](https://github.com/ignite/cli/pull/4709) Remove legacy msgServer support
103+
- [#4710](https://github.com/ignite/cli/pull/4710) Remove the `nullify` pkg from the chain `testutil`
104+
105+
### Fixes
106+
107+
- [#4686](https://github.com/ignite/cli/pull/4686) Filter discovered protos to only messages.
108+
- [#4694](https://github.com/ignite/cli/issues/4694) Install an app using the `.` as a current path show a wrong app name.
109+
110+
## [`v29.0.0-rc.1`](https://github.com/ignite/cli/releases/tag/v29.0.0-rc.1)
111+
112+
### Features
113+
114+
- [#4509](https://github.com/ignite/cli/pull/4509) Upgrade to Go 1.24. Running `ignite doctor` migrates the scaffolded `tools.go` to the tool directive in the go.mod
115+
- [#4588](https://github.com/ignite/cli/pull/4588) Run `buf format after scaffold proto files.
116+
- [#4603](https://github.com/ignite/cli/issues/4603) Add `GetIgniteInfo` gRPC API for apps.
117+
- [#4657](https://github.com/ignite/cli/pull/4657) Upgrade to Cosmos SDK [v0.53.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.53.0).
118+
- Add x/epochs module to default template (except for minimal template).
119+
- Bump minimum compatible Cosmos SDK version to `v0.50.0`.
120+
121+
### Changes
122+
123+
- [#4596](https://github.com/ignite/cli/pull/4596) Add default `openapi.yml` when skipping proto gen.
124+
- [#4601](https://github.com/ignite/cli/pull/4601) Add `appregistry` as default plugin
125+
- [#4613](https://github.com/ignite/cli/pull/4613) Improve and simplify prompting logic by bubbletea.
126+
- [#4624](https://github.com/ignite/cli/pull/4624) Fix autocli templates for variadics.
127+
- [#4644](https://github.com/ignite/cli/pull/4644) Improve UI and UX for `testnet multi-node` command.
128+
- [#4645](https://github.com/ignite/cli/pull/4645) Refactor the xast.ModifyFunction to improve the readability.
129+
- [#3393](https://github.com/ignite/cli/issues/3393) Remove xgenny embed walker
130+
- [#4664](https://github.com/ignite/cli/pull/4664) Add verbose flags on `scaffold` and `generate` commands.
131+
- The flag displays the steps Ignite is taking to generate the code.
132+
- The verbosity only applies to the command. For full verbosity use the `IGNT_DEBUG` environment variable instead.
133+
134+
### Fixes
135+
136+
- [#4347](https://github.com/ignite/cli/pull/4347) Fix `ts-client` generation
137+
- [#4577](https://github.com/ignite/cli/pull/4577) Add proto version to query path.
138+
- [#4579](https://github.com/ignite/cli/pull/4579) Fix empty params response.
139+
- [#4585](https://github.com/ignite/cli/pull/4585) Fix faucet cmd issue.
140+
- [#4587](https://github.com/ignite/cli/pull/4587) Add missing light clients routes to IBC client keeper.
141+
- [#4595](https://github.com/ignite/cli/pull/4595) Fix wrong InterfaceRegistry for IBC modules.
142+
- [#4609](https://github.com/ignite/cli/pull/4609) Add work dir for relayer integration tests.
143+
- [#4658](https://github.com/ignite/cli/pull/4658) Fix indentation for params scaffolded into a struct.
144+
- [#4582](https://github.com/ignite/cli/issues/4582) Fix xast misplacing comments.
145+
- [#4660](https://github.com/ignite/cli/pull/4660) Fix xast test case indentation.
146+
- [#4667](https://github.com/ignite/cli/pull/4667) Harden `IsSlice`
147+
148+
## [`v29.0.0-beta.1`](https://github.com/ignite/cli/releases/tag/v29.0.0-beta.1)
149+
150+
### Features
151+
152+
- [#3707](https://github.com/ignite/cli/pull/3707) and [#4094](https://github.com/ignite/cli/pull/4094) Add collections support.
153+
- [#3977](https://github.com/ignite/cli/pull/3977) Add `chain lint` command to lint the chain's codebase using `golangci-lint`
154+
- [#3770](https://github.com/ignite/cli/pull/3770) Add `scaffold configs` and `scaffold params` commands
155+
- [#4001](https://github.com/ignite/cli/pull/4001) Improve `xgenny` dry run
156+
- [#3967](https://github.com/ignite/cli/issues/3967) Add HD wallet parameters `address index` and `account number` to the chain account config
157+
- [#4004](https://github.com/ignite/cli/pull/4004) Remove all import placeholders using the `xast` pkg
158+
- [#4071](https://github.com/ignite/cli/pull/4071) Support custom proto path
159+
- [#3718](https://github.com/ignite/cli/pull/3718) Add `gen-mig-diffs` tool app to compare scaffold output of two versions of ignite
160+
- [#4100](https://github.com/ignite/cli/pull/4100) Set the `proto-dir` flag only for the `scaffold chain` command and use the proto path from the config
161+
- [#4111](https://github.com/ignite/cli/pull/4111) Remove vuex generation
162+
- [#4113](https://github.com/ignite/cli/pull/4113) Generate chain config documentation automatically
163+
- [#4131](https://github.com/ignite/cli/pull/4131) Support `bytes` as data type in the `scaffold` commands
164+
- [#4300](https://github.com/ignite/cli/pull/4300) Only panics the module in the most top function level
165+
- [#4327](https://github.com/ignite/cli/pull/4327) Use the TxConfig from simState instead create a new one
166+
- [#4326](https://github.com/ignite/cli/pull/4326) Add `buf.build` version to `ignite version` command
167+
- [#4436](https://github.com/ignite/cli/pull/4436) Return tx hash to the faucet API
168+
- [#4437](https://github.com/ignite/cli/pull/4437) Remove module placeholders
169+
- [#4289](https://github.com/ignite/cli/pull/4289), [#4423](https://github.com/ignite/cli/pull/4423), [#4432](https://github.com/ignite/cli/pull/4432), [#4507](https://github.com/ignite/cli/pull/4507), [#4524](https://github.com/ignite/cli/pull/4524) Cosmos SDK v0.52 support and downgrade back to 0.50, while keeping latest improvements.
170+
- [#4480](https://github.com/ignite/cli/pull/4480) Add field max length
171+
- [#4477](https://github.com/ignite/cli/pull/4477), [#4559](https://github.com/ignite/cli/pull/4559) IBC v10 support
172+
- [#4166](https://github.com/ignite/cli/issues/4166) Migrate buf config files to v2
173+
- [#4494](https://github.com/ignite/cli/pull/4494) Automatic migrate the buf configs to v2
174+
175+
### Changes
176+
177+
- [#4094](https://github.com/ignite/cli/pull/4094) Scaffolding a multi-index map using `ignite s map foo bar baz --index foobar,foobaz` is no longer supported. Use one index instead of use `collections.IndexedMap`.
178+
- [#4058](https://github.com/ignite/cli/pull/4058) Simplify scaffolded modules by including `ValidateBasic()` logic in message handler.
179+
- [#4058](https://github.com/ignite/cli/pull/4058) Use `address.Codec` instead of `AccAddressFromBech32`.
180+
- [#3993](https://github.com/ignite/cli/pull/3993) Oracle scaffolding was deprecated and has been removed
181+
- [#3962](https://github.com/ignite/cli/pull/3962) Rename all RPC endpoints and autocli commands generated for `map`/`list`/`single` types
182+
- [#3976](https://github.com/ignite/cli/pull/3976) Remove error checks for Cobra command value get calls
183+
- [#4002](https://github.com/ignite/cli/pull/4002) Bump buf build
184+
- [#4008](https://github.com/ignite/cli/pull/4008) Rename `pkg/yaml` to `pkg/xyaml`
185+
- [#4075](https://github.com/ignite/cli/pull/4075) Use `gopkg.in/yaml.v3` instead `gopkg.in/yaml.v2`
186+
- [#4118](https://github.com/ignite/cli/pull/4118) Version scaffolded protos as `v1` to follow SDK structure.
187+
- [#4167](https://github.com/ignite/cli/pull/4167) Scaffold `int64` instead of `int32` when a field type is `int`
188+
- [#4159](https://github.com/ignite/cli/pull/4159) Enable gci linter
189+
- [#4160](https://github.com/ignite/cli/pull/4160) Enable copyloopvar linter
190+
- [#4162](https://github.com/ignite/cli/pull/4162) Enable errcheck linter
191+
- [#4189](https://github.com/ignite/cli/pull/4189) Deprecate `ignite node` for `ignite connect` app
192+
- [#4290](https://github.com/ignite/cli/pull/4290) Remove ignite ics logic from ignite cli (this functionality will be in the `consumer` app)
193+
- [#4295](https://github.com/ignite/cli/pull/4295) Stop scaffolding `pulsar` files
194+
- [#4317](https://github.com/ignite/cli/pull/4317) Remove xchisel dependency
195+
- [#4361](https://github.com/ignite/cli/pull/4361) Remove unused `KeyPrefix` method
196+
- [#4384](https://github.com/ignite/cli/pull/4384) Compare genesis params into chain genesis tests
197+
- [#4463](https://github.com/ignite/cli/pull/4463) Run `chain simulation` with any simulation test case
198+
- [#4533](https://github.com/ignite/cli/pull/4533) Promote GitHub codespace instead of Gitpod
199+
- [#4549](https://github.com/ignite/cli/pull/4549) Remove unused placeholder vars
200+
- [#4557](https://github.com/ignite/cli/pull/4557) Remove github.com/gookit/color
201+
202+
### Fixes
203+
204+
- [#4000](https://github.com/ignite/cli/pull/4000) Run all dry runners before the wet run in the `xgenny` pkg
205+
- [#4091](https://github.com/ignite/cli/pull/4091) Fix race conditions in the plugin logic
206+
- [#4128](https://github.com/ignite/cli/pull/4128) Check for duplicate proto fields in config
207+
- [#4402](https://github.com/ignite/cli/pull/4402) Fix gentx parser into the cosmosutil package
208+
- [#4552](https://github.com/ignite/cli/pull/4552) Avoid direct access to proto field `perms.Account` and `perms.Permissions`
209+
- [#4555](https://github.com/ignite/cli/pull/4555) Fix buf lint issues into the chain code
210+
5211
## [`v28.11.0`](https://github.com/ignite/cli/releases/tag/v28.11.0)
6212

7213
### Changes

ignite/cmd/bubblemodel/chain_serve.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ import (
77

88
tea "github.com/charmbracelet/bubbletea"
99

10+
<<<<<<< HEAD
1011
"github.com/ignite/cli/v28/ignite/pkg/announcements"
1112
"github.com/ignite/cli/v28/ignite/pkg/cliui/colors"
1213
"github.com/ignite/cli/v28/ignite/pkg/cliui/icons"
1314
cliuimodel "github.com/ignite/cli/v28/ignite/pkg/cliui/model"
1415
"github.com/ignite/cli/v28/ignite/pkg/events"
16+
=======
17+
"github.com/ignite/cli/v29/ignite/internal/announcements"
18+
"github.com/ignite/cli/v29/ignite/pkg/cliui/colors"
19+
"github.com/ignite/cli/v29/ignite/pkg/cliui/icons"
20+
cliuimodel "github.com/ignite/cli/v29/ignite/pkg/cliui/model"
21+
"github.com/ignite/cli/v29/ignite/pkg/events"
22+
>>>>>>> 3919d6bb (feat(cosmosgen): fetch fallback buf token (#4805))
1523
)
1624

1725
const (

ignite/cmd/cmd.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/spf13/cobra"
1313
flag "github.com/spf13/pflag"
1414

15+
<<<<<<< HEAD
1516
"github.com/ignite/cli/v28/ignite/config"
1617
"github.com/ignite/cli/v28/ignite/pkg/announcements"
1718
"github.com/ignite/cli/v28/ignite/pkg/cache"
@@ -22,6 +23,26 @@ import (
2223
"github.com/ignite/cli/v28/ignite/pkg/gitpod"
2324
"github.com/ignite/cli/v28/ignite/pkg/goenv"
2425
"github.com/ignite/cli/v28/ignite/version"
26+
=======
27+
"github.com/ignite/cli/v29/ignite/config"
28+
chainconfig "github.com/ignite/cli/v29/ignite/config/chain"
29+
"github.com/ignite/cli/v29/ignite/internal/announcements"
30+
"github.com/ignite/cli/v29/ignite/pkg/cache"
31+
"github.com/ignite/cli/v29/ignite/pkg/cliui"
32+
uilog "github.com/ignite/cli/v29/ignite/pkg/cliui/log"
33+
"github.com/ignite/cli/v29/ignite/pkg/dircache"
34+
"github.com/ignite/cli/v29/ignite/pkg/errors"
35+
"github.com/ignite/cli/v29/ignite/pkg/goenv"
36+
"github.com/ignite/cli/v29/ignite/pkg/gomodulepath"
37+
"github.com/ignite/cli/v29/ignite/version"
38+
)
39+
40+
type key int
41+
42+
const (
43+
keyChainConfig key = iota
44+
keyChainConfigPath key = iota
45+
>>>>>>> 3919d6bb (feat(cosmosgen): fetch fallback buf token (#4805))
2546
)
2647

2748
const (

ignite/internal/analytics/analytics.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@ import (
1212
"github.com/manifoldco/promptui"
1313
"github.com/spf13/cobra"
1414

15+
<<<<<<< HEAD
1516
"github.com/ignite/cli/v28/ignite/config"
1617
"github.com/ignite/cli/v28/ignite/pkg/gitpod"
1718
"github.com/ignite/cli/v28/ignite/pkg/matomo"
1819
"github.com/ignite/cli/v28/ignite/pkg/randstr"
1920
"github.com/ignite/cli/v28/ignite/pkg/sentry"
2021
"github.com/ignite/cli/v28/ignite/version"
22+
=======
23+
"github.com/ignite/cli/v29/ignite/config"
24+
"github.com/ignite/cli/v29/ignite/internal/sentry"
25+
"github.com/ignite/cli/v29/ignite/pkg/cliui"
26+
"github.com/ignite/cli/v29/ignite/pkg/errors"
27+
"github.com/ignite/cli/v29/ignite/pkg/matomo"
28+
"github.com/ignite/cli/v29/ignite/pkg/randstr"
29+
"github.com/ignite/cli/v29/ignite/version"
30+
>>>>>>> 3919d6bb (feat(cosmosgen): fetch fallback buf token (#4805))
2131
)
2232

2333
const (

ignite/pkg/announcements/announcement.go renamed to ignite/internal/announcements/announcement.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@ import (
1111
)
1212

1313
var (
14-
SurveyLink = "https://bit.ly/3WZS2uS"
15-
APIURL = "http://announcements.ignite.com/v1/announcements"
14+
SurveyLink = "https://bit.ly/3WZS2uS"
15+
AnnouncementURL = "https://api.ignite.com/v1/announcements"
1616
)
1717

18-
type api struct {
19-
Announcements []announcement `json:"announcements"`
20-
}
21-
2218
type announcement struct {
2319
ID string `json:"id"`
2420
Text string `json:"text"`
@@ -28,13 +24,16 @@ type announcement struct {
2824

2925
// Fetch fetches the latest announcements from the API.
3026
func Fetch() string {
31-
resp, err := http.Get(APIURL) //nolint:gosec
27+
resp, err := http.Get(AnnouncementURL) //nolint:gosec
3228
if err != nil || resp.StatusCode != 200 {
3329
return fallbackData()
3430
}
3531
defer resp.Body.Close()
3632

37-
var data api
33+
type response struct {
34+
Announcements []announcement `json:"announcements"`
35+
}
36+
var data response
3837
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
3938
return fallbackData()
4039
}

ignite/pkg/announcements/announcement_test.go renamed to ignite/internal/announcements/announcement_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import (
66
"net/http/httptest"
77
"testing"
88

9+
<<<<<<< HEAD:ignite/pkg/announcements/announcement_test.go
910
"github.com/ignite/cli/v28/ignite/pkg/announcements"
11+
=======
12+
"github.com/ignite/cli/v29/ignite/internal/announcements"
13+
>>>>>>> 3919d6bb (feat(cosmosgen): fetch fallback buf token (#4805)):ignite/internal/announcements/announcement_test.go
1014
)
1115

1216
func TestFetchAnnouncements(t *testing.T) {
@@ -52,9 +56,9 @@ func TestFetchAnnouncements(t *testing.T) {
5256
}))
5357
defer server.Close()
5458

55-
originalAPI := announcements.APIURL
56-
announcements.APIURL = server.URL
57-
defer func() { announcements.APIURL = originalAPI }()
59+
originalAPI := announcements.AnnouncementURL
60+
announcements.AnnouncementURL = server.URL
61+
defer func() { announcements.AnnouncementURL = originalAPI }()
5862

5963
result := announcements.Fetch()
6064
if result != tt.expected {

ignite/internal/buf/buf.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package buf
2+
3+
import (
4+
"encoding/json"
5+
"net/http"
6+
"time"
7+
8+
"github.com/ignite/cli/v29/ignite/pkg/errors"
9+
)
10+
11+
var BufTokenURL = "https://buf.ignite.com" //nolint:gosec // URL is hardcoded and not user-provided
12+
13+
// FetchToken fetches the buf token from the Ignite API.
14+
func FetchToken() (string, error) {
15+
client := &http.Client{
16+
Timeout: 5 * time.Second,
17+
}
18+
19+
resp, err := client.Get(BufTokenURL)
20+
if err != nil {
21+
return "", err
22+
}
23+
defer resp.Body.Close()
24+
25+
if resp.StatusCode != http.StatusOK {
26+
return "", errors.Errorf("HTTP request failed with status code: %d", resp.StatusCode)
27+
}
28+
29+
type tokenResponse struct {
30+
Token string `json:"token"`
31+
}
32+
var tokenResp tokenResponse
33+
34+
if err := json.NewDecoder(resp.Body).Decode(&tokenResp); err != nil {
35+
return "", err
36+
}
37+
38+
return tokenResp.Token, nil
39+
}

0 commit comments

Comments
 (0)