Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to pass an auth token #57

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditionally instantiate if token is set?

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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WithBearerAuthToken?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://api.node.glif.io/ just calls them api keys :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would drop FileCoin from the name. I think we don't much that specifically depends on glif. Unless the snapshot format is glif-specific?

In any case, there are mo blockers here.

)
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
Loading