Skip to content

Commit

Permalink
chore: use new surl v2 lib
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Jan 4, 2025
1 parent 231de97 commit 0c5b45c
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 22 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/jackc/pgx/v5 v5.5.5
github.com/jackc/tern/v2 v2.2.2
github.com/jaschaephraim/lrserver v0.0.0-20171129202958-50d19f603f71
github.com/leg100/surl v0.0.5
github.com/leg100/surl/v2 v2.0.0
github.com/lestrrat-go/jwx/v2 v2.1.1
github.com/mitchellh/iochan v1.0.0
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -93,7 +93,7 @@ require (
github.com/hashicorp/jsonapi v0.0.0-20210826224640-ee7dae0fb22d // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/itchyny/base58-go v0.2.0 // indirect
github.com/itchyny/base58-go v0.2.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
Expand Down
11 changes: 4 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/itchyny/base58-go v0.2.0 h1:L8n89aG4XsdjVELfCK8G7TK3fqvDo02P0C4EKBLBx0I=
github.com/itchyny/base58-go v0.2.0/go.mod h1:uSBhd5brsJi5iG4IVb0egRS7SsGU1kgf+xO1AbKMCJE=
github.com/itchyny/base58-go v0.2.2 h1:pswMT6rW2nRoELk5Mi8+xGLQPmDnlNnCwbfRCl2p7Mo=
github.com/itchyny/base58-go v0.2.2/go.mod h1:e7aEDHyQXm42jniwyoi+MaUeUdeWp58C5H20rTe52co=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
Expand All @@ -292,7 +292,6 @@ github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jackc/tern/v2 v2.2.2 h1:pxPcFFBwgmk18zrx1eKh3tmp6Igfstoh33owokekdJo=
github.com/jackc/tern/v2 v2.2.2/go.mod h1:EStqJVUowhII9OpCTcZISE1BfpGlwE4oq0oQtHAGuuI=
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand All @@ -318,8 +317,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/leg100/surl v0.0.5 h1:xykQiuuEdnEumELfayOvGdssLtRYwhy8MUs+mWZo8TE=
github.com/leg100/surl v0.0.5/go.mod h1:TOATXkCJwVSzuNBN4InQAdiFbvAzPh6JqUzIcdu1wms=
github.com/leg100/surl/v2 v2.0.0 h1:kqxK6pQ9V6mu633RZhykI0zlcwUbihTgODvN18M4DWU=
github.com/leg100/surl/v2 v2.0.0/go.mod h1:JnekyIVJm0rwebAScOa0e0SAm+2DIOBOYFf8sYEBNi4=
github.com/lestrrat-go/blackmagic v1.0.2 h1:Cg2gVSc9h7sz9NOByczrbUvLopQmXrfFx//N+AkAr5k=
github.com/lestrrat-go/blackmagic v1.0.2/go.mod h1:UrEqBzIR2U6CnzVyUtfM6oZNMt/7O7Vohk2J0OGSAtU=
github.com/lestrrat-go/httpcc v1.0.1 h1:ydWCStUeJLkpYyjLDHihupbn2tYmZ7m22BGkcvZZrIE=
Expand Down Expand Up @@ -619,11 +618,9 @@ golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
2 changes: 1 addition & 1 deletion internal/configversion/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/leg100/otf/internal/resource"
"github.com/leg100/otf/internal/sql"
"github.com/leg100/otf/internal/tfeapi"
"github.com/leg100/surl"
"github.com/leg100/surl/v2"
)

type (
Expand Down
4 changes: 2 additions & 2 deletions internal/configversion/tfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/leg100/otf/internal/resource"
"github.com/leg100/otf/internal/tfeapi"
"github.com/leg100/otf/internal/tfeapi/types"
"github.com/leg100/surl"
"github.com/leg100/surl/v2"
)

type tfe struct {
Expand Down Expand Up @@ -87,7 +87,7 @@ func (a *tfe) createConfigurationVersion(w http.ResponseWriter, r *http.Request)
//
// https://developer.hashicorp.com/terraform/cloud-docs/api-docs/configuration-versions#configuration-files-upload-url
uploadURL := fmt.Sprintf("/configuration-versions/%s/upload", cv.ID)
uploadURL, err = a.Sign(uploadURL, time.Hour)
uploadURL, err = a.Sign(uploadURL, time.Now().Add(time.Hour))
if err != nil {
tfeapi.Error(w, err)
return
Expand Down
4 changes: 2 additions & 2 deletions internal/module/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/leg100/otf/internal"
"github.com/leg100/otf/internal/http/decode"
"github.com/leg100/otf/internal/tfeapi"
"github.com/leg100/surl"
"github.com/leg100/surl/v2"
)

type api struct {
Expand Down Expand Up @@ -121,7 +121,7 @@ func (h *api) getModuleVersionDownloadLink(w http.ResponseWriter, r *http.Reques
return
}

signed, err := h.Sign(fmt.Sprintf("/modules/download/%s.tar.gz", version.ID), time.Hour)
signed, err := h.Sign(fmt.Sprintf("/modules/download/%s.tar.gz", version.ID), time.Now().Add(time.Hour))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down
2 changes: 1 addition & 1 deletion internal/module/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/leg100/otf/internal/sql/sqlc"
"github.com/leg100/otf/internal/vcs"
"github.com/leg100/otf/internal/vcsprovider"
"github.com/leg100/surl"
"github.com/leg100/surl/v2"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion internal/run/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/leg100/otf/internal/vcs"
"github.com/leg100/otf/internal/vcsprovider"
"github.com/leg100/otf/internal/workspace"
"github.com/leg100/surl"
"github.com/leg100/surl/v2"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion internal/run/tfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ func (a *tfe) toPhaseTimestamps(from []PhaseStatusTimestamp) *types.PhaseStatusT

func (a *tfe) logURL(r *http.Request, phase Phase) (string, error) {
logs := fmt.Sprintf("/runs/%s/logs/%s", phase.RunID, phase.PhaseType)
logs, err := a.Sign(logs, time.Hour)
logs, err := a.Sign(logs, time.Now().Add(time.Hour))
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"

"github.com/gorilla/mux"
"github.com/leg100/surl"
"github.com/leg100/surl/v2"
)

// NewSigner constructs a signer for signing and verifying URLs
Expand All @@ -20,7 +20,7 @@ func NewSigner(secret []byte) *surl.Signer {

// Signer cryptographically signs URLs with a limited lifespan.
type Signer interface {
Sign(string, time.Duration) (string, error)
Sign(string, time.Time) (string, error)
}

// Verifier verifies signed URLs
Expand Down
2 changes: 1 addition & 1 deletion internal/state/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/leg100/otf/internal/sql/sqlc"
"github.com/leg100/otf/internal/tfeapi"
"github.com/leg100/otf/internal/workspace"
"github.com/leg100/surl"
"github.com/leg100/surl/v2"
)

var ErrCurrentVersionDeletionAttempt = errors.New("deleting the current state version is not allowed")
Expand Down
4 changes: 2 additions & 2 deletions internal/state/tfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/leg100/otf/internal/tfeapi"
"github.com/leg100/otf/internal/tfeapi/types"
"github.com/leg100/otf/internal/workspace"
"github.com/leg100/surl"
"github.com/leg100/surl/v2"
"golang.org/x/exp/maps"
)

Expand Down Expand Up @@ -442,7 +442,7 @@ func (a *tfe) includeWorkspaceCurrentOutputs(ctx context.Context, v any) ([]any,

func (a *tfe) generateSignedURL(r *http.Request, fmtpath string, args ...any) (string, error) {
path := fmt.Sprintf(fmtpath, args...)
signedPath, err := a.Sign(path, time.Hour)
signedPath, err := a.Sign(path, time.Now().Add(time.Hour))
if err != nil {
return "", err
}
Expand Down

0 comments on commit 0c5b45c

Please sign in to comment.