-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
525 additions
and
25 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,53 @@ | ||
package shim | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/artefactual/archivematica/hack/ccp/internal/shim/gen" | ||
"github.com/artefactual/archivematica/hack/ccp/internal/store" | ||
) | ||
|
||
const ( | ||
archivematicaVersion = "dev" | ||
) | ||
|
||
func infoMiddleware(store store.Store) func(next gen.StrictHandlerFunc, _ string) gen.StrictHandlerFunc { | ||
pipelineID := "" | ||
|
||
return func(next gen.StrictHandlerFunc, _ string) gen.StrictHandlerFunc { | ||
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (response interface{}, err error) { | ||
if pipelineID == "" { | ||
if id, err := store.ReadPipelineID(ctx); err != nil { | ||
return nil, err | ||
} else { | ||
pipelineID = id.String() | ||
} | ||
} | ||
w.Header().Set("X-Archivematica-Version", archivematicaVersion) | ||
w.Header().Set("x-Archivematica-ID", pipelineID) | ||
return next(ctx, w, r, request) | ||
} | ||
} | ||
} | ||
|
||
type contextKey string | ||
|
||
const ( | ||
requestContextKey contextKey = "requestObject" | ||
) | ||
|
||
func contextMiddleware(next gen.StrictHandlerFunc, _ string) gen.StrictHandlerFunc { | ||
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (response interface{}, err error) { | ||
ctx = context.WithValue(ctx, requestContextKey, r) | ||
return next(ctx, w, r, request) | ||
} | ||
} | ||
|
||
func requestFromContext(ctx context.Context) *http.Request { | ||
if req, ok := ctx.Value(requestContextKey).(*http.Request); ok { | ||
return req | ||
} | ||
|
||
return nil | ||
} |
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.