Skip to content

Commit

Permalink
Add ability to pass an auth token (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
willscott authored Apr 24, 2024
2 parents db014a7 + 285b269 commit bbb7f4a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion heyfil.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ func newHeyFil(o ...Option) (*heyFil, error) {
if err != nil {
return nil, err
}
c := jsonrpc.NewClient(opts.api)
if opts.apiToken != "" {
c = jsonrpc.NewClientWithOpts(opts.api, &jsonrpc.RPCClientOpts{CustomHeaders: map[string]string{"Authorization": "Bearer " + opts.apiToken}})

}
hf := &heyFil{
options: opts,
c: jsonrpc.NewClient(opts.api),
c: c,
targets: make(map[string]*Target),
toCheck: make(chan *Target, 100),
checked: make(chan *Target, 100),
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ func main() {
httpIndexerEndpoint := flag.String("httpIndexerEndpoint", "https://cid.contact", "The HTTP IPNI endpoint to which announcements are made.")
maxConcurrentChecks := flag.Int("maxConcurrentChecks", 10, "The maximum number of concurrent checks.")
storePath := flag.String("storePath", "", "The directory to use for storing the discovered SP information.")
token := flag.String("token", "", "A bearer token to pass for auth to the filecoin api endpoint.")
flag.Parse()

hf, err := newHeyFil(
WithHttpIndexerEndpoint(*httpIndexerEndpoint),
WithMaxConcurrentChecks(*maxConcurrentChecks),
WithStorePath(*storePath),
WithFileCoinAPIToken(*token),
)
if err != nil {
panic(err)
Expand Down
9 changes: 9 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type (
Option func(*options) error
options struct {
api string
apiToken string
h host.Host
topic string
headProtocolPattern *regexp.Regexp
Expand All @@ -36,6 +37,7 @@ type (
func newOptions(o ...Option) (*options, error) {
opts := &options{
api: `https://api.node.glif.io`,
apiToken: ``,
marketDealsS3Snapshot: `https://marketdeals.s3.amazonaws.com/StateMarketDeals.json.zst`,
marketDealsFilTools: `https://filecoin.tools/api/deals/list`,
httpIndexerEndpoint: `https://cid.contact`,
Expand Down Expand Up @@ -74,6 +76,13 @@ func WithFileCoinAPI(url string) Option {
}
}

func WithFileCoinAPIToken(token string) Option {
return func(o *options) error {
o.apiToken = token
return nil
}
}

// WithHost specifies the libp2p host.
// If unset, a new host with random identity is instantiated.
func WithHost(h host.Host) Option {
Expand Down

0 comments on commit bbb7f4a

Please sign in to comment.