4468903535
Adds a new hashed key storage mechanism for API keys in the cache. Replaces direct mapping to API keys with composite keys based on organizationId and name. Implements searching of API keys using hash comparisons for improved security. Updates related tests to ensure correct functionality and validate the hashing. Also, adds support for a new dependency `golang.org/x/crypto`.
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package graph
|
|
|
|
import (
|
|
"gitlab.com/unboundsoftware/schemas/domain"
|
|
"gitlab.com/unboundsoftware/schemas/graph/model"
|
|
)
|
|
|
|
func ToGqlOrganizations(orgs []domain.Organization) []*model.Organization {
|
|
result := make([]*model.Organization, len(orgs))
|
|
for i, o := range orgs {
|
|
result[i] = ToGqlOrganization(o)
|
|
}
|
|
return result
|
|
}
|
|
|
|
func ToGqlOrganization(o domain.Organization) *model.Organization {
|
|
users := ToGqlUsers(o.Users)
|
|
apiKeys := ToGqlAPIKeys(o.APIKeys)
|
|
return &model.Organization{
|
|
ID: o.ID.String(),
|
|
Name: o.Name,
|
|
Users: users,
|
|
APIKeys: apiKeys,
|
|
}
|
|
}
|
|
|
|
func ToGqlUsers(users []string) []*model.User {
|
|
result := make([]*model.User, len(users))
|
|
for i, u := range users {
|
|
result[i] = &model.User{ID: u}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func ToGqlAPIKeys(keys []domain.APIKey) []*model.APIKey {
|
|
result := make([]*model.APIKey, len(keys))
|
|
for i, k := range keys {
|
|
result[i] = &model.APIKey{
|
|
ID: apiKeyId(k.OrganizationId, k.Name),
|
|
Name: k.Name,
|
|
Key: nil, // Never return the hashed key - only return plaintext on creation
|
|
Organization: nil,
|
|
Refs: k.Refs,
|
|
Read: k.Read,
|
|
Publish: k.Publish,
|
|
}
|
|
}
|
|
return result
|
|
}
|