mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 15:14:38 +00:00
Export maps from permission generation (#3137)
* Adjust permission generation to make maps exportable * fix bug and add twilio
This commit is contained in:
parent
25b01019b3
commit
555e1ceeee
6 changed files with 41 additions and 41 deletions
|
@ -58,7 +58,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
permissionStrings = map[Permission]string{
|
||||
PermissionStrings = map[Permission]string{
|
||||
Repo: "repo",
|
||||
RepoStatus: "repo:status",
|
||||
RepoDeployment: "repo_deployment",
|
||||
|
@ -109,7 +109,7 @@ var (
|
|||
ReadSshSigningKey: "read:ssh_signing_key",
|
||||
}
|
||||
|
||||
stringToPermission = map[string]Permission{
|
||||
StringToPermission = map[string]Permission{
|
||||
"repo": Repo,
|
||||
"repo:status": RepoStatus,
|
||||
"repo_deployment": RepoDeployment,
|
||||
|
@ -160,7 +160,7 @@ var (
|
|||
"read:ssh_signing_key": ReadSshSigningKey,
|
||||
}
|
||||
|
||||
permissionIDs = map[Permission]int{
|
||||
PermissionIDs = map[Permission]int{
|
||||
Repo: 0,
|
||||
RepoStatus: 1,
|
||||
RepoDeployment: 2,
|
||||
|
@ -211,7 +211,7 @@ var (
|
|||
ReadSshSigningKey: 47,
|
||||
}
|
||||
|
||||
idToPermission = map[int]Permission{
|
||||
IdToPermission = map[int]Permission{
|
||||
0: Repo,
|
||||
1: RepoStatus,
|
||||
2: RepoDeployment,
|
||||
|
@ -265,7 +265,7 @@ var (
|
|||
|
||||
// ToString converts a Permission enum to its string representation
|
||||
func (p Permission) ToString() (string, error) {
|
||||
if str, ok := permissionStrings[p]; ok {
|
||||
if str, ok := PermissionStrings[p]; ok {
|
||||
return str, nil
|
||||
}
|
||||
return "", errors.New("invalid permission")
|
||||
|
@ -273,7 +273,7 @@ func (p Permission) ToString() (string, error) {
|
|||
|
||||
// ToID converts a Permission enum to its ID
|
||||
func (p Permission) ToID() (int, error) {
|
||||
if id, ok := permissionIDs[p]; ok {
|
||||
if id, ok := PermissionIDs[p]; ok {
|
||||
return id, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission")
|
||||
|
@ -281,7 +281,7 @@ func (p Permission) ToID() (int, error) {
|
|||
|
||||
// PermissionFromString converts a string representation to its Permission enum
|
||||
func PermissionFromString(s string) (Permission, error) {
|
||||
if p, ok := stringToPermission[s]; ok {
|
||||
if p, ok := StringToPermission[s]; ok {
|
||||
return p, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission string")
|
||||
|
@ -289,7 +289,7 @@ func PermissionFromString(s string) (Permission, error) {
|
|||
|
||||
// PermissionFromID converts an ID to its Permission enum
|
||||
func PermissionFromID(id int) (Permission, error) {
|
||||
if p, ok := idToPermission[id]; ok {
|
||||
if p, ok := IdToPermission[id]; ok {
|
||||
return p, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission ID")
|
||||
|
|
|
@ -69,7 +69,7 @@ func hasPrivateRepoAccess(scopes map[Permission]bool) bool {
|
|||
func processScopes(headerScopesSlice []analyzers.Permission) map[Permission]bool {
|
||||
allScopes := make(map[Permission]bool)
|
||||
for _, scope := range headerScopesSlice {
|
||||
allScopes[stringToPermission[scope.Value]] = true
|
||||
allScopes[StringToPermission[scope.Value]] = true
|
||||
}
|
||||
for scope := range allScopes {
|
||||
if subScopes, ok := SCOPE_TO_SUB_SCOPE[scope]; ok {
|
||||
|
|
|
@ -88,7 +88,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
permissionStrings = map[Permission]string{
|
||||
PermissionStrings = map[Permission]string{
|
||||
ActionsRead: "actions:read",
|
||||
ActionsWrite: "actions:write",
|
||||
AdministrationRead: "administration:read",
|
||||
|
@ -169,7 +169,7 @@ var (
|
|||
WatchingWrite: "watching:write",
|
||||
}
|
||||
|
||||
stringToPermission = map[string]Permission{
|
||||
StringToPermission = map[string]Permission{
|
||||
"actions:read": ActionsRead,
|
||||
"actions:write": ActionsWrite,
|
||||
"administration:read": AdministrationRead,
|
||||
|
@ -250,7 +250,7 @@ var (
|
|||
"watching:write": WatchingWrite,
|
||||
}
|
||||
|
||||
permissionIDs = map[Permission]int{
|
||||
PermissionIDs = map[Permission]int{
|
||||
ActionsRead: 0,
|
||||
ActionsWrite: 1,
|
||||
AdministrationRead: 2,
|
||||
|
@ -331,7 +331,7 @@ var (
|
|||
WatchingWrite: 77,
|
||||
}
|
||||
|
||||
idToPermission = map[int]Permission{
|
||||
IdToPermission = map[int]Permission{
|
||||
0: ActionsRead,
|
||||
1: ActionsWrite,
|
||||
2: AdministrationRead,
|
||||
|
@ -415,7 +415,7 @@ var (
|
|||
|
||||
// ToString converts a Permission enum to its string representation
|
||||
func (p Permission) ToString() (string, error) {
|
||||
if str, ok := permissionStrings[p]; ok {
|
||||
if str, ok := PermissionStrings[p]; ok {
|
||||
return str, nil
|
||||
}
|
||||
return "", errors.New("invalid permission")
|
||||
|
@ -423,7 +423,7 @@ func (p Permission) ToString() (string, error) {
|
|||
|
||||
// ToID converts a Permission enum to its ID
|
||||
func (p Permission) ToID() (int, error) {
|
||||
if id, ok := permissionIDs[p]; ok {
|
||||
if id, ok := PermissionIDs[p]; ok {
|
||||
return id, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission")
|
||||
|
@ -431,7 +431,7 @@ func (p Permission) ToID() (int, error) {
|
|||
|
||||
// PermissionFromString converts a string representation to its Permission enum
|
||||
func PermissionFromString(s string) (Permission, error) {
|
||||
if p, ok := stringToPermission[s]; ok {
|
||||
if p, ok := StringToPermission[s]; ok {
|
||||
return p, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission string")
|
||||
|
@ -439,7 +439,7 @@ func PermissionFromString(s string) (Permission, error) {
|
|||
|
||||
// PermissionFromID converts an ID to its Permission enum
|
||||
func PermissionFromID(id int) (Permission, error) {
|
||||
if p, ok := idToPermission[id]; ok {
|
||||
if p, ok := IdToPermission[id]; ok {
|
||||
return p, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission ID")
|
||||
|
|
|
@ -20,7 +20,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
permissionStrings = map[Permission]string{
|
||||
PermissionStrings = map[Permission]string{
|
||||
ModelsRead: "models:read",
|
||||
ModelCapabilitiesWrite: "model_capabilities:write",
|
||||
AssistantsRead: "assistants:read",
|
||||
|
@ -33,7 +33,7 @@ var (
|
|||
FilesWrite: "files:write",
|
||||
}
|
||||
|
||||
stringToPermission = map[string]Permission{
|
||||
StringToPermission = map[string]Permission{
|
||||
"models:read": ModelsRead,
|
||||
"model_capabilities:write": ModelCapabilitiesWrite,
|
||||
"assistants:read": AssistantsRead,
|
||||
|
@ -46,7 +46,7 @@ var (
|
|||
"files:write": FilesWrite,
|
||||
}
|
||||
|
||||
permissionIDs = map[Permission]int{
|
||||
PermissionIDs = map[Permission]int{
|
||||
ModelsRead: 0,
|
||||
ModelCapabilitiesWrite: 1,
|
||||
AssistantsRead: 2,
|
||||
|
@ -59,7 +59,7 @@ var (
|
|||
FilesWrite: 9,
|
||||
}
|
||||
|
||||
idToPermission = map[int]Permission{
|
||||
IdToPermission = map[int]Permission{
|
||||
0: ModelsRead,
|
||||
1: ModelCapabilitiesWrite,
|
||||
2: AssistantsRead,
|
||||
|
@ -75,7 +75,7 @@ var (
|
|||
|
||||
// ToString converts a Permission enum to its string representation
|
||||
func (p Permission) ToString() (string, error) {
|
||||
if str, ok := permissionStrings[p]; ok {
|
||||
if str, ok := PermissionStrings[p]; ok {
|
||||
return str, nil
|
||||
}
|
||||
return "", errors.New("invalid permission")
|
||||
|
@ -83,7 +83,7 @@ func (p Permission) ToString() (string, error) {
|
|||
|
||||
// ToID converts a Permission enum to its ID
|
||||
func (p Permission) ToID() (int, error) {
|
||||
if id, ok := permissionIDs[p]; ok {
|
||||
if id, ok := PermissionIDs[p]; ok {
|
||||
return id, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission")
|
||||
|
@ -91,7 +91,7 @@ func (p Permission) ToID() (int, error) {
|
|||
|
||||
// PermissionFromString converts a string representation to its Permission enum
|
||||
func PermissionFromString(s string) (Permission, error) {
|
||||
if p, ok := stringToPermission[s]; ok {
|
||||
if p, ok := StringToPermission[s]; ok {
|
||||
return p, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission string")
|
||||
|
@ -99,7 +99,7 @@ func PermissionFromString(s string) (Permission, error) {
|
|||
|
||||
// PermissionFromID converts an ID to its Permission enum
|
||||
func PermissionFromID(id int) (Permission, error) {
|
||||
if p, ok := idToPermission[id]; ok {
|
||||
if p, ok := IdToPermission[id]; ok {
|
||||
return p, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission ID")
|
||||
|
|
|
@ -26,7 +26,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
permissionStrings = map[Permission]string{
|
||||
PermissionStrings = map[Permission]string{
|
||||
AccountManagementRead: "account_management:read",
|
||||
AccountManagementWrite: "account_management:write",
|
||||
SubaccountConfigurationRead: "subaccount_configuration:read",
|
||||
|
@ -45,7 +45,7 @@ var (
|
|||
CallManagementWrite: "call_management:write",
|
||||
}
|
||||
|
||||
stringToPermission = map[string]Permission{
|
||||
StringToPermission = map[string]Permission{
|
||||
"account_management:read": AccountManagementRead,
|
||||
"account_management:write": AccountManagementWrite,
|
||||
"subaccount_configuration:read": SubaccountConfigurationRead,
|
||||
|
@ -64,7 +64,7 @@ var (
|
|||
"call_management:write": CallManagementWrite,
|
||||
}
|
||||
|
||||
permissionIDs = map[Permission]int{
|
||||
PermissionIDs = map[Permission]int{
|
||||
AccountManagementRead: 0,
|
||||
AccountManagementWrite: 1,
|
||||
SubaccountConfigurationRead: 2,
|
||||
|
@ -83,7 +83,7 @@ var (
|
|||
CallManagementWrite: 15,
|
||||
}
|
||||
|
||||
idToPermission = map[int]Permission{
|
||||
IdToPermission = map[int]Permission{
|
||||
0: AccountManagementRead,
|
||||
1: AccountManagementWrite,
|
||||
2: SubaccountConfigurationRead,
|
||||
|
@ -105,7 +105,7 @@ var (
|
|||
|
||||
// ToString converts a Permission enum to its string representation
|
||||
func (p Permission) ToString() (string, error) {
|
||||
if str, ok := permissionStrings[p]; ok {
|
||||
if str, ok := PermissionStrings[p]; ok {
|
||||
return str, nil
|
||||
}
|
||||
return "", errors.New("invalid permission")
|
||||
|
@ -113,7 +113,7 @@ func (p Permission) ToString() (string, error) {
|
|||
|
||||
// ToID converts a Permission enum to its ID
|
||||
func (p Permission) ToID() (int, error) {
|
||||
if id, ok := permissionIDs[p]; ok {
|
||||
if id, ok := PermissionIDs[p]; ok {
|
||||
return id, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission")
|
||||
|
@ -121,7 +121,7 @@ func (p Permission) ToID() (int, error) {
|
|||
|
||||
// PermissionFromString converts a string representation to its Permission enum
|
||||
func PermissionFromString(s string) (Permission, error) {
|
||||
if p, ok := stringToPermission[s]; ok {
|
||||
if p, ok := StringToPermission[s]; ok {
|
||||
return p, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission string")
|
||||
|
@ -129,7 +129,7 @@ func PermissionFromString(s string) (Permission, error) {
|
|||
|
||||
// PermissionFromID converts an ID to its Permission enum
|
||||
func PermissionFromID(id int) (Permission, error) {
|
||||
if p, ok := idToPermission[id]; ok {
|
||||
if p, ok := IdToPermission[id]; ok {
|
||||
return p, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission ID")
|
||||
|
|
|
@ -32,25 +32,25 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
permissionStrings = map[Permission]string{
|
||||
PermissionStrings = map[Permission]string{
|
||||
{{- range $index, $permission := .Permissions }}
|
||||
{{ ToCamelCase $permission }}: "{{ $permission }}",
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
stringToPermission = map[string]Permission{
|
||||
StringToPermission = map[string]Permission{
|
||||
{{- range $index, $permission := .Permissions }}
|
||||
"{{ $permission }}": {{ ToCamelCase $permission }},
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
permissionIDs = map[Permission]int{
|
||||
PermissionIDs = map[Permission]int{
|
||||
{{- range $index, $permission := .Permissions }}
|
||||
{{ ToCamelCase $permission }}: {{ $index }},
|
||||
{{- end }}
|
||||
}
|
||||
|
||||
idToPermission = map[int]Permission{
|
||||
IdToPermission = map[int]Permission{
|
||||
{{- range $index, $permission := .Permissions }}
|
||||
{{ $index }}: {{ ToCamelCase $permission }},
|
||||
{{- end }}
|
||||
|
@ -59,7 +59,7 @@ var (
|
|||
|
||||
// ToString converts a Permission enum to its string representation
|
||||
func (p Permission) ToString() (string, error) {
|
||||
if str, ok := permissionStrings[p]; ok {
|
||||
if str, ok := PermissionStrings[p]; ok {
|
||||
return str, nil
|
||||
}
|
||||
return "", errors.New("invalid permission")
|
||||
|
@ -67,7 +67,7 @@ func (p Permission) ToString() (string, error) {
|
|||
|
||||
// ToID converts a Permission enum to its ID
|
||||
func (p Permission) ToID() (int, error) {
|
||||
if id, ok := permissionIDs[p]; ok {
|
||||
if id, ok := PermissionIDs[p]; ok {
|
||||
return id, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission")
|
||||
|
@ -75,7 +75,7 @@ func (p Permission) ToID() (int, error) {
|
|||
|
||||
// PermissionFromString converts a string representation to its Permission enum
|
||||
func PermissionFromString(s string) (Permission, error) {
|
||||
if p, ok := stringToPermission[s]; ok {
|
||||
if p, ok := StringToPermission[s]; ok {
|
||||
return p, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission string")
|
||||
|
@ -83,7 +83,7 @@ func PermissionFromString(s string) (Permission, error) {
|
|||
|
||||
// PermissionFromID converts an ID to its Permission enum
|
||||
func PermissionFromID(id int) (Permission, error) {
|
||||
if p, ok := idToPermission[id]; ok {
|
||||
if p, ok := IdToPermission[id]; ok {
|
||||
return p, nil
|
||||
}
|
||||
return 0, errors.New("invalid permission ID")
|
||||
|
|
Loading…
Reference in a new issue