mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 07:19:20 +01:00
refactor(api): extract function
Some checks are pending
Dev / build-local (push) Waiting to run
Dev / migrate-boltdb (push) Blocked by required conditions
Dev / migrate-mysql (push) Blocked by required conditions
Dev / migrate-mariadb (push) Blocked by required conditions
Dev / migrate-postgres (push) Blocked by required conditions
Dev / integrate-boltdb (push) Blocked by required conditions
Dev / integrate-mysql (push) Blocked by required conditions
Dev / integrate-mariadb (push) Blocked by required conditions
Dev / integrate-postgres (push) Blocked by required conditions
Dev / deploy-server (push) Blocked by required conditions
Dev / deploy-runner (push) Blocked by required conditions
Some checks are pending
Dev / build-local (push) Waiting to run
Dev / migrate-boltdb (push) Blocked by required conditions
Dev / migrate-mysql (push) Blocked by required conditions
Dev / migrate-mariadb (push) Blocked by required conditions
Dev / migrate-postgres (push) Blocked by required conditions
Dev / integrate-boltdb (push) Blocked by required conditions
Dev / integrate-mysql (push) Blocked by required conditions
Dev / integrate-mariadb (push) Blocked by required conditions
Dev / integrate-postgres (push) Blocked by required conditions
Dev / deploy-server (push) Blocked by required conditions
Dev / deploy-runner (push) Blocked by required conditions
This commit is contained in:
parent
645668dc76
commit
fe88aa371e
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
66
db/bolt/terraform_inventory.go
Normal file
66
db/bolt/terraform_inventory.go
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user