get.go 945 B

1234567891011121314151617181920212223242526272829303132
  1. package gitinstallation
  2. import (
  3. "net/http"
  4. "github.com/porter-dev/porter/api/server/authz"
  5. "github.com/porter-dev/porter/api/server/handlers"
  6. "github.com/porter-dev/porter/api/server/shared"
  7. "github.com/porter-dev/porter/api/types"
  8. "github.com/porter-dev/porter/internal/models/integrations"
  9. )
  10. type GitInstallationGetHandler struct {
  11. handlers.PorterHandlerWriter
  12. authz.KubernetesAgentGetter
  13. }
  14. func NewGitInstallationGetHandler(
  15. config *shared.Config,
  16. writer shared.ResultWriter,
  17. ) *GitInstallationGetHandler {
  18. return &GitInstallationGetHandler{
  19. PorterHandlerWriter: handlers.NewDefaultPorterHandler(config, nil, writer),
  20. KubernetesAgentGetter: authz.NewOutOfClusterAgentGetter(config),
  21. }
  22. }
  23. func (c *GitInstallationGetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  24. ga, _ := r.Context().Value(types.GitInstallationScope).(*integrations.GithubAppInstallation)
  25. c.WriteResult(w, ga.ToGitInstallationType())
  26. }