Skip to content

Commit

Permalink
Add Cidr table (#4319)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmcshane authored Feb 22, 2024
1 parent 4f9a0f1 commit b833691
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
27 changes: 27 additions & 0 deletions internal/models/ipam.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package models

import (
"net"

"github.com/google/uuid"
"gorm.io/gorm"
)

// Ipam represents an entry in the Ipam table
type Ipam struct {
gorm.Model

// ID is a UUID for the APIContract
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`

// ProjectID is the ID of the project that the config belongs to.
// This should be a foreign key, but GORM doesnt play well with FKs.
ProjectID int `json:"project_id"`

CIDR net.IPNet `gorm:"type:cidr;column:cidr_range"`
}

// TableName overrides the table name
func (Ipam) TableName() string {
return "ipam"
}
16 changes: 16 additions & 0 deletions internal/repository/gorm/ipam.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package gorm

import (
"github.com/porter-dev/porter/internal/repository"
"gorm.io/gorm"
)

// Ipam uses gorm.DB for querying the database
type Ipam struct {
db *gorm.DB
}

// NewIpamRepository creates an IPAM connection
func NewIpamRepository(db *gorm.DB) repository.IpamRepository {
return &Ipam{db}
}
1 change: 1 addition & 0 deletions internal/repository/gorm/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ func AutoMigrate(db *gorm.DB, debug bool) error {
&ints.GithubAppInstallation{},
&ints.GithubAppOAuthIntegration{},
&ints.SlackIntegration{},
&models.Ipam{},
)
}
7 changes: 7 additions & 0 deletions internal/repository/gorm/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type GormRepository struct {
githubWebhook repository.GithubWebhookRepository
datastore repository.DatastoreRepository
appInstance repository.AppInstanceRepository
ipam repository.IpamRepository
}

func (t *GormRepository) User() repository.UserRepository {
Expand Down Expand Up @@ -275,6 +276,11 @@ func (t *GormRepository) AppInstance() repository.AppInstanceRepository {
return t.appInstance
}

// Ipam returns the IpamRepository interface implemented by gorm
func (t *GormRepository) Ipam() repository.IpamRepository {
return t.ipam
}

// NewRepository returns a Repository which persists users in memory
// and accepts a parameter that can trigger read/write errors
func NewRepository(db *gorm.DB, key *[32]byte, storageBackend credentials.CredentialStorage) repository.Repository {
Expand Down Expand Up @@ -331,5 +337,6 @@ func NewRepository(db *gorm.DB, key *[32]byte, storageBackend credentials.Creden
githubWebhook: NewGithubWebhookRepository(db),
datastore: NewDatastoreRepository(db),
appInstance: NewAppInstanceRepository(db),
ipam: NewIpamRepository(db),
}
}
4 changes: 4 additions & 0 deletions internal/repository/ipam.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package repository

// IpamRepository represents the set of queries on the Ipam model
type IpamRepository interface{}

0 comments on commit b833691

Please sign in to comment.