Skip to content

Commit

Permalink
update swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
Raajheer1 committed Aug 27, 2024
1 parent 17ee073 commit fa5b4ae
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cmd/api/external/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/VATUSA/primary-api/pkg/oauth"
"github.com/VATUSA/primary-api/pkg/storage"
"github.com/joho/godotenv"
"log"
log "github.com/sirupsen/logrus"
"net/http"
)

Expand Down
23 changes: 0 additions & 23 deletions cmd/api/external/main_tls.go

This file was deleted.

7 changes: 7 additions & 0 deletions external/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4740,6 +4740,13 @@ const docTemplate = `{
}
}
}
},
"securityDefinitions": {
"ApiKeyAuth": {
"type": "apiKey",
"name": "x-api-key",
"in": "header"
}
}
}`

Expand Down
7 changes: 7 additions & 0 deletions external/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4733,5 +4733,12 @@
}
}
}
},
"securityDefinitions": {
"ApiKeyAuth": {
"type": "apiKey",
"name": "x-api-key",
"in": "header"
}
}
}
5 changes: 5 additions & 0 deletions external/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3228,4 +3228,9 @@ paths:
summary: Update a user flag
tags:
- user-flag
securityDefinitions:
ApiKeyAuth:
in: header
name: x-api-key
type: apiKey
swagger: "2.0"
4 changes: 4 additions & 0 deletions external/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import (

// @BasePath /v3

// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name x-api-key

func Router(r chi.Router, cfg *config.Config) {
v3.Router(r, cfg)

Expand Down
7 changes: 4 additions & 3 deletions external/v3/user/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/VATUSA/primary-api/pkg/utils"
vatsim_api "github.com/VATUSA/primary-api/pkg/vatsim/api"
gonanoid "github.com/matoous/go-nanoid"
log "github.com/sirupsen/logrus"
"golang.org/x/oauth2"
"io"
"net/http"
Expand Down Expand Up @@ -54,12 +55,14 @@ func GetLogin(w http.ResponseWriter, r *http.Request) {
func GetLoginCallback(w http.ResponseWriter, r *http.Request) {
sessionCookie, err := r.Cookie("session")
if err != nil {
log.WithError(err).Error("Error getting session cookie.")
utils.Render(w, r, utils.ErrForbidden)
return
}

session := make(map[string]string)
if err := cookie.CookieStore.Decode("session", sessionCookie.Value, &session); err != nil {
log.WithError(err).Error("Error decoding session cookie.")
utils.Render(w, r, utils.ErrForbidden)
return
}
Expand All @@ -71,7 +74,7 @@ func GetLoginCallback(w http.ResponseWriter, r *http.Request) {

token, err := exchangeToken(r.Context(), oauth.OAuthConfig, r.URL.Query().Get("code"))
if err != nil {
fmt.Printf("Error: %s\n", err)
log.WithError(err).Error("Error exchanging tokens with VATSIM.")
utils.Render(w, r, utils.ErrInternalServer)
return
}
Expand Down Expand Up @@ -110,8 +113,6 @@ func GetLoginCallback(w http.ResponseWriter, r *http.Request) {
}

if resp.StatusCode >= 299 {
fmt.Println("Error Code:", resp.StatusCode)
fmt.Println("Error Body:", string(body))
utils.Render(w, r, utils.ErrInternalServer)
return
}
Expand Down
1 change: 1 addition & 0 deletions external/v3/user/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

func Router(r chi.Router) {
r.With(middleware.NotGuest).Get("/logout", GetLogout)

r.Get("/login", GetLogin)
r.Get("/login/callback", GetLoginCallback)

Expand Down
5 changes: 5 additions & 0 deletions pkg/go-chi/middleware/auth/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ func CanViewUser(next http.Handler) http.Handler {

credentials := GetCredentials(r)
if credentials.User != nil {
if targetUser.CID == credentials.User.CID {
next.ServeHTTP(w, r)
return
}

if utils.IsVATUSAStaff(credentials.User) {
next.ServeHTTP(w, r)
return
Expand Down
1 change: 1 addition & 0 deletions pkg/go-chi/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func New(cfg *config.Config) *chi.Mux {

r.Use(middleware.Recoverer)
r.Use(middleware.RealIP)
r.Use(middleware.Logger)

r.Use(render.SetContentType(render.ContentTypeJSON))

Expand Down

0 comments on commit fa5b4ae

Please sign in to comment.