Skip to content

Commit

Permalink
Standardize cors handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
emosbaugh committed Aug 26, 2020
1 parent f441287 commit 46827e0
Show file tree
Hide file tree
Showing 27 changed files with 67 additions and 281 deletions.
12 changes: 2 additions & 10 deletions kotsadm/pkg/handlers/airgap.go
Expand Up @@ -25,11 +25,7 @@ type UpdateAppFromAirgapResponse struct {
}

func GetAirgapInstallStatus(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down Expand Up @@ -76,11 +72,7 @@ func ResetAirgapInstallStatus(w http.ResponseWriter, r *http.Request) {
}

func UploadAirgapBundle(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down
12 changes: 2 additions & 10 deletions kotsadm/pkg/handlers/app.go
Expand Up @@ -74,11 +74,7 @@ type ResponseCluster struct {
}

func ListApps(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down Expand Up @@ -113,11 +109,7 @@ func ListApps(w http.ResponseWriter, r *http.Request) {
}

func GetApp(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down
30 changes: 5 additions & 25 deletions kotsadm/pkg/handlers/backup.go
Expand Up @@ -21,11 +21,7 @@ type CreateBackupResponse struct {
}

func CreateBackup(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down Expand Up @@ -75,11 +71,7 @@ type ListBackupsResponse struct {
}

func ListBackups(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down Expand Up @@ -139,11 +131,7 @@ type ListKotsadmBackupsResponse struct {
}

func ListKotsadmBackups(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down Expand Up @@ -183,11 +171,7 @@ type GetKotsadmBackupResponse struct {
}

func GetKotsadmBackup(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down Expand Up @@ -228,11 +212,7 @@ type DeleteKotsadmBackupResponse struct {
}

func DeleteKotsadmBackup(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down
18 changes: 3 additions & 15 deletions kotsadm/pkg/handlers/config.go
Expand Up @@ -62,11 +62,7 @@ type CurrentAppConfigResponse struct {
}

func UpdateAppConfig(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down Expand Up @@ -161,11 +157,7 @@ func UpdateAppConfig(w http.ResponseWriter, r *http.Request) {
}

func LiveAppConfig(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down Expand Up @@ -258,11 +250,7 @@ func LiveAppConfig(w http.ResponseWriter, r *http.Request) {
}

func CurrentAppConfig(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down
6 changes: 1 addition & 5 deletions kotsadm/pkg/handlers/contents.go
Expand Up @@ -18,11 +18,7 @@ type GetAppContentsResponse struct {
}

func GetAppContents(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down
6 changes: 1 addition & 5 deletions kotsadm/pkg/handlers/dashboard.go
Expand Up @@ -20,11 +20,7 @@ type GetAppDashboardResponse struct {
}

func GetAppDashboard(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down
6 changes: 1 addition & 5 deletions kotsadm/pkg/handlers/deploy.go
Expand Up @@ -19,11 +19,7 @@ import (
)

func DeployAppVersion(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down
6 changes: 1 addition & 5 deletions kotsadm/pkg/handlers/downstream.go
Expand Up @@ -11,11 +11,7 @@ import (
)

func GetDownstreamOutput(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down
6 changes: 1 addition & 5 deletions kotsadm/pkg/handlers/image_rewrite_status.go
Expand Up @@ -14,11 +14,7 @@ type GetImageRewriteStatusResponse struct {
}

func GetImageRewriteStatus(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down
6 changes: 1 addition & 5 deletions kotsadm/pkg/handlers/kurl_delete_node.go
Expand Up @@ -14,11 +14,7 @@ import (
)

func DeleteNode(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down
6 changes: 1 addition & 5 deletions kotsadm/pkg/handlers/kurl_drain_node.go
Expand Up @@ -13,11 +13,7 @@ import (
)

func DrainNode(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down
12 changes: 2 additions & 10 deletions kotsadm/pkg/handlers/kurl_node_join_command.go
Expand Up @@ -15,11 +15,7 @@ type GenerateNodeJoinCommandResponse struct {
}

func GenerateNodeJoinCommandWorker(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down Expand Up @@ -48,11 +44,7 @@ func GenerateNodeJoinCommandWorker(w http.ResponseWriter, r *http.Request) {
}

func GenerateNodeJoinCommandMaster(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down
30 changes: 5 additions & 25 deletions kotsadm/pkg/handlers/license.go
Expand Up @@ -86,11 +86,7 @@ type GetOnlineInstallStatusErrorResponse struct {
}

func SyncLicense(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down Expand Up @@ -148,11 +144,7 @@ func SyncLicense(w http.ResponseWriter, r *http.Request) {
}

func GetLicense(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down Expand Up @@ -234,11 +226,7 @@ func getLicenseEntitlements(license *kotsv1beta1.License) ([]EntitlementResponse
}

func UploadNewLicense(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down Expand Up @@ -370,11 +358,7 @@ func UploadNewLicense(w http.ResponseWriter, r *http.Request) {
}

func ResumeInstallOnline(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down Expand Up @@ -457,11 +441,7 @@ func ResumeInstallOnline(w http.ResponseWriter, r *http.Request) {
}

func GetOnlineInstallStatus(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down
5 changes: 1 addition & 4 deletions kotsadm/pkg/handlers/login.go
Expand Up @@ -20,10 +20,7 @@ type LoginResponse struct {
}

func Login(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
if handleOptionsRequest(w, r) {
return
}

Expand Down
6 changes: 1 addition & 5 deletions kotsadm/pkg/handlers/logout.go
Expand Up @@ -9,11 +9,7 @@ import (
)

func Logout(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down
6 changes: 1 addition & 5 deletions kotsadm/pkg/handlers/metadata.go
Expand Up @@ -23,11 +23,7 @@ type MetadataResponse struct {
}

func Metadata(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
if handleOptionsRequest(w, r) {
return
}

Expand Down
4 changes: 3 additions & 1 deletion kotsadm/pkg/handlers/ping.go
Expand Up @@ -16,7 +16,9 @@ type PingResponse struct {
}

func Ping(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
if handleOptionsRequest(w, r) {
return
}

pingResponse := PingResponse{}

Expand Down
6 changes: 1 addition & 5 deletions kotsadm/pkg/handlers/platform_license.go
Expand Up @@ -22,11 +22,7 @@ type ExchangePlatformLicenseResponse struct {
}

func ExchangePlatformLicense(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
if handleOptionsRequest(w, r) {
return
}

Expand Down

0 comments on commit 46827e0

Please sign in to comment.