Skip to content
Snippets Groups Projects
Commit c0a2b324 authored by steven.jaquet's avatar steven.jaquet
Browse files

Mise à jour de la partie 4 du TP

parent a080017d
Branches
No related tags found
No related merge requests found
No preview for this file type
GET_USERS = "foo aristote"
GET_PASSWORDS = "bar Euclide"
ALL_USERS = "aristote"
ALL_PASSWORDS = "Euclide"
\ No newline at end of file
......@@ -11,7 +11,9 @@ services:
- 443:443
appsec:
env_file: credentials.env
image: docker-app-sec
container_name: appsec
expose:
- "8080"
package main
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"os"
"strings"
"github.com/gin-gonic/gin"
jwtverifier "github.com/okta/okta-jwt-verifier-golang"
)
......@@ -164,27 +167,40 @@ var auth = make(map[string][]string)
func main() {
router := gin.Default()
authGetStudents := router.Group("/", gin.BasicAuth(gin.Accounts{
"foo": "bar",
"aristote": "Eucl1de",
}))
fmt.Print(os.Environ())
authAllStudents := router.Group("/", gin.BasicAuth(gin.Accounts{
"aristote": "Eucl1de",
}))
imported_users_GET := strings.Fields(os.Getenv("GET_USERS"))
imported_passwords_GET := strings.Fields(os.Getenv("GET_PASSWORDS"))
imported_users_ALL := strings.Fields(os.Getenv("ALL_USERS"))
imported_passwords_ALL := strings.Fields(os.Getenv("ALL_PASSWORDS"))
var users_GET = make(map[string]string)
var users_ALL = make(map[string]string)
// Add imported users and passwords for GET requests
for key, val := range imported_users_GET {
user_password := imported_passwords_GET[key]
users_GET[val] = user_password
}
// Add imported users and passwords for ALL requests
for key, val := range imported_users_ALL {
user_password := imported_passwords_ALL[key]
users_ALL[val] = user_password
}
authGetStudents := router.Group("/", gin.BasicAuth(users_GET))
authAllStudents := router.Group("/", gin.BasicAuth(users_ALL))
authGetStudents.GET("/students", getStudents)
authGetStudents.GET("/students/:id", getStudentByID)
authAllStudents.POST("/students", postStudent)
authAllStudents.DELETE("/student/:id", deleteStudent)
auth["steven.jaquet@etu.hesge.ch"] =
append(auth["steven.jaquet@etu.hesge.ch"], "GET", "POST")
auth["michael.jaquet1@etu.hesge.ch"] =
append(auth["michael.jaquet1@etu.hesge.ch"], "GET", "DELETE")
auth["david.jaquet1@etu.hesge.ch"] =
append(auth["david.jaquet1@etu.hesge.ch"], "GET")
auth["steven.jaquet@etu.hesge.ch"] = append(auth["steven.jaquet@etu.hesge.ch"], "GET", "POST")
auth["michael.jaquet1@etu.hesge.ch"] = append(auth["michael.jaquet1@etu.hesge.ch"], "GET", "DELETE")
auth["david.jaquet1@etu.hesge.ch"] = append(auth["david.jaquet1@etu.hesge.ch"], "GET")
router.Run(":8080")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment