15 Commits

Author SHA1 Message Date
Lourenço Vales
ad86804f56 small typos 2025-10-05 23:14:25 +02:00
Lourenço Vales
0784060d05 final fixes 2025-10-05 23:14:25 +02:00
Lourenço Vales
2591c7468d small typo 2025-10-05 23:14:25 +02:00
Lourenço Vales
7d2c20a579 changed validation for MX record corner case 2025-10-05 23:14:25 +02:00
Lourenço Vales
472cb18060 added more robust validation; small changes 2025-10-05 23:14:25 +02:00
Lourenço Vales
3d721f4688 fixed slight error in validation 2025-10-05 23:14:25 +02:00
Lourenço Vales
8fff0f5d24 adding doc comments 2025-10-05 23:14:25 +02:00
Lourenço Vales
9e45a08704 fixed record deletion by changing the matching condition 2025-10-05 23:14:25 +02:00
Lourenço Vales
5cf369d2a8 adding Poll condition to guarantee minimum time between tries 2025-10-05 23:14:25 +02:00
Lourenço Vales
bce129c9eb everything is implemented, now on to testing 2025-10-05 23:14:25 +02:00
Lourenço Vales
70da562ceb added partial cloudflare api integration 2025-10-05 23:14:25 +02:00
Lourenço Vales
c6dc388427 added cmp function 2025-10-05 23:14:25 +02:00
Lourenço Vales
17c8153c1e added CheckApply function; made some changes to structure 2025-10-05 23:14:25 +02:00
Lourenço Vales
62ecbf633d engine: resources: Add Cloudflare DNS resource 2025-10-05 23:14:25 +02:00
James Shubin
06f54e5628 engine: resources: Virt builder needs HOME sometimes
Seems this is new or got pulled in automatically somehow. This fixes:

virt-builder: error: ssh-inject: $HOME environment variable is not set
2025-10-03 17:16:35 -04:00
2 changed files with 26 additions and 14 deletions

View File

@@ -51,10 +51,10 @@ func init() {
// CloudflareDNSRes is a resource for managing DNS records in Cloudflare zones.
// This resource uses the Cloudflare API to create, update, and delete DNS
// records in a specified zone. It supports various record types including A,
// AAAA, CNAME, MX, TXT, NS, and PTR records. The resource requires polling
// to detect changes, as the Cloudflare API does not provide an event stream.
// The Purge functionality allows enforcing that only managed DNS records exist
// in the zone, removing any unmanaged records.
// AAAA, CNAME, MX, TXT, NS, and PTR records. The resource requires polling to
// detect changes, as the Cloudflare API does not provide an event stream. The
// Purge functionality allows enforcing that only managed DNS records exist in
// the zone, removing any unmanaged records.
type CloudflareDNSRes struct {
traits.Base
traits.GraphQueryable
@@ -130,7 +130,7 @@ func (obj *CloudflareDNSRes) Validate() error {
}
if obj.APIToken == "" {
return fmt.Errorf("API token is required")
return fmt.Errorf("api token is required")
}
if obj.Type == "" {
@@ -138,7 +138,7 @@ func (obj *CloudflareDNSRes) Validate() error {
}
if (obj.TTL < 60 || obj.TTL > 86400) && obj.TTL != 1 { // API requirement
return fmt.Errorf("TTL must be between 60s and 86400s, or set to 1")
return fmt.Errorf("ttl must be between 60s and 86400s, or set to 1")
}
if obj.Zone == "" {
@@ -578,7 +578,7 @@ func (obj *CloudflareDNSRes) needsUpdate(record dns.RecordResponse) bool {
return true
}
// TODO add more checks?
//TODO: add more checks?
return false
@@ -679,16 +679,18 @@ func (obj *CloudflareDNSRes) GraphQueryAllowed(opts ...engine.GraphQueryableOpti
return nil
}
// matchesRecordName checks if a record name from the API matches our desired record name.
// Handles both FQDN (www.example.com) and short form (www) comparisons.
// matchesRecordName checks if a record name from the API matches our desired
// record name. Handles both FQDN (www.example.com) and short form (www)
// comparisons.
func (obj *CloudflareDNSRes) matchesRecordName(apiRecordName string) bool {
desired := obj.normalizeRecordName(obj.RecordName)
actual := obj.normalizeRecordName(apiRecordName)
return desired == actual
}
// normalizeRecordName converts a record name to a consistent format for comparison.
// Converts to FQDN format (e.g., "www" -> "www.example.com", "@" -> "example.com")
// normalizeRecordName converts a record name to a consistent format for
// comparison. Converts to FQDN format (e.g., "www" -> "www.example.com", "@" ->
// "example.com")
func (obj *CloudflareDNSRes) normalizeRecordName(name string) string {
if name == "@" || name == obj.Zone {
return obj.Zone

View File

@@ -36,6 +36,7 @@ import (
"net/url"
"os"
"os/exec"
"os/user"
"path"
"path/filepath"
"runtime"
@@ -621,6 +622,15 @@ func (obj *VirtBuilderRes) CheckApply(ctx context.Context, apply bool) (bool, er
cmd := exec.CommandContext(ctx, cmdName, cmdArgs...)
usr, err := user.Current()
if err != nil {
return false, err
}
// FIXME: consider building this from an empty environment?
cmd.Env = append(os.Environ(),
fmt.Sprintf("HOME=%s", usr.HomeDir),
)
// ignore signals sent to parent process (we're in our own group)
cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
@@ -638,7 +648,7 @@ func (obj *VirtBuilderRes) CheckApply(ctx context.Context, apply bool) (bool, er
return false, errwrap.Wrapf(err, "error starting cmd")
}
err := cmd.Wait() // we can unblock this with the timeout
cmderr := cmd.Wait() // we can unblock this with the timeout
out := b.String()
p := path.Join(obj.varDir, fmt.Sprintf("%d.log", start))
@@ -648,7 +658,7 @@ func (obj *VirtBuilderRes) CheckApply(ctx context.Context, apply bool) (bool, er
}
}
if err == nil {
if cmderr == nil {
obj.init.Logf("built image successfully!")
return false, nil // success!
}
@@ -667,7 +677,7 @@ func (obj *VirtBuilderRes) CheckApply(ctx context.Context, apply bool) (bool, er
obj.init.Logf("deleted partial output")
}
exitErr, ok := err.(*exec.ExitError) // embeds an os.ProcessState
exitErr, ok := cmderr.(*exec.ExitError) // embeds an os.ProcessState
if !ok {
// command failed in some bad way
return false, errwrap.Wrapf(err, "cmd failed in some bad way")