Skip to content

Commit

Permalink
remove comments
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene committed Feb 3, 2025
1 parent 4eaad65 commit a236485
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 33 deletions.
1 change: 0 additions & 1 deletion auth/postgres/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func Migration() *migrate.MemoryMigrationSource {
entity_ids TEXT[],
domains TEXT[],
entity_types TEXT[],
metadata TEXT
)`,
},
Down: []string{
Expand Down
32 changes: 0 additions & 32 deletions auth/postgres/pat.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ type dbPat struct {
EntityIDs []string `db:"entity_ids,omitempty"` // Combined list of all entity IDs
Domains []string `db:"domains,omitempty"` // List of all domain IDs
EntityTypes []string `db:"entity_types,omitempty"` // List of all entity types

// Metadata
Metadata string `db:"metadata,omitempty"` // JSON string for additional metadata
}

type dbAuthPage struct {
Expand All @@ -59,7 +56,6 @@ func toAuthPat(db dbPat) (auth.PAT, error) {
Scope: auth.Scope{Domains: make(map[string]auth.DomainScope)},
}

// Parse scopes data
var scopeData struct {
Users auth.OperationScope `json:"users,omitempty"`
Dashboard auth.OperationScope `json:"dashboard,omitempty"`
Expand All @@ -71,27 +67,16 @@ func toAuthPat(db dbPat) (auth.PAT, error) {
return auth.PAT{}, fmt.Errorf("failed to unmarshal scopes data: %w", err)
}

// Parse metadata if exists
var metadata map[string]interface{}
if db.Metadata != "" {
if err := json.Unmarshal([]byte(db.Metadata), &metadata); err != nil {
return auth.PAT{}, fmt.Errorf("failed to unmarshal metadata: %w", err)
}
}

// Set platform scopes
pat.Scope.Users = scopeData.Users
pat.Scope.Dashboard = scopeData.Dashboard
pat.Scope.Messaging = scopeData.Messaging

// Set domain scopes
for domainID, dsd := range scopeData.DomainScopes {
domainScope := auth.DomainScope{
DomainManagement: dsd.DomainManagement,
Entities: make(map[auth.DomainEntityType]auth.OperationScope),
}

// Process domain entity scopes
for entityTypeStr, ops := range dsd.Entities {
entityType, err := auth.ParseDomainEntityType(entityTypeStr)
if err != nil {
Expand All @@ -107,7 +92,6 @@ func toAuthPat(db dbPat) (auth.PAT, error) {
}

func patToDBRecords(pat auth.PAT) (dbPat, error) {
// Initialize scope data structure
scopeData := struct {
Users auth.OperationScope `json:"users,omitempty"`
Dashboard auth.OperationScope `json:"dashboard,omitempty"`
Expand All @@ -117,13 +101,11 @@ func patToDBRecords(pat auth.PAT) (dbPat, error) {
DomainScopes: make(map[string]DomainScopeData),
}

// Collect all operations and entity IDs
var allOps []string
var allEntityIDs []string
var allDomains []string
var allEntityTypes []string

// Process platform scopes
if len(pat.Scope.Users) > 0 {
scopeData.Users = pat.Scope.Users
ops, ids := extractOpsAndIDs(pat.Scope.Users)
Expand All @@ -148,7 +130,6 @@ func patToDBRecords(pat auth.PAT) (dbPat, error) {
allEntityTypes = append(allEntityTypes, "messaging")
}

// Process domain scopes
for domainID, domainScope := range pat.Scope.Domains {
dsd := DomainScopeData{
DomainManagement: domainScope.DomainManagement,
Expand Down Expand Up @@ -179,28 +160,16 @@ func patToDBRecords(pat auth.PAT) (dbPat, error) {
allDomains = append(allDomains, domainID)
}

// Remove duplicates
allOps = uniqueStrings(allOps)
allEntityIDs = uniqueStrings(allEntityIDs)
allDomains = uniqueStrings(allDomains)
allEntityTypes = uniqueStrings(allEntityTypes)

// Marshal scope data
scopesJSON, err := json.Marshal(scopeData)
if err != nil {
return dbPat{}, fmt.Errorf("failed to marshal scopes data: %w", err)
}

// Create metadata
metadata := map[string]interface{}{
"created_at": time.Now(),
"version": "1.0",
}
metadataJSON, err := json.Marshal(metadata)
if err != nil {
return dbPat{}, fmt.Errorf("failed to marshal metadata: %w", err)
}

return dbPat{
ID: pat.ID,
User: pat.User,
Expand All @@ -218,7 +187,6 @@ func patToDBRecords(pat auth.PAT) (dbPat, error) {
EntityIDs: allEntityIDs,
Domains: allDomains,
EntityTypes: allEntityTypes,
Metadata: string(metadataJSON),
}, nil
}

Expand Down

0 comments on commit a236485

Please sign in to comment.