Skip to content

Commit 285b269

Browse files
committed
Add ability to pass an auth token
1 parent db014a7 commit 285b269

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

heyfil.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ func newHeyFil(o ...Option) (*heyFil, error) {
3838
if err != nil {
3939
return nil, err
4040
}
41+
c := jsonrpc.NewClient(opts.api)
42+
if opts.apiToken != "" {
43+
c = jsonrpc.NewClientWithOpts(opts.api, &jsonrpc.RPCClientOpts{CustomHeaders: map[string]string{"Authorization": "Bearer " + opts.apiToken}})
44+
45+
}
4146
hf := &heyFil{
4247
options: opts,
43-
c: jsonrpc.NewClient(opts.api),
48+
c: c,
4449
targets: make(map[string]*Target),
4550
toCheck: make(chan *Target, 100),
4651
checked: make(chan *Target, 100),

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ func main() {
1313
httpIndexerEndpoint := flag.String("httpIndexerEndpoint", "https://cid.contact", "The HTTP IPNI endpoint to which announcements are made.")
1414
maxConcurrentChecks := flag.Int("maxConcurrentChecks", 10, "The maximum number of concurrent checks.")
1515
storePath := flag.String("storePath", "", "The directory to use for storing the discovered SP information.")
16+
token := flag.String("token", "", "A bearer token to pass for auth to the filecoin api endpoint.")
1617
flag.Parse()
1718

1819
hf, err := newHeyFil(
1920
WithHttpIndexerEndpoint(*httpIndexerEndpoint),
2021
WithMaxConcurrentChecks(*maxConcurrentChecks),
2122
WithStorePath(*storePath),
23+
WithFileCoinAPIToken(*token),
2224
)
2325
if err != nil {
2426
panic(err)

options.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type (
1414
Option func(*options) error
1515
options struct {
1616
api string
17+
apiToken string
1718
h host.Host
1819
topic string
1920
headProtocolPattern *regexp.Regexp
@@ -36,6 +37,7 @@ type (
3637
func newOptions(o ...Option) (*options, error) {
3738
opts := &options{
3839
api: `https://api.node.glif.io`,
40+
apiToken: ``,
3941
marketDealsS3Snapshot: `https://marketdeals.s3.amazonaws.com/StateMarketDeals.json.zst`,
4042
marketDealsFilTools: `https://filecoin.tools/api/deals/list`,
4143
httpIndexerEndpoint: `https://cid.contact`,
@@ -74,6 +76,13 @@ func WithFileCoinAPI(url string) Option {
7476
}
7577
}
7678

79+
func WithFileCoinAPIToken(token string) Option {
80+
return func(o *options) error {
81+
o.apiToken = token
82+
return nil
83+
}
84+
}
85+
7786
// WithHost specifies the libp2p host.
7887
// If unset, a new host with random identity is instantiated.
7988
func WithHost(h host.Host) Option {

0 commit comments

Comments
 (0)