Skip to content

Commit 9b2acc0

Browse files
authored
Merge pull request #256 from aquasecurity/SLK-66308-registry-prefixes-inconsistency
SLK-66308 - Add support to default_prefix
2 parents c47ac78 + f8bed5a commit 9b2acc0

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

aquasec/resource_registry.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,21 @@ func resourceRegistryRead(d *schema.ResourceData, m interface{}) error {
325325
return err
326326
}
327327

328+
// Check if default_prefix, and remove it for tf diff
329+
prefixes := r.Prefixes
330+
if r.DefaultPrefix != "" {
331+
// Find the index of r.DefaultPrefix
332+
var indexToRemove int
333+
for i, prefix := range prefixes {
334+
if prefix == r.DefaultPrefix {
335+
indexToRemove = i
336+
break
337+
}
338+
}
339+
// Remove the element by slicing the slice
340+
prefixes = append(prefixes[:indexToRemove], prefixes[indexToRemove+1:]...)
341+
}
342+
328343
if err = d.Set("auto_pull", r.AutoPull); err != nil {
329344
return err
330345
}
@@ -373,7 +388,7 @@ func resourceRegistryRead(d *schema.ResourceData, m interface{}) error {
373388
if err = d.Set("username", r.Username); err != nil {
374389
return err
375390
}
376-
if err = d.Set("prefixes", r.Prefixes); err != nil {
391+
if err = d.Set("prefixes", prefixes); err != nil {
377392
return err
378393
}
379394
if err = d.Set("advanced_settings_cleanup", r.AdvancedSettingsCleanup); err != nil {
@@ -419,6 +434,13 @@ func resourceRegistryUpdate(d *schema.ResourceData, m interface{}) error {
419434
if d.HasChanges("name", "registry_scan_timeout", "username", "description", "pull_image_tag_pattern", "password", "url", "type", "auto_pull", "auto_pull_rescan", "auto_pull_max", "advanced_settings_cleanup", "auto_pull_time", "auto_pull_interval", "auto_cleanup", "image_creation_date_condition", "scanner_name", "prefixes", "pull_image_count", "pull_image_age", "options", "webhook", "always_pull_patterns", "pull_repo_patterns_excluded") {
420435

421436
prefixes := d.Get("prefixes").([]interface{})
437+
var defaultPrefix string
438+
// Add default_prefix to prefixes
439+
r, _ := c.GetRegistry(d.Id())
440+
if r.DefaultPrefix != "" {
441+
prefixes = append(prefixes, r.DefaultPrefix)
442+
defaultPrefix = r.DefaultPrefix
443+
}
422444
always_pull_patterns := d.Get("always_pull_patterns").([]interface{})
423445
pull_repo_patterns_excluded := d.Get("pull_repo_patterns_excluded").([]interface{})
424446
pull_image_tag_pattern := d.Get("pull_image_tag_pattern").([]interface{})
@@ -454,6 +476,7 @@ func resourceRegistryUpdate(d *schema.ResourceData, m interface{}) error {
454476
ScannerNameRemoved: convertStringArr(scanner_name_removed),
455477
ExistingScanners: convertStringArr(existsing_scanners),
456478
Prefixes: convertStringArr(prefixes),
479+
DefaultPrefix: defaultPrefix,
457480
AlwaysPullPatterns: convertStringArr(always_pull_patterns),
458481
PullRepoPatternsExcluded: convertStringArr(pull_repo_patterns_excluded),
459482
PullImageTagPattern: convertStringArr(pull_image_tag_pattern),

client/registries.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Registry struct {
4141
ScannerNameRemoved []string `json:"scanner_name_removed,omitempty"`
4242
ExistingScanners []string `json:"existsing_scanners,omitempty"`
4343
Options []Options `json:"options"`
44+
DefaultPrefix string `json:"default_prefix"`
4445
//Architecture string `json:"architecture"`
4546
//ICRAccountId string `json:"icr_account_id"`
4647
//ACRConnectionType string `json:"acr_connection_type"`

0 commit comments

Comments
 (0)