-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LaunchDarkly Token Analyzer #3948
Changes from 1 commit
36e64af
1c92298
f143fa8
b840782
aab2c0a
9806026
cc2ac00
8ff00ae
745868e
6d3b8fa
6902b03
746e4fb
8452bdd
d445b25
25356be
4235470
143947a
8a0561a
deccdd9
8d6265f
08cdc2f
47cdd0c
1c61fce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,17 @@ package launchdarkly | |
|
||
import "sync" | ||
|
||
var ( | ||
MetadataKey = "key" | ||
|
||
// resource types | ||
applicationType = "Application" | ||
repositoryType = "Repository" | ||
projectType = "Project" | ||
environmentType = "Environment" | ||
experimentType = "Expirement" | ||
) | ||
|
||
type SecretInfo struct { | ||
User User | ||
Permissions []string | ||
|
@@ -42,7 +53,16 @@ type CustomRole struct { | |
AssignedToTeams int | ||
} | ||
|
||
// policy is a set of statements | ||
/* | ||
policy is a set of statements | ||
|
||
Jargon: | ||
- Resource: List of resources | ||
- NotResources: Except this list of resources | ||
- Actions: List of actions | ||
- NotActions: Except this list of actions | ||
- Effect: Allowed or Denied | ||
*/ | ||
type Policy struct { | ||
Resources []string | ||
NotResources []string | ||
|
@@ -70,8 +90,8 @@ func (s *SecretInfo) addPermission(perm string) { | |
|
||
// hasPermission checks if a particular permission exist in secret info permissions list. | ||
func (s *SecretInfo) hasPermission(perm string) bool { | ||
s.mu.Lock() | ||
defer s.mu.Unlock() | ||
s.mu.RLock() | ||
defer s.mu.RUnlock() | ||
|
||
for _, permission := range s.Permissions { | ||
if permission == perm { | ||
|
@@ -90,6 +110,37 @@ func (s *SecretInfo) appendResource(resource Resource) { | |
s.Resources = append(s.Resources, resource) | ||
} | ||
|
||
// listResourceByType returns a list of resources matching the given type. | ||
func (s *SecretInfo) listResourceByType(resourceType string) []Resource { | ||
s.mu.RLock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Do we actually need the mutex? 🤔 I didn’t notice any concurrent operations, but I might have missed something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you missed the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😢 I knew there had to be a reason. Sorry about that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries! |
||
defer s.mu.RUnlock() | ||
|
||
resources := make([]Resource, 0, len(s.Resources)) | ||
for _, resource := range s.Resources { | ||
if resource.Type == resourceType { | ||
resources = append(resources, resource) | ||
} | ||
} | ||
|
||
return resources | ||
} | ||
|
||
// getResourceByID returns a copy of the resource matching the given ID, or nil if not found. | ||
func (s *SecretInfo) getResourceByID(id string) *Resource { | ||
s.mu.RLock() | ||
defer s.mu.RUnlock() | ||
|
||
for _, resource := range s.Resources { | ||
if resource.ID == id { | ||
// return a copy of the resource to avoid accidently making changes in the actual resource | ||
copyResource := resource | ||
return ©Resource | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// hasCustomRoles check if token has any custom roles assigned | ||
func (t Token) hasCustomRoles() bool { | ||
return len(t.CustomRoles) > 0 | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣