-
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.
- Add internal Swagger UI - Add cors
- Loading branch information
Nicolas Choquet
committed
Mar 22, 2024
1 parent
7320ff7
commit f04423c
Showing
63 changed files
with
2,428 additions
and
739 deletions.
There are no files selected for viewing
Empty file.
Empty file.
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
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 was deleted.
Oops, something went wrong.
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,19 @@ | ||
package credentials | ||
|
||
import ( | ||
"filesystem_service/arrays" | ||
"filesystem_service/integer" | ||
"strings" | ||
) | ||
|
||
func CreateNewToken(availableCharacters string, charNumber int) string { | ||
return strings.Join( | ||
arrays.Map[string, string]( | ||
arrays.Generate[string](charNumber), | ||
func(t string) string { | ||
return strings.Split(availableCharacters, "")[integer.RandomBetween(0, len(availableCharacters)-1)] | ||
}, | ||
), | ||
"", | ||
) | ||
} |
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,7 @@ | ||
package credentials | ||
|
||
import "fmt" | ||
|
||
func GenerateClientId() string { | ||
return fmt.Sprintf("fs_service_i@%v", CreateNewToken(AvailableCharacters, 15)) | ||
} |
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,7 @@ | ||
package credentials | ||
|
||
import "fmt" | ||
|
||
func GenerateClientSecret() string { | ||
return fmt.Sprintf("fs_service_s@%v", CreateNewToken(AvailableCharacters, 15)) | ||
} |
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,48 @@ | ||
package credentials | ||
|
||
import ( | ||
"filesystem_service/auth/roles" | ||
"filesystem_service/database" | ||
"fmt" | ||
) | ||
|
||
func GenerateCredentials(role string) { | ||
db, err := database.Init() | ||
defer db.Close() | ||
if err != nil { | ||
fmt.Printf("Une erreur est survenue lors de l'initialisation de la base de donnée.\n") | ||
fmt.Printf(err.Error() + "\n") | ||
return | ||
} | ||
|
||
roleId := roles.GetRoleIdFromName(db, role) | ||
|
||
if roleId != -1 { | ||
fmt.Printf("Generation du client_id ...\n") | ||
fmt.Printf("Generation du client_secret ...\n") | ||
clientId := GenerateClientId() | ||
clientSecret := GenerateClientSecret() | ||
|
||
if _, err = db.Exec(`UPDATE credentials | ||
SET active = FALSE | ||
WHERE active = TRUE;`); err != nil { | ||
fmt.Printf("\nUne erreur est survenue lors de la création du token de signature.\n") | ||
fmt.Printf(err.Error() + "\n") | ||
return | ||
} | ||
|
||
if _, err = db.Exec(`INSERT INTO credentials ( | ||
client_id, | ||
client_secret, | ||
role, | ||
active | ||
) VALUES (?, ?, ?, TRUE);`, clientId, clientSecret, roleId); err != nil { | ||
fmt.Printf("\nUne erreur est survenue lors de la création du token de signature.\n") | ||
fmt.Printf(err.Error() + "\n") | ||
return | ||
} | ||
|
||
fmt.Printf("\nVous devrez les saisir dans le système d'exploitation web.\n") | ||
fmt.Printf("\n=> client_id: %v\n=> client_secret: %v\n", clientId, clientSecret) | ||
} | ||
} |
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,3 @@ | ||
package credentials | ||
|
||
var AvailableCharacters = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789" |
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,40 @@ | ||
package credentials | ||
|
||
import ( | ||
"filesystem_service/auth/roles" | ||
"filesystem_service/database" | ||
"fmt" | ||
) | ||
|
||
func UpdateCredentials(clientId string, newRole string) { | ||
if clientId == "" { | ||
fmt.Printf("Vous devez renseigner le client_id.\n") | ||
return | ||
} | ||
|
||
if newRole == "" { | ||
fmt.Printf("Vous devez renseigner votre nouveau rôle.\n") | ||
return | ||
} | ||
|
||
db, err := database.Init() | ||
defer db.Close() | ||
if err != nil { | ||
fmt.Printf("Une erreur est survenue lors de l'initialisation de la base de donnée.\n") | ||
fmt.Printf(err.Error() + "\n") | ||
return | ||
} | ||
|
||
newRoleId := roles.GetRoleIdFromName(db, newRole) | ||
|
||
if _, err = db.Exec( | ||
`UPDATE credentials SET role = ? WHERE client_id = ?;`, | ||
newRoleId, clientId, | ||
); err != nil { | ||
fmt.Printf("Une erreur est survenue lors de laa modification de votre rôle.\n") | ||
fmt.Printf(err.Error() + "\n") | ||
return | ||
} | ||
|
||
fmt.Printf("Votre rôle à bien été modifié.\n") | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.