|
1 | 1 | package aquasec |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "log" |
5 | 6 |
|
6 | 7 | "github.com/aquasecurity/terraform-provider-aquasec/client" |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" |
7 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
8 | 10 | ) |
9 | 11 |
|
10 | 12 | func dataSourceRegistry() *schema.Resource { |
11 | 13 | return &schema.Resource{ |
12 | | - Read: dataRegistryRead, |
| 14 | + ReadContext: dataRegistryRead, |
13 | 15 | Schema: map[string]*schema.Schema{ |
14 | 16 | "username": { |
15 | 17 | Type: schema.TypeString, |
@@ -193,11 +195,167 @@ func dataSourceRegistry() *schema.Resource { |
193 | 195 | Type: schema.TypeString, |
194 | 196 | }, |
195 | 197 | }, |
| 198 | + "auto_scan_time": { |
| 199 | + Type: schema.TypeSet, |
| 200 | + Description: "When enabled, registry events are sent to the given Aqua webhook url", |
| 201 | + Optional: true, |
| 202 | + Computed: true, |
| 203 | + Elem: &schema.Resource{ |
| 204 | + Schema: map[string]*schema.Schema{ |
| 205 | + "auto_pull_day": { |
| 206 | + Type: schema.TypeInt, |
| 207 | + Description: "The day for auto pull", |
| 208 | + Optional: true, |
| 209 | + Computed: true, |
| 210 | + }, |
| 211 | + "iteration": { |
| 212 | + Type: schema.TypeInt, |
| 213 | + Description: "Number of iterations", |
| 214 | + Optional: true, |
| 215 | + Computed: true, |
| 216 | + }, |
| 217 | + "iteration_type": { |
| 218 | + Type: schema.TypeString, |
| 219 | + Description: "The type of iteration (day, week, month, year)", |
| 220 | + Optional: true, |
| 221 | + Computed: true, |
| 222 | + }, |
| 223 | + "time": { |
| 224 | + Type: schema.TypeString, |
| 225 | + Description: "the time for auto pull", |
| 226 | + Optional: true, |
| 227 | + Computed: true, |
| 228 | + }, |
| 229 | + "week_days": { |
| 230 | + Type: schema.TypeList, |
| 231 | + Description: "The days of week for auto pull", |
| 232 | + Optional: true, |
| 233 | + Elem: &schema.Schema{ |
| 234 | + Type: schema.TypeString, |
| 235 | + }, |
| 236 | + }, |
| 237 | + }, |
| 238 | + }, |
| 239 | + }, |
| 240 | + "detected_type": { |
| 241 | + Type: schema.TypeInt, |
| 242 | + Description: "The detected type of the registry", |
| 243 | + Computed: true, |
| 244 | + }, |
| 245 | + "force_save": { |
| 246 | + Type: schema.TypeBool, |
| 247 | + Description: "Whether to force save the registry even if the test connection fails", |
| 248 | + Optional: true, |
| 249 | + Default: false, |
| 250 | + }, |
| 251 | + "force_ootb": { |
| 252 | + Type: schema.TypeBool, |
| 253 | + Description: "To identify and ignore supersonic client calls initiated from OOTB", |
| 254 | + Optional: true, |
| 255 | + Default: false, |
| 256 | + }, |
| 257 | + "image_s3_prefixes": { |
| 258 | + Type: schema.TypeList, |
| 259 | + Description: "The S3 prefixes for images", |
| 260 | + Optional: true, |
| 261 | + Elem: &schema.Schema{ |
| 262 | + Type: schema.TypeString, |
| 263 | + }, |
| 264 | + }, |
| 265 | + "is_registry_connected": { |
| 266 | + Type: schema.TypeBool, |
| 267 | + Description: "Whether the registry is connected", |
| 268 | + Computed: true, |
| 269 | + }, |
| 270 | + "permission": { |
| 271 | + Type: schema.TypeString, |
| 272 | + Description: "Permission action", |
| 273 | + Optional: true, |
| 274 | + }, |
| 275 | + "pull_max_tags": { |
| 276 | + Type: schema.TypeInt, |
| 277 | + Description: "The maximum number of tags for auto pull", |
| 278 | + Optional: true, |
| 279 | + }, |
| 280 | + "pull_tags_pattern": { |
| 281 | + Type: schema.TypeList, |
| 282 | + Description: "Patterns for tags to be pulled from auto pull", |
| 283 | + Optional: true, |
| 284 | + Elem: &schema.Schema{ |
| 285 | + Type: schema.TypeString, |
| 286 | + }, |
| 287 | + }, |
| 288 | + "pull_repo_patterns": { |
| 289 | + Type: schema.TypeList, |
| 290 | + Description: "Patterns for repositories to be pulled from auto pull", |
| 291 | + Optional: true, |
| 292 | + Elem: &schema.Schema{ |
| 293 | + Type: schema.TypeString, |
| 294 | + }, |
| 295 | + }, |
| 296 | + "registries_type": { |
| 297 | + Type: schema.TypeString, |
| 298 | + Description: "The type of registries", |
| 299 | + Computed: true, |
| 300 | + }, |
| 301 | + "auto_pull_latest_xff_enabled": { |
| 302 | + Type: schema.TypeBool, |
| 303 | + Description: "Auto pull latest xff enabled", |
| 304 | + Optional: true, |
| 305 | + }, |
| 306 | + "is_architecture_system_default": { |
| 307 | + Type: schema.TypeBool, |
| 308 | + Description: "Whether the architecture is the system default", |
| 309 | + Optional: true, |
| 310 | + }, |
| 311 | + "client_cert": { |
| 312 | + Type: schema.TypeString, |
| 313 | + Description: "The client certificate for the registry", |
| 314 | + Optional: true, |
| 315 | + }, |
| 316 | + "client_key": { |
| 317 | + Type: schema.TypeString, |
| 318 | + Description: "The client key for the registry", |
| 319 | + Optional: true, |
| 320 | + }, |
| 321 | + "auto_pull_in_progress": { |
| 322 | + Type: schema.TypeBool, |
| 323 | + Description: "Whether auto pull is in progress", |
| 324 | + Computed: true, |
| 325 | + }, |
| 326 | + "auto_pull_processed_page_number": { |
| 327 | + Type: schema.TypeInt, |
| 328 | + Description: "The page number processed for auto pull", |
| 329 | + Computed: true, |
| 330 | + }, |
| 331 | + "architecture": { |
| 332 | + Type: schema.TypeString, |
| 333 | + Description: "The architecture of the registry", |
| 334 | + Optional: true, |
| 335 | + }, |
| 336 | + "cloud_resources": { |
| 337 | + Type: schema.TypeList, |
| 338 | + Description: "The cloud resource of the registry", |
| 339 | + Optional: true, |
| 340 | + Elem: &schema.Schema{ |
| 341 | + Type: schema.TypeString, |
| 342 | + }, |
| 343 | + }, |
| 344 | + "error_msg": { |
| 345 | + Type: schema.TypeString, |
| 346 | + Description: "The error message of the registry", |
| 347 | + Optional: true, |
| 348 | + }, |
| 349 | + "nexus_mtts_ff_enabled": { |
| 350 | + Type: schema.TypeBool, |
| 351 | + Description: "Enable mutual TLS for Sonatype Nexus Repository", |
| 352 | + Optional: true, |
| 353 | + }, |
196 | 354 | }, |
197 | 355 | } |
198 | 356 | } |
199 | 357 |
|
200 | | -func dataRegistryRead(d *schema.ResourceData, m interface{}) error { |
| 358 | +func dataRegistryRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { |
201 | 359 | log.Println("[DEBUG] inside dataRegistryRead") |
202 | 360 | ac := m.(*client.Client) |
203 | 361 | name := d.Get("name").(string) |
@@ -231,10 +389,29 @@ func dataRegistryRead(d *schema.ResourceData, m interface{}) error { |
231 | 389 | if scannerType == "specific" { |
232 | 390 | d.Set("scanner_name", convertStringArr(scanner_name)) |
233 | 391 | } |
234 | | - |
| 392 | + d.Set("is_architecture_system_default", reg.IsArchitectureSystemDefault) |
| 393 | + d.Set("client_cert", reg.ClientCert) |
| 394 | + d.Set("client_key", reg.ClientKey) |
| 395 | + d.Set("auto_pull_in_progress", reg.AutoPullInProgress) |
| 396 | + d.Set("auto_pull_processed_page_number", reg.AutoPullProcessedPageNumber) |
| 397 | + d.Set("architecture", reg.Architecture) |
| 398 | + d.Set("error_msg", reg.ErrorMsg) |
| 399 | + d.Set("nexus_mtts_ff_enabled", reg.NexusMttsFfEnabled) |
| 400 | + d.Set("force_save", reg.ForceSave) |
| 401 | + d.Set("force_ootb", reg.ForceOotb) |
| 402 | + d.Set("is_registry_connected", reg.IsRegistryConnected) |
| 403 | + d.Set("permission", reg.Permission) |
| 404 | + d.Set("pull_max_tags", reg.PullMaxTags) |
| 405 | + d.Set("registries_type", reg.RegistriesType) |
| 406 | + d.Set("detected_type", reg.DetectedType) |
| 407 | + d.Set("auto_pull_latest_xff_enabled", reg.AutoPullLatestXffEnabled) |
| 408 | + d.Set("image_s3_prefixes", reg.ImageS3Prefixes) |
| 409 | + d.Set("cloud_resources", reg.CloudResources) |
| 410 | + d.Set("pull_repo_patterns", reg.PullRepoPatterns) |
| 411 | + d.Set("pull_tags_pattern", reg.PullTagsPattern) |
235 | 412 | d.SetId(name) |
236 | 413 | } else { |
237 | | - return err |
| 414 | + return diag.FromErr(err) |
238 | 415 | } |
239 | 416 |
|
240 | 417 | return nil |
|
0 commit comments