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

This commit is contained in:
Denis Gukov 2024-12-15 02:01:02 +05:00
parent 645668dc76
commit fe88aa371e
No known key found for this signature in database
GPG Key ID: 044381366A5D4731
2 changed files with 75 additions and 5 deletions

View File

@ -4,11 +4,11 @@ import (
"net/http" "net/http"
"strings" "strings"
"github.com/gorilla/context"
"github.com/semaphoreui/semaphore/api/helpers" "github.com/semaphoreui/semaphore/api/helpers"
"github.com/semaphoreui/semaphore/db" "github.com/semaphoreui/semaphore/db"
"github.com/semaphoreui/semaphore/pkg/random" "github.com/semaphoreui/semaphore/pkg/random"
"github.com/semaphoreui/semaphore/util" "github.com/semaphoreui/semaphore/util"
"github.com/gorilla/context"
) )
type publicAlias struct { type publicAlias struct {
@ -16,19 +16,23 @@ type publicAlias struct {
URL string `json:"url"` URL string `json:"url"`
} }
func getPublicAlias(alias db.IntegrationAlias) publicAlias { func getPublicAliasURL(scope string, alias string) string {
aliasURL := util.Config.WebHost aliasURL := util.Config.WebHost
if !strings.HasSuffix(aliasURL, "/") { if !strings.HasSuffix(aliasURL, "/") {
aliasURL += "/" aliasURL += "/"
} }
aliasURL += "api/integrations/" + alias.Alias aliasURL += "api/" + scope + "/" + alias
return aliasURL
}
func getPublicAlias(alias db.IntegrationAlias) publicAlias {
return publicAlias{ return publicAlias{
ID: alias.ID, ID: alias.ID,
URL: aliasURL, URL: getPublicAliasURL("integrations", alias.Alias),
} }
} }

View 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
}