forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_tls_redirect_wrappa.go
97 lines (87 loc) · 1.88 KB
/
api_tls_redirect_wrappa.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package wrappa
import (
"github.com/concourse/atc"
"github.com/tedsuo/rata"
)
type APITLSRedirectWrappa struct {
externalHost string
}
func NewAPITLSRedirectWrappa(
host string,
) *APITLSRedirectWrappa {
return &APITLSRedirectWrappa{
externalHost: host,
}
}
func (wrappa *APITLSRedirectWrappa) Wrap(handlers rata.Handlers) rata.Handlers {
wrapped := rata.Handlers{}
for name, handler := range handlers {
newHandler := handler
switch name {
//wrap everything that is GET or HEAD
case atc.GetConfig,
atc.ListBuilds,
atc.GetBuild,
atc.GetBuildPlan,
atc.BuildEvents,
atc.BuildResources,
atc.GetBuildPreparation,
atc.ListJobs,
atc.GetJob,
atc.ListJobBuilds,
atc.ListJobInputs,
atc.GetJobBuild,
atc.JobBadge,
atc.ListPipelines,
atc.GetPipeline,
atc.GetVersionsDB,
atc.ListResources,
atc.GetResource,
atc.ListResourceVersions,
atc.ListBuildsWithVersionAsInput,
atc.ListBuildsWithVersionAsOutput,
atc.ListWorkers,
atc.GetLogLevel,
atc.DownloadCLI,
atc.GetInfo,
atc.ListContainers,
atc.GetContainer,
atc.HijackContainer,
atc.ListVolumes,
atc.ListAuthMethods,
atc.GetAuthToken,
atc.ListAllPipelines,
atc.ListTeams:
newHandler = RedirectingAPIHandler(wrappa.externalHost)
//except ReadPipe
case atc.ReadPipe,
atc.CreateBuild,
atc.AbortBuild,
atc.CreateJobBuild,
atc.CheckResource,
atc.CreatePipe,
atc.RegisterWorker,
atc.DeletePipeline,
atc.SaveConfig,
atc.PauseJob,
atc.UnpauseJob,
atc.OrderPipelines,
atc.PausePipeline,
atc.UnpausePipeline,
atc.RenamePipeline,
atc.PauseResource,
atc.UnpauseResource,
atc.EnableResourceVersion,
atc.DisableResourceVersion,
atc.WritePipe,
atc.SetLogLevel,
atc.SetTeam,
atc.ConcealPipeline,
atc.RevealPipeline:
default:
panic("you missed a spot")
}
wrapped[name] = newHandler
}
return wrapped
}