-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from auth0/improve-log-errors
feat: log errors context
- Loading branch information
Showing
214 changed files
with
10,429 additions
and
10,578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package actions | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/auth0/auth0-cli/internal/auth0" | ||
"gopkg.in/auth0.v5/management" | ||
) | ||
|
||
// NewSampledExecutionAPI creates a decorated ActionExecutionAPI which | ||
// implements a leaky bucket based on the given interval. | ||
func NewSampledExecutionAPI(api auth0.ActionExecutionAPI, interval time.Duration) auth0.ActionExecutionAPI { | ||
return &sampledExecutionAPI{ | ||
api: api, | ||
interval: interval, | ||
timer: time.NewTimer(0), | ||
} | ||
} | ||
|
||
type sampledExecutionAPI struct { | ||
auth0.ActionExecutionAPI | ||
|
||
api auth0.ActionExecutionAPI | ||
|
||
interval time.Duration | ||
timer *time.Timer | ||
} | ||
|
||
// errRateLimited is returned whenever the leaky bucket isn't ready to drip. | ||
var errRateLimited = errors.New("actions: rate limited") | ||
|
||
// Read checks if the leaky bucket is ready to drip: if not, then an | ||
// errRateLimited is returned. | ||
func (a *sampledExecutionAPI) Read(id string) (*management.ActionExecution, error) { | ||
select { | ||
case <-a.timer.C: | ||
a.timer.Reset(a.interval) | ||
return a.api.Read(id) | ||
default: | ||
return nil, errRateLimited | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.