This repository has been archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
root.go
138 lines (126 loc) · 2.83 KB
/
root.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package http
import (
"encoding/json"
"fmt"
"net/http"
"github.com/18F/e-QIP-prototype/api"
)
var (
// APIName ...
APIName = "eqip"
// APIVersion ...
APIVersion = "v1"
)
type endpoint struct {
Path string
Description string
Verbs []string
}
// RootHandler is the handler for the root endpoint.
type RootHandler struct {
Env api.Settings
}
// ServeHTTP accepts GET requests to get all endpoints that the API
// supports.
func (service RootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Eqip-Media-Type", fmt.Sprintf("%s.%s", APIName, APIVersion))
w.Header().Set("Content-Type", "application/json")
// Core set of endpoints
endpoints := []endpoint{
{
Path: "/",
Description: "root",
Verbs: []string{"GET"},
},
{
Path: "/refresh",
Description: "web token refresh",
Verbs: []string{"POST"},
},
{
Path: "/me",
Description: "me",
Verbs: []string{"GET"},
},
{
Path: "/me/logout",
Description: "end session for account",
Verbs: []string{"GET"},
},
{
Path: "/me/validate",
Description: "validation",
Verbs: []string{"POST"},
},
{
Path: "/me/save",
Description: "save",
Verbs: []string{"POST", "PUT"},
},
{
Path: "/me/form",
Description: "returns the form in its entirety",
Verbs: []string{"GET"},
},
{
Path: "/me/form/hash",
Description: "returns the form hash code",
Verbs: []string{"GET"},
},
{
Path: "/me/section?:id",
Description: "returns the form section",
Verbs: []string{"GET"},
},
}
if service.Env.True(api.AttachmentsEnabled) {
attachments := []endpoint{
{
Path: "/me/attachment",
Description: "store attachment",
Verbs: []string{"POST", "PUT"},
},
{
Path: "/me/attachment/:id",
Description: "get attachment",
Verbs: []string{"GET"},
},
{
Path: "/me/attachment/:id/delete",
Description: "delete attachment",
Verbs: []string{"POST", "DELETE"},
},
}
endpoints = append(endpoints, attachments...)
}
if service.Env.True(api.BasicEnabled) {
basic := []endpoint{
{
Path: "/auth/basic",
Description: "basic authentication",
Verbs: []string{"POST"},
},
}
endpoints = append(endpoints, basic...)
}
if service.Env.True(api.SamlEnabled) {
saml := []endpoint{
{
Path: "/auth/saml",
Description: "SAML entrypoint",
Verbs: []string{"GET"},
},
{
Path: "/auth/saml/callback",
Description: "SAML callback",
Verbs: []string{"GET", "POST"},
},
}
endpoints = append(endpoints, saml...)
}
json.NewEncoder(w).Encode(struct {
Endpoints []endpoint `json:"endpoints"`
}{
Endpoints: endpoints,
})
}