-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This service authorizes calls and converts extensions to users. This information can be used in Asterisk to take action.
- Loading branch information
1 parent
360784b
commit 24f18d4
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- migrate:up | ||
ALTER TABLE ps_endpoints ADD COLUMN sid SERIAL PRIMARY KEY; | ||
|
||
CREATE TABLE ery_extension ( | ||
id SERIAL PRIMARY KEY, | ||
endpoint_id SERIAL NOT NULL, | ||
extension varchar UNIQUE, | ||
FOREIGN KEY (endpoint_id) REFERENCES ps_endpoints(sid) | ||
) | ||
|
||
-- migrate:down | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package bouncer | ||
|
||
type Response struct { | ||
Allow bool `json:"allow"` | ||
Destination string `json:"destination"` | ||
} | ||
|
||
func Check(endpoint, extension string) (Response, error) { | ||
return Response{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package handler | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/go-chi/chi/v5" | ||
"github.com/jackc/pgx/v5" | ||
"net/http" | ||
) | ||
|
||
type Authorization struct { | ||
*pgx.Conn | ||
} | ||
|
||
type AuthorizationRequest struct { | ||
From string `json:"endpoint"` | ||
Extension string `json:"extension"` | ||
} | ||
|
||
func (e *Authorization) Router() chi.Router { | ||
r := chi.NewRouter() | ||
r.Post("/", e.post) | ||
|
||
return r | ||
} | ||
|
||
// @Summary Determine whether the specified action (call) is allowed or not. | ||
// @Accept json | ||
// @Produce json | ||
// @Param payload body AuthorizationRequest true "Action to be reviewed" | ||
// @Success 200 {object} bouncer.Response | ||
// @Failure 400 | ||
// @Failure 500 | ||
// @Tags bouncer | ||
// @Router /bouncer [post] | ||
func (e *Authorization) post(w http.ResponseWriter, r *http.Request) { | ||
var payload AuthorizationRequest | ||
decoder := json.NewDecoder(r.Body) | ||
err := decoder.Decode(&payload) | ||
if err != nil { | ||
w.WriteHeader(http.StatusBadRequest) | ||
return | ||
} | ||
} |