diff --git a/api/projects/integration_alias.go b/api/projects/integration_alias.go index ab1c2ba6..5fc83835 100644 --- a/api/projects/integration_alias.go +++ b/api/projects/integration_alias.go @@ -4,11 +4,11 @@ import ( "net/http" "strings" + "github.com/gorilla/context" "github.com/semaphoreui/semaphore/api/helpers" "github.com/semaphoreui/semaphore/db" "github.com/semaphoreui/semaphore/pkg/random" "github.com/semaphoreui/semaphore/util" - "github.com/gorilla/context" ) type publicAlias struct { @@ -16,19 +16,23 @@ type publicAlias struct { URL string `json:"url"` } -func getPublicAlias(alias db.IntegrationAlias) publicAlias { - +func getPublicAliasURL(scope string, alias string) string { aliasURL := util.Config.WebHost if !strings.HasSuffix(aliasURL, "/") { aliasURL += "/" } - aliasURL += "api/integrations/" + alias.Alias + aliasURL += "api/" + scope + "/" + alias + + return aliasURL +} + +func getPublicAlias(alias db.IntegrationAlias) publicAlias { return publicAlias{ ID: alias.ID, - URL: aliasURL, + URL: getPublicAliasURL("integrations", alias.Alias), } } diff --git a/db/bolt/terraform_inventory.go b/db/bolt/terraform_inventory.go new file mode 100644 index 00000000..8a769f5b --- /dev/null +++ b/db/bolt/terraform_inventory.go @@ -0,0 +1,66 @@ +package bolt + +import ( + "github.com/semaphoreui/semaphore/db" +) + +func (d *BoltDb) CreateTerraformInventoryAlias(alias db.TerraformInventoryAlias) (res db.TerraformInventoryAlias, err error) { + var newInv interface{} + newInv, err = d.createObject(alias.ProjectID, db.TerraformInventoryAliasProps, alias) + if err != nil { + return + } + res = newInv.(db.TerraformInventoryAlias) + return +} + +func (d *BoltDb) UpdateTerraformInventoryAlias(alias db.TerraformInventoryAlias) (err error) { + + err = d.updateObject(alias.ProjectID, db.TemplateProps, alias) + + return +} + +func (d *BoltDb) GetTerraformInventoryAliasByAlias(alias string) (res db.TerraformInventoryAlias, err error) { + + err = d.getObject(-1, db.TerraformInventoryStateProps, strObjectID(alias), &res) + + return +} + +func (d *BoltDb) GetTerraformInventoryAlias(projectID, inventoryID int, alias string) (res db.TerraformInventoryAlias, err error) { + + al, err := d.GetTerraformInventoryAliasByAlias(alias) + + if err != nil { + return + } + + if al.ProjectID != projectID || al.InventoryID != inventoryID { + err = db.ErrNotFound + return + } + + return +} + +func (d *BoltDb) GetTerraformInventoryAliases(projectID, inventoryID int) (res []db.TerraformInventoryAlias, err error) { + err = d.getObjects(projectID, db.TerraformInventoryAliasProps, db.RetrieveQueryParams{}, func(i interface{}) bool { + alias := i.(db.TerraformInventoryAlias) + return alias.InventoryID == inventoryID + }, &res) + return +} + +func (d *BoltDb) DeleteTerraformInventoryAlias(projectID int, inventoryID int, alias string) (err error) { + err = d.deleteObject(projectID, db.TerraformInventoryAliasProps, strObjectID(alias), nil) + return +} + +func (d *BoltDb) GetTerraformInventoryStates(projectID, inventoryID int) (res []db.TerraformInventoryState, err error) { + err = d.getObjects(projectID, db.TerraformInventoryStateProps, db.RetrieveQueryParams{}, func(i interface{}) bool { + state := i.(db.TerraformInventoryState) + return state.InventoryID == inventoryID + }, &res) + return +}