From f77d2b53a27eb2aa33bc48873cc4e7624b1c8ada Mon Sep 17 00:00:00 2001 From: hc-github-team-tf-azure <> Date: Tue, 29 Oct 2024 10:43:31 +0000 Subject: [PATCH] Updating based on f87ca5fe6 --- .../2023-11-01-preview/archives/README.md | 103 +++ .../2023-11-01-preview/archives/client.go | 26 + .../2023-11-01-preview/archives/constants.go | 101 +++ .../2023-11-01-preview/archives/id_archive.go | 148 +++ .../archives/id_archive_test.go | 372 ++++++++ .../2023-11-01-preview/archives/id_package.go | 139 +++ .../archives/id_package_test.go | 327 +++++++ .../archives/method_create.go | 75 ++ .../archives/method_delete.go | 70 ++ .../2023-11-01-preview/archives/method_get.go | 53 ++ .../archives/method_list.go | 105 +++ .../archives/method_update.go | 57 ++ .../archives/model_archive.go | 16 + .../model_archivepackagesourceproperties.go | 9 + .../archives/model_archiveproperties.go | 12 + .../archives/model_archiveupdateparameters.go | 8 + .../archives/model_archiveupdateproperties.go | 8 + .../2023-11-01-preview/archives/predicates.go | 27 + .../2023-11-01-preview/archives/version.go | 10 + .../archiveversions/README.md | 77 ++ .../archiveversions/client.go | 26 + .../archiveversions/constants.go | 63 ++ .../archiveversions/id_archive.go | 148 +++ .../archiveversions/id_archive_test.go | 372 ++++++++ .../archiveversions/id_version.go | 157 ++++ .../archiveversions/id_version_test.go | 417 +++++++++ .../archiveversions/method_create.go | 71 ++ .../archiveversions/method_delete.go | 70 ++ .../archiveversions/method_get.go | 53 ++ .../archiveversions/method_list.go | 105 +++ .../archiveversions/model_archiveversion.go | 16 + .../model_archiveversionproperties.go | 9 + .../archiveversions/predicates.go | 27 + .../archiveversions/version.go | 10 + .../2023-11-01-preview/cacherules/README.md | 99 ++ .../2023-11-01-preview/cacherules/client.go | 26 + .../cacherules/constants.go | 63 ++ .../cacherules/id_cacherule.go | 139 +++ .../cacherules/id_cacherule_test.go | 327 +++++++ .../cacherules/id_registry.go | 130 +++ .../cacherules/id_registry_test.go | 282 ++++++ .../cacherules/method_create.go | 75 ++ .../cacherules/method_delete.go | 70 ++ .../cacherules/method_get.go | 53 ++ .../cacherules/method_list.go | 105 +++ .../cacherules/method_update.go | 75 ++ .../cacherules/model_cacherule.go | 16 + .../cacherules/model_cacheruleproperties.go | 30 + .../model_cacheruleupdateparameters.go | 8 + .../model_cacheruleupdateproperties.go | 8 + .../cacherules/predicates.go | 27 + .../2023-11-01-preview/cacherules/version.go | 10 + .../2023-11-01-preview/client.go | 154 ++++ .../connectedregistries/README.md | 111 +++ .../connectedregistries/client.go | 26 + .../connectedregistries/constants.go | 368 ++++++++ .../id_connectedregistry.go | 139 +++ .../id_connectedregistry_test.go | 327 +++++++ .../connectedregistries/id_registry.go | 130 +++ .../connectedregistries/id_registry_test.go | 282 ++++++ .../connectedregistries/method_create.go | 75 ++ .../connectedregistries/method_deactivate.go | 70 ++ .../connectedregistries/method_delete.go | 71 ++ .../connectedregistries/method_get.go | 53 ++ .../connectedregistries/method_list.go | 134 +++ .../connectedregistries/method_update.go | 75 ++ .../model_activationproperties.go | 8 + .../model_connectedregistry.go | 16 + .../model_connectedregistryproperties.go | 37 + ...model_connectedregistryupdateparameters.go | 8 + ...model_connectedregistryupdateproperties.go | 11 + .../model_loggingproperties.go | 9 + .../model_loginserverproperties.go | 9 + .../model_parentproperties.go | 9 + .../model_statusdetailproperties.go | 30 + .../model_syncproperties.go | 31 + .../model_syncupdateproperties.go | 10 + .../model_tlscertificateproperties.go | 9 + .../model_tlsproperties.go | 9 + .../connectedregistries/predicates.go | 27 + .../connectedregistries/version.go | 10 + .../credentialsets/README.md | 99 ++ .../credentialsets/client.go | 26 + .../credentialsets/constants.go | 142 +++ .../credentialsets/id_credentialset.go | 139 +++ .../credentialsets/id_credentialset_test.go | 327 +++++++ .../credentialsets/id_registry.go | 130 +++ .../credentialsets/id_registry_test.go | 282 ++++++ .../credentialsets/method_create.go | 75 ++ .../credentialsets/method_delete.go | 70 ++ .../credentialsets/method_get.go | 53 ++ .../credentialsets/method_list.go | 105 +++ .../credentialsets/method_update.go | 75 ++ .../credentialsets/model_authcredential.go | 11 + .../credentialsets/model_credentialhealth.go | 10 + .../credentialsets/model_credentialset.go | 18 + .../model_credentialsetproperties.go | 29 + .../model_credentialsetupdateparameters.go | 13 + .../model_credentialsetupdateproperties.go | 8 + .../credentialsets/predicates.go | 27 + .../credentialsets/version.go | 10 + .../exportpipelines/README.md | 82 ++ .../exportpipelines/client.go | 26 + .../exportpipelines/constants.go | 110 +++ .../exportpipelines/id_exportpipeline.go | 139 +++ .../exportpipelines/id_exportpipeline_test.go | 327 +++++++ .../exportpipelines/id_registry.go | 130 +++ .../exportpipelines/id_registry_test.go | 282 ++++++ .../exportpipelines/method_create.go | 75 ++ .../exportpipelines/method_delete.go | 71 ++ .../exportpipelines/method_get.go | 53 ++ .../exportpipelines/method_list.go | 105 +++ .../exportpipelines/model_exportpipeline.go | 19 + .../model_exportpipelineproperties.go | 10 + .../model_exportpipelinetargetproperties.go | 10 + .../exportpipelines/predicates.go | 32 + .../exportpipelines/version.go | 10 + .../importpipelines/README.md | 82 ++ .../importpipelines/client.go | 26 + .../importpipelines/constants.go | 189 ++++ .../importpipelines/id_importpipeline.go | 139 +++ .../importpipelines/id_importpipeline_test.go | 327 +++++++ .../importpipelines/id_registry.go | 130 +++ .../importpipelines/id_registry_test.go | 282 ++++++ .../importpipelines/method_create.go | 75 ++ .../importpipelines/method_delete.go | 71 ++ .../importpipelines/method_get.go | 53 ++ .../importpipelines/method_list.go | 105 +++ .../importpipelines/model_importpipeline.go | 19 + .../model_importpipelineproperties.go | 11 + .../model_importpipelinesourceproperties.go | 10 + .../model_pipelinesourcetriggerproperties.go | 8 + .../model_pipelinetriggerproperties.go | 8 + .../importpipelines/predicates.go | 32 + .../importpipelines/version.go | 10 + .../2023-11-01-preview/operation/README.md | 42 + .../2023-11-01-preview/operation/client.go | 26 + .../2023-11-01-preview/operation/constants.go | 48 + .../method_registrieschecknameavailability.go | 59 ++ .../model_registrynamecheckrequest.go | 9 + .../operation/model_registrynamestatus.go | 10 + .../2023-11-01-preview/operation/version.go | 10 + .../2023-11-01-preview/pipelineruns/README.md | 82 ++ .../2023-11-01-preview/pipelineruns/client.go | 26 + .../pipelineruns/constants.go | 177 ++++ .../pipelineruns/id_pipelinerun.go | 139 +++ .../pipelineruns/id_pipelinerun_test.go | 327 +++++++ .../pipelineruns/id_registry.go | 130 +++ .../pipelineruns/id_registry_test.go | 282 ++++++ .../pipelineruns/method_create.go | 75 ++ .../pipelineruns/method_delete.go | 71 ++ .../pipelineruns/method_get.go | 53 ++ .../pipelineruns/method_list.go | 105 +++ .../model_exportpipelinetargetproperties.go | 10 + .../model_importpipelinesourceproperties.go | 10 + .../pipelineruns/model_pipelinerun.go | 16 + .../model_pipelinerunproperties.go | 11 + .../pipelineruns/model_pipelinerunrequest.go | 12 + .../pipelineruns/model_pipelinerunresponse.go | 47 + .../model_pipelinerunsourceproperties.go | 9 + .../model_pipelineruntargetproperties.go | 9 + .../model_pipelinesourcetriggerdescriptor.go | 26 + .../model_pipelinetriggerdescriptor.go | 8 + .../pipelineruns/model_progressproperties.go | 8 + .../pipelineruns/predicates.go | 27 + .../pipelineruns/version.go | 10 + .../privateendpointconnections/README.md | 82 ++ .../privateendpointconnections/client.go | 26 + .../privateendpointconnections/constants.go | 151 ++++ .../id_privateendpointconnection.go | 139 +++ .../id_privateendpointconnection_test.go | 327 +++++++ .../privateendpointconnections/id_registry.go | 130 +++ .../id_registry_test.go | 282 ++++++ .../method_createorupdate.go | 75 ++ .../method_delete.go | 71 ++ .../privateendpointconnections/method_get.go | 53 ++ .../privateendpointconnections/method_list.go | 105 +++ .../model_privateendpoint.go | 8 + .../model_privateendpointconnection.go | 16 + ...del_privateendpointconnectionproperties.go | 10 + ...model_privatelinkserviceconnectionstate.go | 10 + .../privateendpointconnections/predicates.go | 27 + .../privateendpointconnections/version.go | 10 + .../2023-11-01-preview/registries/README.md | 237 +++++ .../2023-11-01-preview/registries/client.go | 26 + .../registries/constants.go | 854 ++++++++++++++++++ .../registries/id_privatelinkresource.go | 139 +++ .../registries/id_privatelinkresource_test.go | 327 +++++++ .../registries/id_registry.go | 130 +++ .../registries/id_registry_test.go | 282 ++++++ .../registries/method_create.go | 75 ++ .../registries/method_delete.go | 71 ++ .../registries/method_generatecredentials.go | 75 ++ .../registries/method_get.go | 53 ++ .../method_getprivatelinkresource.go | 53 ++ .../registries/method_importimage.go | 74 ++ .../registries/method_list.go | 106 +++ .../registries/method_listbyresourcegroup.go | 106 +++ .../registries/method_listcredentials.go | 54 ++ .../method_listprivatelinkresources.go | 105 +++ .../registries/method_listusages.go | 54 ++ .../registries/method_regeneratecredential.go | 58 ++ .../registries/method_update.go | 75 ++ .../model_azureadauthenticationasarmpolicy.go | 8 + .../registries/model_encryptionproperty.go | 9 + .../registries/model_exportpolicy.go | 8 + .../model_generatecredentialsparameters.go | 28 + .../model_generatecredentialsresult.go | 9 + .../registries/model_importimageparameters.go | 11 + .../registries/model_importsource.go | 11 + .../model_importsourcecredentials.go | 9 + .../registries/model_iprule.go | 9 + .../registries/model_keyvaultproperties.go | 30 + .../registries/model_networkruleset.go | 9 + .../registries/model_policies.go | 13 + .../registries/model_privateendpoint.go | 8 + .../model_privateendpointconnection.go | 16 + ...del_privateendpointconnectionproperties.go | 10 + .../registries/model_privatelinkresource.go | 11 + .../model_privatelinkresourceproperties.go | 10 + ...model_privatelinkserviceconnectionstate.go | 10 + .../registries/model_quarantinepolicy.go | 8 + .../model_regeneratecredentialparameters.go | 8 + .../registries/model_registry.go | 21 + .../model_registrylistcredentialsresult.go | 9 + .../registries/model_registrypassword.go | 9 + .../registries/model_registryproperties.go | 41 + ...odel_registrypropertiesupdateparameters.go | 16 + .../model_registryupdateparameters.go | 15 + .../registries/model_registryusage.go | 11 + .../model_registryusagelistresult.go | 8 + .../registries/model_retentionpolicy.go | 28 + .../registries/model_sku.go | 9 + .../registries/model_softdeletepolicy.go | 28 + .../registries/model_status.go | 28 + .../registries/model_tokenpassword.go | 41 + .../registries/model_trustpolicy.go | 9 + .../registries/predicates.go | 55 ++ .../2023-11-01-preview/registries/version.go | 10 + .../2023-11-01-preview/replications/README.md | 99 ++ .../2023-11-01-preview/replications/client.go | 26 + .../replications/constants.go | 104 +++ .../replications/id_registry.go | 130 +++ .../replications/id_registry_test.go | 282 ++++++ .../replications/id_replication.go | 139 +++ .../replications/id_replication_test.go | 327 +++++++ .../replications/method_create.go | 75 ++ .../replications/method_delete.go | 71 ++ .../replications/method_get.go | 53 ++ .../replications/method_list.go | 105 +++ .../replications/method_update.go | 75 ++ .../replications/model_replication.go | 18 + .../model_replicationproperties.go | 11 + .../model_replicationupdateparameters.go | 9 + ...l_replicationupdateparametersproperties.go | 8 + .../replications/model_status.go | 28 + .../replications/predicates.go | 32 + .../replications/version.go | 10 + .../2023-11-01-preview/scopemaps/README.md | 99 ++ .../2023-11-01-preview/scopemaps/client.go | 26 + .../2023-11-01-preview/scopemaps/constants.go | 63 ++ .../scopemaps/id_registry.go | 130 +++ .../scopemaps/id_registry_test.go | 282 ++++++ .../scopemaps/id_scopemap.go | 139 +++ .../scopemaps/id_scopemap_test.go | 327 +++++++ .../scopemaps/method_create.go | 75 ++ .../scopemaps/method_delete.go | 71 ++ .../scopemaps/method_get.go | 53 ++ .../scopemaps/method_list.go | 105 +++ .../scopemaps/method_update.go | 75 ++ .../scopemaps/model_scopemap.go | 16 + .../scopemaps/model_scopemapproperties.go | 30 + ...odel_scopemappropertiesupdateparameters.go | 9 + .../model_scopemapupdateparameters.go | 8 + .../scopemaps/predicates.go | 27 + .../2023-11-01-preview/scopemaps/version.go | 10 + .../2023-11-01-preview/tokens/README.md | 99 ++ .../2023-11-01-preview/tokens/client.go | 26 + .../2023-11-01-preview/tokens/constants.go | 186 ++++ .../2023-11-01-preview/tokens/id_registry.go | 130 +++ .../tokens/id_registry_test.go | 282 ++++++ .../2023-11-01-preview/tokens/id_token.go | 139 +++ .../tokens/id_token_test.go | 327 +++++++ .../tokens/method_create.go | 75 ++ .../tokens/method_delete.go | 71 ++ .../2023-11-01-preview/tokens/method_get.go | 53 ++ .../2023-11-01-preview/tokens/method_list.go | 105 +++ .../tokens/method_update.go | 75 ++ .../2023-11-01-preview/tokens/model_token.go | 16 + .../tokens/model_tokencertificate.go | 29 + .../model_tokencredentialsproperties.go | 9 + .../tokens/model_tokenpassword.go | 41 + .../tokens/model_tokenproperties.go | 30 + .../tokens/model_tokenupdateparameters.go | 8 + .../tokens/model_tokenupdateproperties.go | 10 + .../2023-11-01-preview/tokens/predicates.go | 27 + .../2023-11-01-preview/tokens/version.go | 10 + .../2023-11-01-preview/webhooks/README.md | 148 +++ .../2023-11-01-preview/webhooks/client.go | 26 + .../2023-11-01-preview/webhooks/constants.go | 154 ++++ .../webhooks/id_registry.go | 130 +++ .../webhooks/id_registry_test.go | 282 ++++++ .../2023-11-01-preview/webhooks/id_webhook.go | 139 +++ .../webhooks/id_webhook_test.go | 327 +++++++ .../webhooks/method_create.go | 75 ++ .../webhooks/method_delete.go | 71 ++ .../2023-11-01-preview/webhooks/method_get.go | 53 ++ .../webhooks/method_getcallbackconfig.go | 54 ++ .../webhooks/method_list.go | 105 +++ .../webhooks/method_listevents.go | 105 +++ .../webhooks/method_ping.go | 54 ++ .../webhooks/method_update.go | 75 ++ .../webhooks/model_actor.go | 8 + .../webhooks/model_callbackconfig.go | 9 + .../webhooks/model_event.go | 10 + .../webhooks/model_eventcontent.go | 32 + .../webhooks/model_eventinfo.go | 8 + .../webhooks/model_eventrequestmessage.go | 12 + .../webhooks/model_eventresponsemessage.go | 12 + .../webhooks/model_request.go | 12 + .../webhooks/model_source.go | 9 + .../webhooks/model_target.go | 16 + .../webhooks/model_webhook.go | 18 + .../webhooks/model_webhookcreateparameters.go | 10 + .../webhooks/model_webhookproperties.go | 11 + ...model_webhookpropertiescreateparameters.go | 12 + ...model_webhookpropertiesupdateparameters.go | 12 + .../webhooks/model_webhookupdateparameters.go | 9 + .../2023-11-01-preview/webhooks/predicates.go | 45 + .../2023-11-01-preview/webhooks/version.go | 10 + .../model_replicationobject.go | 2 +- .../volumegroups/model_replicationobject.go | 2 +- .../volumes/model_replicationobject.go | 2 +- .../redisenterprise/2024-10-01/client.go | 55 ++ .../2024-10-01/databases/README.md | 217 +++++ .../2024-10-01/databases/client.go | 26 + .../2024-10-01/databases/constants.go | 457 ++++++++++ .../2024-10-01/databases/id_database.go | 139 +++ .../2024-10-01/databases/id_database_test.go | 327 +++++++ .../databases/id_redisenterprise.go | 130 +++ .../databases/id_redisenterprise_test.go | 282 ++++++ .../2024-10-01/databases/method_create.go | 75 ++ .../2024-10-01/databases/method_delete.go | 71 ++ .../2024-10-01/databases/method_export.go | 74 ++ .../2024-10-01/databases/method_flush.go | 74 ++ .../method_forcelinktoreplicationgroup.go | 73 ++ .../databases/method_forceunlink.go | 74 ++ .../2024-10-01/databases/method_get.go | 53 ++ .../2024-10-01/databases/method_import.go | 74 ++ .../databases/method_listbycluster.go | 105 +++ .../2024-10-01/databases/method_listkeys.go | 54 ++ .../databases/method_regeneratekey.go | 75 ++ .../2024-10-01/databases/method_update.go | 75 ++ .../2024-10-01/databases/model_accesskeys.go | 9 + .../2024-10-01/databases/model_database.go | 11 + .../databases/model_databaseproperties.go | 16 + .../model_databasepropertiesgeoreplication.go | 9 + .../databases/model_databaseupdate.go | 8 + .../model_exportclusterparameters.go | 8 + .../databases/model_flushparameters.go | 8 + .../databases/model_forcelinkparameters.go | 9 + .../databases/model_forceunlinkparameters.go | 8 + .../model_importclusterparameters.go | 8 + .../databases/model_linkeddatabase.go | 9 + .../2024-10-01/databases/model_module.go | 10 + .../2024-10-01/databases/model_persistence.go | 11 + .../model_regeneratekeyparameters.go | 8 + .../2024-10-01/databases/predicates.go | 27 + .../2024-10-01/databases/version.go | 10 + .../privateendpointconnections/README.md | 81 ++ .../privateendpointconnections/client.go | 26 + .../privateendpointconnections/constants.go | 101 +++ .../id_privateendpointconnection.go | 139 +++ .../id_privateendpointconnection_test.go | 327 +++++++ .../id_redisenterprise.go | 130 +++ .../id_redisenterprise_test.go | 282 ++++++ .../method_delete.go | 71 ++ .../privateendpointconnections/method_get.go | 53 ++ .../privateendpointconnections/method_list.go | 54 ++ .../privateendpointconnections/method_put.go | 74 ++ .../model_privateendpoint.go | 8 + .../model_privateendpointconnection.go | 11 + ...del_privateendpointconnectionlistresult.go | 8 + ...del_privateendpointconnectionproperties.go | 10 + ...model_privatelinkserviceconnectionstate.go | 10 + .../privateendpointconnections/version.go | 10 + .../2024-10-01/privatelinkresources/README.md | 36 + .../2024-10-01/privatelinkresources/client.go | 26 + .../id_redisenterprise.go | 130 +++ .../id_redisenterprise_test.go | 282 ++++++ .../method_listbycluster.go | 54 ++ .../model_privatelinkresource.go | 11 + .../model_privatelinkresourcelistresult.go | 8 + .../model_privatelinkresourceproperties.go | 10 + .../privatelinkresources/version.go | 10 + .../2024-10-01/redisenterprise/README.md | 314 +++++++ .../2024-10-01/redisenterprise/client.go | 26 + .../2024-10-01/redisenterprise/constants.go | 701 ++++++++++++++ .../2024-10-01/redisenterprise/id_database.go | 139 +++ .../redisenterprise/id_database_test.go | 327 +++++++ .../redisenterprise/id_redisenterprise.go | 130 +++ .../id_redisenterprise_test.go | 282 ++++++ .../redisenterprise/method_create.go | 75 ++ .../redisenterprise/method_databasescreate.go | 75 ++ .../redisenterprise/method_databasesdelete.go | 71 ++ .../redisenterprise/method_databasesexport.go | 74 ++ .../redisenterprise/method_databasesflush.go | 74 ++ ...od_databasesforcelinktoreplicationgroup.go | 73 ++ .../method_databasesforceunlink.go | 74 ++ .../redisenterprise/method_databasesget.go | 53 ++ .../redisenterprise/method_databasesimport.go | 74 ++ .../method_databaseslistbycluster.go | 105 +++ .../method_databaseslistkeys.go | 54 ++ .../method_databasesregeneratekey.go | 75 ++ .../redisenterprise/method_databasesupdate.go | 75 ++ .../redisenterprise/method_delete.go | 71 ++ .../2024-10-01/redisenterprise/method_get.go | 53 ++ .../2024-10-01/redisenterprise/method_list.go | 106 +++ .../method_listbyresourcegroup.go | 106 +++ .../redisenterprise/method_update.go | 75 ++ .../redisenterprise/model_accesskeys.go | 9 + .../redisenterprise/model_cluster.go | 21 + .../model_clusterproperties.go | 14 + .../model_clusterpropertiesencryption.go | 8 + ...sencryptioncustomermanagedkeyencryption.go | 9 + ...edkeyencryptionkeyencryptionkeyidentity.go | 9 + .../redisenterprise/model_clusterupdate.go | 15 + .../redisenterprise/model_database.go | 11 + .../model_databaseproperties.go | 16 + .../model_databasepropertiesgeoreplication.go | 9 + .../redisenterprise/model_databaseupdate.go | 8 + .../model_exportclusterparameters.go | 8 + .../redisenterprise/model_flushparameters.go | 8 + .../model_forcelinkparameters.go | 9 + .../model_forceunlinkparameters.go | 8 + .../model_importclusterparameters.go | 8 + .../redisenterprise/model_linkeddatabase.go | 9 + .../redisenterprise/model_module.go | 10 + .../redisenterprise/model_persistence.go | 11 + .../redisenterprise/model_privateendpoint.go | 8 + .../model_privateendpointconnection.go | 11 + ...del_privateendpointconnectionproperties.go | 10 + ...model_privatelinkserviceconnectionstate.go | 10 + .../model_regeneratekeyparameters.go | 8 + .../2024-10-01/redisenterprise/model_sku.go | 9 + .../2024-10-01/redisenterprise/predicates.go | 55 ++ .../2024-10-01/redisenterprise/version.go | 10 + .../standbypool/2024-03-01/client.go | 64 ++ .../README.md | 53 ++ .../client.go | 26 + .../constants.go | 57 ++ .../id_runtimeview.go | 139 +++ .../id_runtimeview_test.go | 327 +++++++ .../id_standbycontainergrouppool.go | 130 +++ .../id_standbycontainergrouppool_test.go | 282 ++++++ .../method_get.go | 53 ++ .../method_listbystandbypool.go | 105 +++ ...odel_containergroupinstancecountsummary.go | 8 + .../model_poolresourcestatecount.go | 9 + ...bycontainergrouppoolruntimeviewresource.go | 16 + ...rgrouppoolruntimeviewresourceproperties.go | 9 + .../predicates.go | 27 + .../version.go | 10 + .../standbycontainergrouppools/README.md | 121 +++ .../standbycontainergrouppools/client.go | 26 + .../standbycontainergrouppools/constants.go | 95 ++ .../id_standbycontainergrouppool.go | 130 +++ .../id_standbycontainergrouppool_test.go | 282 ++++++ .../method_createorupdate.go | 75 ++ .../method_delete.go | 70 ++ .../standbycontainergrouppools/method_get.go | 53 ++ .../method_listbyresourcegroup.go | 106 +++ .../method_listbysubscription.go | 106 +++ .../method_update.go | 57 ++ .../model_containergroupprofile.go | 9 + .../model_containergroupproperties.go | 9 + ...ndbycontainergrouppoolelasticityprofile.go | 9 + ...model_standbycontainergrouppoolresource.go | 18 + ...dbycontainergrouppoolresourceproperties.go | 10 + ...standbycontainergrouppoolresourceupdate.go | 9 + ...tainergrouppoolresourceupdateproperties.go | 9 + .../model_subnet.go | 8 + .../standbycontainergrouppools/predicates.go | 32 + .../standbycontainergrouppools/version.go | 10 + .../README.md | 53 ++ .../client.go | 26 + .../constants.go | 57 ++ .../id_standbyvirtualmachinepool.go | 130 +++ .../id_standbyvirtualmachinepool_test.go | 282 ++++++ ...id_standbyvirtualmachinepoolruntimeview.go | 139 +++ ...andbyvirtualmachinepoolruntimeview_test.go | 327 +++++++ .../method_get.go | 53 ++ .../method_listbystandbypool.go | 105 +++ .../model_poolresourcestatecount.go | 9 + ...byvirtualmachinepoolruntimeviewresource.go | 16 + ...achinepoolruntimeviewresourceproperties.go | 9 + ...odel_virtualmachineinstancecountsummary.go | 9 + .../predicates.go | 27 + .../version.go | 10 + .../standbyvirtualmachinepools/README.md | 121 +++ .../standbyvirtualmachinepools/client.go | 26 + .../standbyvirtualmachinepools/constants.go | 98 ++ .../id_standbyvirtualmachinepool.go | 130 +++ .../id_standbyvirtualmachinepool_test.go | 282 ++++++ .../method_createorupdate.go | 75 ++ .../method_delete.go | 70 ++ .../standbyvirtualmachinepools/method_get.go | 53 ++ .../method_listbyresourcegroup.go | 106 +++ .../method_listbysubscription.go | 106 +++ .../method_update.go | 57 ++ ...ndbyvirtualmachinepoolelasticityprofile.go | 9 + ...model_standbyvirtualmachinepoolresource.go | 18 + ...dbyvirtualmachinepoolresourceproperties.go | 11 + ...standbyvirtualmachinepoolresourceupdate.go | 9 + ...tualmachinepoolresourceupdateproperties.go | 10 + .../standbyvirtualmachinepools/predicates.go | 32 + .../standbyvirtualmachinepools/version.go | 10 + .../standbyvirtualmachines/README.md | 53 ++ .../standbyvirtualmachines/client.go | 26 + .../standbyvirtualmachines/constants.go | 57 ++ .../id_standbyvirtualmachine.go | 139 +++ .../id_standbyvirtualmachine_test.go | 327 +++++++ .../id_standbyvirtualmachinepool.go | 130 +++ .../id_standbyvirtualmachinepool_test.go | 282 ++++++ .../standbyvirtualmachines/method_get.go | 53 ++ ...listbystandbyvirtualmachinepoolresource.go | 105 +++ .../model_standbyvirtualmachineresource.go | 16 + ...standbyvirtualmachineresourceproperties.go | 9 + .../standbyvirtualmachines/predicates.go | 27 + .../standbyvirtualmachines/version.go | 10 + 530 files changed, 40171 insertions(+), 3 deletions(-) create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/id_archive.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/id_archive_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/id_package.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/id_package_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/method_create.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/method_update.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/model_archive.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/model_archivepackagesourceproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/model_archiveproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/model_archiveupdateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/model_archiveupdateproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archives/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_archive.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_archive_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_version_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_create.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/model_archiveversion.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/model_archiveversionproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/archiveversions/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/id_cacherule.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/id_cacherule_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/id_registry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/id_registry_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/method_create.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/method_update.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacherule.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacheruleproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacheruleupdateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacheruleupdateproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/cacherules/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_connectedregistry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_connectedregistry_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_registry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_registry_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_create.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_deactivate.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_update.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_activationproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistryproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistryupdateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistryupdateproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_loggingproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_loginserverproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_parentproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_statusdetailproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_syncproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_syncupdateproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_tlscertificateproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_tlsproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/connectedregistries/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_credentialset.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_credentialset_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_registry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_registry_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_create.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_update.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_authcredential.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialhealth.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialset.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialsetproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialsetupdateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialsetupdateproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/credentialsets/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_exportpipeline.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_exportpipeline_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_registry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_registry_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_create.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/model_exportpipeline.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/model_exportpipelineproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/model_exportpipelinetargetproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/exportpipelines/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_importpipeline.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_importpipeline_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_registry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_registry_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_create.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_importpipeline.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_importpipelineproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_importpipelinesourceproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_pipelinesourcetriggerproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_pipelinetriggerproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/importpipelines/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/operation/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/operation/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/operation/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/operation/method_registrieschecknameavailability.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/operation/model_registrynamecheckrequest.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/operation/model_registrynamestatus.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/operation/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_pipelinerun.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_pipelinerun_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_registry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_registry_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_create.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_exportpipelinetargetproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_importpipelinesourceproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerun.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunrequest.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunresponse.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunsourceproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelineruntargetproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinesourcetriggerdescriptor.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinetriggerdescriptor.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_progressproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/pipelineruns/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_privateendpointconnection.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_privateendpointconnection_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_registry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_registry_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_createorupdate.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privateendpoint.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privateendpointconnection.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/id_privatelinkresource.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/id_privatelinkresource_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/id_registry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/id_registry_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/method_create.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/method_generatecredentials.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/method_getprivatelinkresource.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/method_importimage.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/method_listbyresourcegroup.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/method_listcredentials.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/method_listprivatelinkresources.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/method_listusages.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/method_regeneratecredential.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/method_update.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_azureadauthenticationasarmpolicy.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_encryptionproperty.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_exportpolicy.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_generatecredentialsparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_generatecredentialsresult.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_importimageparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_importsource.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_importsourcecredentials.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_iprule.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_keyvaultproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_networkruleset.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_policies.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_privateendpoint.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_privateendpointconnection.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_privatelinkresource.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_privatelinkresourceproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_quarantinepolicy.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_regeneratecredentialparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_registry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_registrylistcredentialsresult.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_registrypassword.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_registryproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_registrypropertiesupdateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_registryupdateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_registryusage.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_registryusagelistresult.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_retentionpolicy.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_sku.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_softdeletepolicy.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_status.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_tokenpassword.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/model_trustpolicy.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/registries/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/id_registry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/id_registry_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/id_replication.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/id_replication_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/method_create.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/method_update.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/model_replication.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/model_replicationproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/model_replicationupdateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/model_replicationupdateparametersproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/model_status.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/replications/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_registry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_registry_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_scopemap.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_scopemap_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_create.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_update.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemap.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemapproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemappropertiesupdateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemapupdateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/scopemaps/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/id_registry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/id_registry_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/id_token.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/id_token_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/method_create.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/method_update.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/model_token.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokencertificate.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokencredentialsproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenpassword.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenupdateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenupdateproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/tokens/version.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/README.md create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/client.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/constants.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/id_registry.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/id_registry_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/id_webhook.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/id_webhook_test.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/method_create.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/method_delete.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/method_get.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/method_getcallbackconfig.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/method_list.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/method_listevents.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/method_ping.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/method_update.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_actor.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_callbackconfig.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_event.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventcontent.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventinfo.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventrequestmessage.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventresponsemessage.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_request.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_source.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_target.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhook.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookcreateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookproperties.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookpropertiescreateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookpropertiesupdateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookupdateparameters.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/predicates.go create mode 100644 resource-manager/containerregistry/2023-11-01-preview/webhooks/version.go create mode 100644 resource-manager/redisenterprise/2024-10-01/client.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/README.md create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/client.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/constants.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/id_database.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/id_database_test.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/id_redisenterprise.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/id_redisenterprise_test.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/method_create.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/method_delete.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/method_export.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/method_flush.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/method_forcelinktoreplicationgroup.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/method_forceunlink.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/method_get.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/method_import.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/method_listbycluster.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/method_listkeys.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/method_regeneratekey.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/method_update.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_accesskeys.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_database.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_databaseproperties.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_databasepropertiesgeoreplication.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_databaseupdate.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_exportclusterparameters.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_flushparameters.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_forcelinkparameters.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_forceunlinkparameters.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_importclusterparameters.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_linkeddatabase.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_module.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_persistence.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/model_regeneratekeyparameters.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/predicates.go create mode 100644 resource-manager/redisenterprise/2024-10-01/databases/version.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/README.md create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/client.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/constants.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_privateendpointconnection.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_privateendpointconnection_test.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_redisenterprise.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_redisenterprise_test.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_delete.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_get.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_list.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_put.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpoint.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpointconnection.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpointconnectionlistresult.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privateendpointconnections/version.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privatelinkresources/README.md create mode 100644 resource-manager/redisenterprise/2024-10-01/privatelinkresources/client.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privatelinkresources/id_redisenterprise.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privatelinkresources/id_redisenterprise_test.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privatelinkresources/method_listbycluster.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privatelinkresources/model_privatelinkresource.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privatelinkresources/model_privatelinkresourcelistresult.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privatelinkresources/model_privatelinkresourceproperties.go create mode 100644 resource-manager/redisenterprise/2024-10-01/privatelinkresources/version.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/README.md create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/client.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/constants.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/id_database.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/id_database_test.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/id_redisenterprise.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/id_redisenterprise_test.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_create.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasescreate.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesdelete.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesexport.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesflush.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesforcelinktoreplicationgroup.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesforceunlink.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesget.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesimport.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databaseslistbycluster.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databaseslistkeys.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesregeneratekey.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesupdate.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_delete.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_get.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_list.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_listbyresourcegroup.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/method_update.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_accesskeys.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_cluster.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterproperties.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterpropertiesencryption.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryption.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryptionkeyencryptionkeyidentity.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterupdate.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_database.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_databaseproperties.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_databasepropertiesgeoreplication.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_databaseupdate.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_exportclusterparameters.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_flushparameters.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forcelinkparameters.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forceunlinkparameters.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_importclusterparameters.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_linkeddatabase.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_module.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_persistence.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privateendpoint.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privateendpointconnection.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_regeneratekeyparameters.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/model_sku.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/predicates.go create mode 100644 resource-manager/redisenterprise/2024-10-01/redisenterprise/version.go create mode 100644 resource-manager/standbypool/2024-03-01/client.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/README.md create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/client.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/constants.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_runtimeview.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_runtimeview_test.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_standbycontainergrouppool.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_standbycontainergrouppool_test.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/method_get.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/method_listbystandbypool.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_containergroupinstancecountsummary.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_poolresourcestatecount.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_standbycontainergrouppoolruntimeviewresource.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_standbycontainergrouppoolruntimeviewresourceproperties.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/predicates.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/version.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/README.md create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/client.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/constants.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/id_standbycontainergrouppool.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/id_standbycontainergrouppool_test.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_createorupdate.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_delete.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_get.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_listbyresourcegroup.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_listbysubscription.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_update.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_containergroupprofile.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_containergroupproperties.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolelasticityprofile.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresource.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresourceproperties.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresourceupdate.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresourceupdateproperties.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_subnet.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/predicates.go create mode 100644 resource-manager/standbypool/2024-03-01/standbycontainergrouppools/version.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/README.md create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/client.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/constants.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepool.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepool_test.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepoolruntimeview.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepoolruntimeview_test.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/method_get.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/method_listbystandbypool.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_poolresourcestatecount.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_standbyvirtualmachinepoolruntimeviewresource.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_standbyvirtualmachinepoolruntimeviewresourceproperties.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_virtualmachineinstancecountsummary.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/predicates.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/version.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/README.md create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/client.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/constants.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/id_standbyvirtualmachinepool.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/id_standbyvirtualmachinepool_test.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_createorupdate.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_delete.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_get.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbyresourcegroup.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbysubscription.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_update.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolelasticityprofile.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresource.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceproperties.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdate.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdateproperties.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/predicates.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/version.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachines/README.md create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachines/client.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachines/constants.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachine.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachine_test.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachinepool.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachinepool_test.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachines/method_get.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachines/method_listbystandbyvirtualmachinepoolresource.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachines/model_standbyvirtualmachineresource.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachines/model_standbyvirtualmachineresourceproperties.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachines/predicates.go create mode 100644 resource-manager/standbypool/2024-03-01/standbyvirtualmachines/version.go diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/README.md b/resource-manager/containerregistry/2023-11-01-preview/archives/README.md new file mode 100644 index 00000000000..1e7ba3ee601 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/README.md @@ -0,0 +1,103 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/archives` Documentation + +The `archives` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/archives" +``` + + +### Client Initialization + +```go +client := archives.NewArchivesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ArchivesClient.Create` + +```go +ctx := context.TODO() +id := archives.NewArchiveID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName") + +payload := archives.Archive{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ArchivesClient.Delete` + +```go +ctx := context.TODO() +id := archives.NewArchiveID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ArchivesClient.Get` + +```go +ctx := context.TODO() +id := archives.NewArchiveID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ArchivesClient.List` + +```go +ctx := context.TODO() +id := archives.NewPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ArchivesClient.Update` + +```go +ctx := context.TODO() +id := archives.NewArchiveID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName") + +payload := archives.ArchiveUpdateParameters{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/client.go b/resource-manager/containerregistry/2023-11-01-preview/archives/client.go new file mode 100644 index 00000000000..76210037207 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/client.go @@ -0,0 +1,26 @@ +package archives + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArchivesClient struct { + Client *resourcemanager.Client +} + +func NewArchivesClientWithBaseURI(sdkApi sdkEnv.Api) (*ArchivesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "archives", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ArchivesClient: %+v", err) + } + + return &ArchivesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/constants.go b/resource-manager/containerregistry/2023-11-01-preview/archives/constants.go new file mode 100644 index 00000000000..07712b1dbd8 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/constants.go @@ -0,0 +1,101 @@ +package archives + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PackageSourceType string + +const ( + PackageSourceTypeRemote PackageSourceType = "remote" +) + +func PossibleValuesForPackageSourceType() []string { + return []string{ + string(PackageSourceTypeRemote), + } +} + +func (s *PackageSourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePackageSourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePackageSourceType(input string) (*PackageSourceType, error) { + vals := map[string]PackageSourceType{ + "remote": PackageSourceTypeRemote, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PackageSourceType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/id_archive.go b/resource-manager/containerregistry/2023-11-01-preview/archives/id_archive.go new file mode 100644 index 00000000000..2dc3873d7c7 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/id_archive.go @@ -0,0 +1,148 @@ +package archives + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ArchiveId{}) +} + +var _ resourceids.ResourceId = &ArchiveId{} + +// ArchiveId is a struct representing the Resource ID for a Archive +type ArchiveId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + PackageName string + ArchiveName string +} + +// NewArchiveID returns a new ArchiveId struct +func NewArchiveID(subscriptionId string, resourceGroupName string, registryName string, packageName string, archiveName string) ArchiveId { + return ArchiveId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + PackageName: packageName, + ArchiveName: archiveName, + } +} + +// ParseArchiveID parses 'input' into a ArchiveId +func ParseArchiveID(input string) (*ArchiveId, error) { + parser := resourceids.NewParserFromResourceIdType(&ArchiveId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ArchiveId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseArchiveIDInsensitively parses 'input' case-insensitively into a ArchiveId +// note: this method should only be used for API response data and not user input +func ParseArchiveIDInsensitively(input string) (*ArchiveId, error) { + parser := resourceids.NewParserFromResourceIdType(&ArchiveId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ArchiveId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ArchiveId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.PackageName, ok = input.Parsed["packageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "packageName", input) + } + + if id.ArchiveName, ok = input.Parsed["archiveName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "archiveName", input) + } + + return nil +} + +// ValidateArchiveID checks that 'input' can be parsed as a Archive ID +func ValidateArchiveID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseArchiveID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Archive ID +func (id ArchiveId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/packages/%s/archives/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.PackageName, id.ArchiveName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Archive ID +func (id ArchiveId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticPackages", "packages", "packages"), + resourceids.UserSpecifiedSegment("packageName", "packageName"), + resourceids.StaticSegment("staticArchives", "archives", "archives"), + resourceids.UserSpecifiedSegment("archiveName", "archiveName"), + } +} + +// String returns a human-readable description of this Archive ID +func (id ArchiveId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Package Name: %q", id.PackageName), + fmt.Sprintf("Archive Name: %q", id.ArchiveName), + } + return fmt.Sprintf("Archive (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/id_archive_test.go b/resource-manager/containerregistry/2023-11-01-preview/archives/id_archive_test.go new file mode 100644 index 00000000000..c7703d27d5f --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/id_archive_test.go @@ -0,0 +1,372 @@ +package archives + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ArchiveId{} + +func TestNewArchiveID(t *testing.T) { + id := NewArchiveID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.PackageName != "packageName" { + t.Fatalf("Expected %q but got %q for Segment 'PackageName'", id.PackageName, "packageName") + } + + if id.ArchiveName != "archiveName" { + t.Fatalf("Expected %q but got %q for Segment 'ArchiveName'", id.ArchiveName, "archiveName") + } +} + +func TestFormatArchiveID(t *testing.T) { + actual := NewArchiveID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseArchiveID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ArchiveId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName", + Expected: &ArchiveId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PackageName: "packageName", + ArchiveName: "archiveName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseArchiveID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PackageName != v.Expected.PackageName { + t.Fatalf("Expected %q but got %q for PackageName", v.Expected.PackageName, actual.PackageName) + } + + if actual.ArchiveName != v.Expected.ArchiveName { + t.Fatalf("Expected %q but got %q for ArchiveName", v.Expected.ArchiveName, actual.ArchiveName) + } + + } +} + +func TestParseArchiveIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ArchiveId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe/aRcHiVeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName", + Expected: &ArchiveId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PackageName: "packageName", + ArchiveName: "archiveName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe/aRcHiVeS/aRcHiVeNaMe", + Expected: &ArchiveId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + PackageName: "pAcKaGeNaMe", + ArchiveName: "aRcHiVeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe/aRcHiVeS/aRcHiVeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseArchiveIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PackageName != v.Expected.PackageName { + t.Fatalf("Expected %q but got %q for PackageName", v.Expected.PackageName, actual.PackageName) + } + + if actual.ArchiveName != v.Expected.ArchiveName { + t.Fatalf("Expected %q but got %q for ArchiveName", v.Expected.ArchiveName, actual.ArchiveName) + } + + } +} + +func TestSegmentsForArchiveId(t *testing.T) { + segments := ArchiveId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ArchiveId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/id_package.go b/resource-manager/containerregistry/2023-11-01-preview/archives/id_package.go new file mode 100644 index 00000000000..2d30274ba2d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/id_package.go @@ -0,0 +1,139 @@ +package archives + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PackageId{}) +} + +var _ resourceids.ResourceId = &PackageId{} + +// PackageId is a struct representing the Resource ID for a Package +type PackageId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + PackageName string +} + +// NewPackageID returns a new PackageId struct +func NewPackageID(subscriptionId string, resourceGroupName string, registryName string, packageName string) PackageId { + return PackageId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + PackageName: packageName, + } +} + +// ParsePackageID parses 'input' into a PackageId +func ParsePackageID(input string) (*PackageId, error) { + parser := resourceids.NewParserFromResourceIdType(&PackageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PackageId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePackageIDInsensitively parses 'input' case-insensitively into a PackageId +// note: this method should only be used for API response data and not user input +func ParsePackageIDInsensitively(input string) (*PackageId, error) { + parser := resourceids.NewParserFromResourceIdType(&PackageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PackageId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PackageId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.PackageName, ok = input.Parsed["packageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "packageName", input) + } + + return nil +} + +// ValidatePackageID checks that 'input' can be parsed as a Package ID +func ValidatePackageID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePackageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Package ID +func (id PackageId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/packages/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.PackageName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Package ID +func (id PackageId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticPackages", "packages", "packages"), + resourceids.UserSpecifiedSegment("packageName", "packageName"), + } +} + +// String returns a human-readable description of this Package ID +func (id PackageId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Package Name: %q", id.PackageName), + } + return fmt.Sprintf("Package (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/id_package_test.go b/resource-manager/containerregistry/2023-11-01-preview/archives/id_package_test.go new file mode 100644 index 00000000000..c7b12669d2e --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/id_package_test.go @@ -0,0 +1,327 @@ +package archives + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PackageId{} + +func TestNewPackageID(t *testing.T) { + id := NewPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.PackageName != "packageName" { + t.Fatalf("Expected %q but got %q for Segment 'PackageName'", id.PackageName, "packageName") + } +} + +func TestFormatPackageID(t *testing.T) { + actual := NewPackageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePackageID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PackageId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName", + Expected: &PackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PackageName: "packageName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePackageID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PackageName != v.Expected.PackageName { + t.Fatalf("Expected %q but got %q for PackageName", v.Expected.PackageName, actual.PackageName) + } + + } +} + +func TestParsePackageIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PackageId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName", + Expected: &PackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PackageName: "packageName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe", + Expected: &PackageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + PackageName: "pAcKaGeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePackageIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PackageName != v.Expected.PackageName { + t.Fatalf("Expected %q but got %q for PackageName", v.Expected.PackageName, actual.PackageName) + } + + } +} + +func TestSegmentsForPackageId(t *testing.T) { + segments := PackageId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PackageId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/method_create.go b/resource-manager/containerregistry/2023-11-01-preview/archives/method_create.go new file mode 100644 index 00000000000..2b7749748f2 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/method_create.go @@ -0,0 +1,75 @@ +package archives + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Archive +} + +// Create ... +func (c ArchivesClient) Create(ctx context.Context, id ArchiveId, input Archive) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ArchivesClient) CreateThenPoll(ctx context.Context, id ArchiveId, input Archive) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/archives/method_delete.go new file mode 100644 index 00000000000..878c300f2f9 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/method_delete.go @@ -0,0 +1,70 @@ +package archives + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ArchivesClient) Delete(ctx context.Context, id ArchiveId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ArchivesClient) DeleteThenPoll(ctx context.Context, id ArchiveId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/archives/method_get.go new file mode 100644 index 00000000000..3d18cdfab3d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/method_get.go @@ -0,0 +1,53 @@ +package archives + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Archive +} + +// Get ... +func (c ArchivesClient) Get(ctx context.Context, id ArchiveId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Archive + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/archives/method_list.go new file mode 100644 index 00000000000..81b5f43645f --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/method_list.go @@ -0,0 +1,105 @@ +package archives + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Archive +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Archive +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ArchivesClient) List(ctx context.Context, id PackageId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/archives", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Archive `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ArchivesClient) ListComplete(ctx context.Context, id PackageId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ArchiveOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ArchivesClient) ListCompleteMatchingPredicate(ctx context.Context, id PackageId, predicate ArchiveOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Archive, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/method_update.go b/resource-manager/containerregistry/2023-11-01-preview/archives/method_update.go new file mode 100644 index 00000000000..3b32e4bd438 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/method_update.go @@ -0,0 +1,57 @@ +package archives + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Archive +} + +// Update ... +func (c ArchivesClient) Update(ctx context.Context, id ArchiveId, input ArchiveUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Archive + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/model_archive.go b/resource-manager/containerregistry/2023-11-01-preview/archives/model_archive.go new file mode 100644 index 00000000000..f58f170319e --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/model_archive.go @@ -0,0 +1,16 @@ +package archives + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Archive struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ArchiveProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/model_archivepackagesourceproperties.go b/resource-manager/containerregistry/2023-11-01-preview/archives/model_archivepackagesourceproperties.go new file mode 100644 index 00000000000..575d28f4af5 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/model_archivepackagesourceproperties.go @@ -0,0 +1,9 @@ +package archives + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArchivePackageSourceProperties struct { + Type *PackageSourceType `json:"type,omitempty"` + Url *string `json:"url,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/model_archiveproperties.go b/resource-manager/containerregistry/2023-11-01-preview/archives/model_archiveproperties.go new file mode 100644 index 00000000000..d6574aa3ba7 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/model_archiveproperties.go @@ -0,0 +1,12 @@ +package archives + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArchiveProperties struct { + PackageSource *ArchivePackageSourceProperties `json:"packageSource,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + PublishedVersion *string `json:"publishedVersion,omitempty"` + RepositoryEndpoint *string `json:"repositoryEndpoint,omitempty"` + RepositoryEndpointPrefix *string `json:"repositoryEndpointPrefix,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/model_archiveupdateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/archives/model_archiveupdateparameters.go new file mode 100644 index 00000000000..15a0e0ecc20 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/model_archiveupdateparameters.go @@ -0,0 +1,8 @@ +package archives + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArchiveUpdateParameters struct { + Properties *ArchiveUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/model_archiveupdateproperties.go b/resource-manager/containerregistry/2023-11-01-preview/archives/model_archiveupdateproperties.go new file mode 100644 index 00000000000..00a08e372cd --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/model_archiveupdateproperties.go @@ -0,0 +1,8 @@ +package archives + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArchiveUpdateProperties struct { + PublishedVersion *string `json:"publishedVersion,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/archives/predicates.go new file mode 100644 index 00000000000..8d09711e9c6 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/predicates.go @@ -0,0 +1,27 @@ +package archives + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArchiveOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ArchiveOperationPredicate) Matches(input Archive) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archives/version.go b/resource-manager/containerregistry/2023-11-01-preview/archives/version.go new file mode 100644 index 00000000000..a19b353cc06 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archives/version.go @@ -0,0 +1,10 @@ +package archives + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/archives/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/README.md b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/README.md new file mode 100644 index 00000000000..432df2b881a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/README.md @@ -0,0 +1,77 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/archiveversions` Documentation + +The `archiveversions` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/archiveversions" +``` + + +### Client Initialization + +```go +client := archiveversions.NewArchiveVersionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ArchiveVersionsClient.Create` + +```go +ctx := context.TODO() +id := archiveversions.NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName", "versionName") + +if err := client.CreateThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ArchiveVersionsClient.Delete` + +```go +ctx := context.TODO() +id := archiveversions.NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName", "versionName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ArchiveVersionsClient.Get` + +```go +ctx := context.TODO() +id := archiveversions.NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName", "versionName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ArchiveVersionsClient.List` + +```go +ctx := context.TODO() +id := archiveversions.NewArchiveID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/client.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/client.go new file mode 100644 index 00000000000..cef30b31ebd --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/client.go @@ -0,0 +1,26 @@ +package archiveversions + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArchiveVersionsClient struct { + Client *resourcemanager.Client +} + +func NewArchiveVersionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ArchiveVersionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "archiveversions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ArchiveVersionsClient: %+v", err) + } + + return &ArchiveVersionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/constants.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/constants.go new file mode 100644 index 00000000000..e1421e47468 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/constants.go @@ -0,0 +1,63 @@ +package archiveversions + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_archive.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_archive.go new file mode 100644 index 00000000000..d5c824e4c51 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_archive.go @@ -0,0 +1,148 @@ +package archiveversions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ArchiveId{}) +} + +var _ resourceids.ResourceId = &ArchiveId{} + +// ArchiveId is a struct representing the Resource ID for a Archive +type ArchiveId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + PackageName string + ArchiveName string +} + +// NewArchiveID returns a new ArchiveId struct +func NewArchiveID(subscriptionId string, resourceGroupName string, registryName string, packageName string, archiveName string) ArchiveId { + return ArchiveId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + PackageName: packageName, + ArchiveName: archiveName, + } +} + +// ParseArchiveID parses 'input' into a ArchiveId +func ParseArchiveID(input string) (*ArchiveId, error) { + parser := resourceids.NewParserFromResourceIdType(&ArchiveId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ArchiveId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseArchiveIDInsensitively parses 'input' case-insensitively into a ArchiveId +// note: this method should only be used for API response data and not user input +func ParseArchiveIDInsensitively(input string) (*ArchiveId, error) { + parser := resourceids.NewParserFromResourceIdType(&ArchiveId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ArchiveId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ArchiveId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.PackageName, ok = input.Parsed["packageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "packageName", input) + } + + if id.ArchiveName, ok = input.Parsed["archiveName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "archiveName", input) + } + + return nil +} + +// ValidateArchiveID checks that 'input' can be parsed as a Archive ID +func ValidateArchiveID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseArchiveID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Archive ID +func (id ArchiveId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/packages/%s/archives/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.PackageName, id.ArchiveName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Archive ID +func (id ArchiveId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticPackages", "packages", "packages"), + resourceids.UserSpecifiedSegment("packageName", "packageName"), + resourceids.StaticSegment("staticArchives", "archives", "archives"), + resourceids.UserSpecifiedSegment("archiveName", "archiveName"), + } +} + +// String returns a human-readable description of this Archive ID +func (id ArchiveId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Package Name: %q", id.PackageName), + fmt.Sprintf("Archive Name: %q", id.ArchiveName), + } + return fmt.Sprintf("Archive (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_archive_test.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_archive_test.go new file mode 100644 index 00000000000..0b0c4cc49be --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_archive_test.go @@ -0,0 +1,372 @@ +package archiveversions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ArchiveId{} + +func TestNewArchiveID(t *testing.T) { + id := NewArchiveID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.PackageName != "packageName" { + t.Fatalf("Expected %q but got %q for Segment 'PackageName'", id.PackageName, "packageName") + } + + if id.ArchiveName != "archiveName" { + t.Fatalf("Expected %q but got %q for Segment 'ArchiveName'", id.ArchiveName, "archiveName") + } +} + +func TestFormatArchiveID(t *testing.T) { + actual := NewArchiveID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseArchiveID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ArchiveId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName", + Expected: &ArchiveId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PackageName: "packageName", + ArchiveName: "archiveName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseArchiveID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PackageName != v.Expected.PackageName { + t.Fatalf("Expected %q but got %q for PackageName", v.Expected.PackageName, actual.PackageName) + } + + if actual.ArchiveName != v.Expected.ArchiveName { + t.Fatalf("Expected %q but got %q for ArchiveName", v.Expected.ArchiveName, actual.ArchiveName) + } + + } +} + +func TestParseArchiveIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ArchiveId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe/aRcHiVeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName", + Expected: &ArchiveId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PackageName: "packageName", + ArchiveName: "archiveName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe/aRcHiVeS/aRcHiVeNaMe", + Expected: &ArchiveId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + PackageName: "pAcKaGeNaMe", + ArchiveName: "aRcHiVeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe/aRcHiVeS/aRcHiVeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseArchiveIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PackageName != v.Expected.PackageName { + t.Fatalf("Expected %q but got %q for PackageName", v.Expected.PackageName, actual.PackageName) + } + + if actual.ArchiveName != v.Expected.ArchiveName { + t.Fatalf("Expected %q but got %q for ArchiveName", v.Expected.ArchiveName, actual.ArchiveName) + } + + } +} + +func TestSegmentsForArchiveId(t *testing.T) { + segments := ArchiveId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ArchiveId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_version.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_version.go new file mode 100644 index 00000000000..0d98b1e1192 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_version.go @@ -0,0 +1,157 @@ +package archiveversions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&VersionId{}) +} + +var _ resourceids.ResourceId = &VersionId{} + +// VersionId is a struct representing the Resource ID for a Version +type VersionId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + PackageName string + ArchiveName string + VersionName string +} + +// NewVersionID returns a new VersionId struct +func NewVersionID(subscriptionId string, resourceGroupName string, registryName string, packageName string, archiveName string, versionName string) VersionId { + return VersionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + PackageName: packageName, + ArchiveName: archiveName, + VersionName: versionName, + } +} + +// ParseVersionID parses 'input' into a VersionId +func ParseVersionID(input string) (*VersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&VersionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseVersionIDInsensitively parses 'input' case-insensitively into a VersionId +// note: this method should only be used for API response data and not user input +func ParseVersionIDInsensitively(input string) (*VersionId, error) { + parser := resourceids.NewParserFromResourceIdType(&VersionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := VersionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *VersionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.PackageName, ok = input.Parsed["packageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "packageName", input) + } + + if id.ArchiveName, ok = input.Parsed["archiveName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "archiveName", input) + } + + if id.VersionName, ok = input.Parsed["versionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "versionName", input) + } + + return nil +} + +// ValidateVersionID checks that 'input' can be parsed as a Version ID +func ValidateVersionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseVersionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Version ID +func (id VersionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/packages/%s/archives/%s/versions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.PackageName, id.ArchiveName, id.VersionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Version ID +func (id VersionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticPackages", "packages", "packages"), + resourceids.UserSpecifiedSegment("packageName", "packageName"), + resourceids.StaticSegment("staticArchives", "archives", "archives"), + resourceids.UserSpecifiedSegment("archiveName", "archiveName"), + resourceids.StaticSegment("staticVersions", "versions", "versions"), + resourceids.UserSpecifiedSegment("versionName", "versionName"), + } +} + +// String returns a human-readable description of this Version ID +func (id VersionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Package Name: %q", id.PackageName), + fmt.Sprintf("Archive Name: %q", id.ArchiveName), + fmt.Sprintf("Version Name: %q", id.VersionName), + } + return fmt.Sprintf("Version (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_version_test.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_version_test.go new file mode 100644 index 00000000000..dd7ade34c06 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/id_version_test.go @@ -0,0 +1,417 @@ +package archiveversions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &VersionId{} + +func TestNewVersionID(t *testing.T) { + id := NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName", "versionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.PackageName != "packageName" { + t.Fatalf("Expected %q but got %q for Segment 'PackageName'", id.PackageName, "packageName") + } + + if id.ArchiveName != "archiveName" { + t.Fatalf("Expected %q but got %q for Segment 'ArchiveName'", id.ArchiveName, "archiveName") + } + + if id.VersionName != "versionName" { + t.Fatalf("Expected %q but got %q for Segment 'VersionName'", id.VersionName, "versionName") + } +} + +func TestFormatVersionID(t *testing.T) { + actual := NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "packageName", "archiveName", "versionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName/versions/versionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseVersionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName/versions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName/versions/versionName", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PackageName: "packageName", + ArchiveName: "archiveName", + VersionName: "versionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName/versions/versionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVersionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PackageName != v.Expected.PackageName { + t.Fatalf("Expected %q but got %q for PackageName", v.Expected.PackageName, actual.PackageName) + } + + if actual.ArchiveName != v.Expected.ArchiveName { + t.Fatalf("Expected %q but got %q for ArchiveName", v.Expected.ArchiveName, actual.ArchiveName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + } +} + +func TestParseVersionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *VersionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe/aRcHiVeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe/aRcHiVeS/aRcHiVeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName/versions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe/aRcHiVeS/aRcHiVeNaMe/vErSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName/versions/versionName", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PackageName: "packageName", + ArchiveName: "archiveName", + VersionName: "versionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/packages/packageName/archives/archiveName/versions/versionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe/aRcHiVeS/aRcHiVeNaMe/vErSiOnS/vErSiOnNaMe", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + PackageName: "pAcKaGeNaMe", + ArchiveName: "aRcHiVeNaMe", + VersionName: "vErSiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pAcKaGeS/pAcKaGeNaMe/aRcHiVeS/aRcHiVeNaMe/vErSiOnS/vErSiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseVersionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PackageName != v.Expected.PackageName { + t.Fatalf("Expected %q but got %q for PackageName", v.Expected.PackageName, actual.PackageName) + } + + if actual.ArchiveName != v.Expected.ArchiveName { + t.Fatalf("Expected %q but got %q for ArchiveName", v.Expected.ArchiveName, actual.ArchiveName) + } + + if actual.VersionName != v.Expected.VersionName { + t.Fatalf("Expected %q but got %q for VersionName", v.Expected.VersionName, actual.VersionName) + } + + } +} + +func TestSegmentsForVersionId(t *testing.T) { + segments := VersionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("VersionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_create.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_create.go new file mode 100644 index 00000000000..3859b7cf60e --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_create.go @@ -0,0 +1,71 @@ +package archiveversions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ArchiveVersion +} + +// Create ... +func (c ArchiveVersionsClient) Create(ctx context.Context, id VersionId) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ArchiveVersionsClient) CreateThenPoll(ctx context.Context, id VersionId) error { + result, err := c.Create(ctx, id) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_delete.go new file mode 100644 index 00000000000..1cde8cae11f --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_delete.go @@ -0,0 +1,70 @@ +package archiveversions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ArchiveVersionsClient) Delete(ctx context.Context, id VersionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ArchiveVersionsClient) DeleteThenPoll(ctx context.Context, id VersionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_get.go new file mode 100644 index 00000000000..c4ca3d2dfc8 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_get.go @@ -0,0 +1,53 @@ +package archiveversions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ArchiveVersion +} + +// Get ... +func (c ArchiveVersionsClient) Get(ctx context.Context, id VersionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ArchiveVersion + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_list.go new file mode 100644 index 00000000000..69dbd3cc144 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/method_list.go @@ -0,0 +1,105 @@ +package archiveversions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ArchiveVersion +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ArchiveVersion +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ArchiveVersionsClient) List(ctx context.Context, id ArchiveId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/versions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ArchiveVersion `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ArchiveVersionsClient) ListComplete(ctx context.Context, id ArchiveId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ArchiveVersionOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ArchiveVersionsClient) ListCompleteMatchingPredicate(ctx context.Context, id ArchiveId, predicate ArchiveVersionOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ArchiveVersion, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/model_archiveversion.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/model_archiveversion.go new file mode 100644 index 00000000000..547b31667cb --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/model_archiveversion.go @@ -0,0 +1,16 @@ +package archiveversions + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArchiveVersion struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ArchiveVersionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/model_archiveversionproperties.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/model_archiveversionproperties.go new file mode 100644 index 00000000000..db7abbc881a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/model_archiveversionproperties.go @@ -0,0 +1,9 @@ +package archiveversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArchiveVersionProperties struct { + ArchiveVersionErrorMessage *string `json:"archiveVersionErrorMessage,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/predicates.go new file mode 100644 index 00000000000..49105828aef --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/predicates.go @@ -0,0 +1,27 @@ +package archiveversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ArchiveVersionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ArchiveVersionOperationPredicate) Matches(input ArchiveVersion) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/archiveversions/version.go b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/version.go new file mode 100644 index 00000000000..f8841b4e52b --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/archiveversions/version.go @@ -0,0 +1,10 @@ +package archiveversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/archiveversions/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/README.md b/resource-manager/containerregistry/2023-11-01-preview/cacherules/README.md new file mode 100644 index 00000000000..4a400d5e041 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/cacherules` Documentation + +The `cacherules` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/cacherules" +``` + + +### Client Initialization + +```go +client := cacherules.NewCacheRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CacheRulesClient.Create` + +```go +ctx := context.TODO() +id := cacherules.NewCacheRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "cacheRuleName") + +payload := cacherules.CacheRule{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `CacheRulesClient.Delete` + +```go +ctx := context.TODO() +id := cacherules.NewCacheRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "cacheRuleName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `CacheRulesClient.Get` + +```go +ctx := context.TODO() +id := cacherules.NewCacheRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "cacheRuleName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CacheRulesClient.List` + +```go +ctx := context.TODO() +id := cacherules.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CacheRulesClient.Update` + +```go +ctx := context.TODO() +id := cacherules.NewCacheRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "cacheRuleName") + +payload := cacherules.CacheRuleUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/client.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/client.go new file mode 100644 index 00000000000..d8e98c949c5 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/client.go @@ -0,0 +1,26 @@ +package cacherules + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CacheRulesClient struct { + Client *resourcemanager.Client +} + +func NewCacheRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*CacheRulesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "cacherules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CacheRulesClient: %+v", err) + } + + return &CacheRulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/constants.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/constants.go new file mode 100644 index 00000000000..bfd55c0bb73 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/constants.go @@ -0,0 +1,63 @@ +package cacherules + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/id_cacherule.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/id_cacherule.go new file mode 100644 index 00000000000..18ee6f7cdb1 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/id_cacherule.go @@ -0,0 +1,139 @@ +package cacherules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CacheRuleId{}) +} + +var _ resourceids.ResourceId = &CacheRuleId{} + +// CacheRuleId is a struct representing the Resource ID for a Cache Rule +type CacheRuleId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + CacheRuleName string +} + +// NewCacheRuleID returns a new CacheRuleId struct +func NewCacheRuleID(subscriptionId string, resourceGroupName string, registryName string, cacheRuleName string) CacheRuleId { + return CacheRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + CacheRuleName: cacheRuleName, + } +} + +// ParseCacheRuleID parses 'input' into a CacheRuleId +func ParseCacheRuleID(input string) (*CacheRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&CacheRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CacheRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCacheRuleIDInsensitively parses 'input' case-insensitively into a CacheRuleId +// note: this method should only be used for API response data and not user input +func ParseCacheRuleIDInsensitively(input string) (*CacheRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&CacheRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CacheRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CacheRuleId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.CacheRuleName, ok = input.Parsed["cacheRuleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "cacheRuleName", input) + } + + return nil +} + +// ValidateCacheRuleID checks that 'input' can be parsed as a Cache Rule ID +func ValidateCacheRuleID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseCacheRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Cache Rule ID +func (id CacheRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/cacheRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.CacheRuleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Cache Rule ID +func (id CacheRuleId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticCacheRules", "cacheRules", "cacheRules"), + resourceids.UserSpecifiedSegment("cacheRuleName", "cacheRuleName"), + } +} + +// String returns a human-readable description of this Cache Rule ID +func (id CacheRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Cache Rule Name: %q", id.CacheRuleName), + } + return fmt.Sprintf("Cache Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/id_cacherule_test.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/id_cacherule_test.go new file mode 100644 index 00000000000..6faed3db991 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/id_cacherule_test.go @@ -0,0 +1,327 @@ +package cacherules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &CacheRuleId{} + +func TestNewCacheRuleID(t *testing.T) { + id := NewCacheRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "cacheRuleName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.CacheRuleName != "cacheRuleName" { + t.Fatalf("Expected %q but got %q for Segment 'CacheRuleName'", id.CacheRuleName, "cacheRuleName") + } +} + +func TestFormatCacheRuleID(t *testing.T) { + actual := NewCacheRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "cacheRuleName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/cacheRules/cacheRuleName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCacheRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CacheRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/cacheRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/cacheRules/cacheRuleName", + Expected: &CacheRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + CacheRuleName: "cacheRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/cacheRules/cacheRuleName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCacheRuleID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.CacheRuleName != v.Expected.CacheRuleName { + t.Fatalf("Expected %q but got %q for CacheRuleName", v.Expected.CacheRuleName, actual.CacheRuleName) + } + + } +} + +func TestParseCacheRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CacheRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/cacheRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/cAcHeRuLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/cacheRules/cacheRuleName", + Expected: &CacheRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + CacheRuleName: "cacheRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/cacheRules/cacheRuleName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/cAcHeRuLeS/cAcHeRuLeNaMe", + Expected: &CacheRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + CacheRuleName: "cAcHeRuLeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/cAcHeRuLeS/cAcHeRuLeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCacheRuleIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.CacheRuleName != v.Expected.CacheRuleName { + t.Fatalf("Expected %q but got %q for CacheRuleName", v.Expected.CacheRuleName, actual.CacheRuleName) + } + + } +} + +func TestSegmentsForCacheRuleId(t *testing.T) { + segments := CacheRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CacheRuleId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/id_registry.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/id_registry.go new file mode 100644 index 00000000000..8f9249caef0 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/id_registry.go @@ -0,0 +1,130 @@ +package cacherules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RegistryId{}) +} + +var _ resourceids.ResourceId = &RegistryId{} + +// RegistryId is a struct representing the Resource ID for a Registry +type RegistryId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string +} + +// NewRegistryID returns a new RegistryId struct +func NewRegistryID(subscriptionId string, resourceGroupName string, registryName string) RegistryId { + return RegistryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + } +} + +// ParseRegistryID parses 'input' into a RegistryId +func ParseRegistryID(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRegistryIDInsensitively parses 'input' case-insensitively into a RegistryId +// note: this method should only be used for API response data and not user input +func ParseRegistryIDInsensitively(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RegistryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + return nil +} + +// ValidateRegistryID checks that 'input' can be parsed as a Registry ID +func ValidateRegistryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRegistryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Registry ID +func (id RegistryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Registry ID +func (id RegistryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + } +} + +// String returns a human-readable description of this Registry ID +func (id RegistryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + } + return fmt.Sprintf("Registry (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/id_registry_test.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/id_registry_test.go new file mode 100644 index 00000000000..2fa7fd7825e --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/id_registry_test.go @@ -0,0 +1,282 @@ +package cacherules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RegistryId{} + +func TestNewRegistryID(t *testing.T) { + id := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } +} + +func TestFormatRegistryID(t *testing.T) { + actual := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRegistryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestParseRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestSegmentsForRegistryId(t *testing.T) { + segments := RegistryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RegistryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_create.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_create.go new file mode 100644 index 00000000000..e5af51fd179 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_create.go @@ -0,0 +1,75 @@ +package cacherules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CacheRule +} + +// Create ... +func (c CacheRulesClient) Create(ctx context.Context, id CacheRuleId, input CacheRule) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c CacheRulesClient) CreateThenPoll(ctx context.Context, id CacheRuleId, input CacheRule) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_delete.go new file mode 100644 index 00000000000..c7c73071543 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_delete.go @@ -0,0 +1,70 @@ +package cacherules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c CacheRulesClient) Delete(ctx context.Context, id CacheRuleId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c CacheRulesClient) DeleteThenPoll(ctx context.Context, id CacheRuleId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_get.go new file mode 100644 index 00000000000..5934319965f --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_get.go @@ -0,0 +1,53 @@ +package cacherules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CacheRule +} + +// Get ... +func (c CacheRulesClient) Get(ctx context.Context, id CacheRuleId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CacheRule + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_list.go new file mode 100644 index 00000000000..9b1c49d2f20 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_list.go @@ -0,0 +1,105 @@ +package cacherules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CacheRule +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []CacheRule +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c CacheRulesClient) List(ctx context.Context, id RegistryId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/cacheRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]CacheRule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c CacheRulesClient) ListComplete(ctx context.Context, id RegistryId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, CacheRuleOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CacheRulesClient) ListCompleteMatchingPredicate(ctx context.Context, id RegistryId, predicate CacheRuleOperationPredicate) (result ListCompleteResult, err error) { + items := make([]CacheRule, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_update.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_update.go new file mode 100644 index 00000000000..52c930db6d4 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/method_update.go @@ -0,0 +1,75 @@ +package cacherules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CacheRule +} + +// Update ... +func (c CacheRulesClient) Update(ctx context.Context, id CacheRuleId, input CacheRuleUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c CacheRulesClient) UpdateThenPoll(ctx context.Context, id CacheRuleId, input CacheRuleUpdateParameters) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacherule.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacherule.go new file mode 100644 index 00000000000..b7301bd6970 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacherule.go @@ -0,0 +1,16 @@ +package cacherules + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CacheRule struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CacheRuleProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacheruleproperties.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacheruleproperties.go new file mode 100644 index 00000000000..1da551d094c --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacheruleproperties.go @@ -0,0 +1,30 @@ +package cacherules + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CacheRuleProperties struct { + CreationDate *string `json:"creationDate,omitempty"` + CredentialSetResourceId *string `json:"credentialSetResourceId,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + SourceRepository *string `json:"sourceRepository,omitempty"` + TargetRepository *string `json:"targetRepository,omitempty"` +} + +func (o *CacheRuleProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CacheRuleProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacheruleupdateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacheruleupdateparameters.go new file mode 100644 index 00000000000..6186726ad34 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacheruleupdateparameters.go @@ -0,0 +1,8 @@ +package cacherules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CacheRuleUpdateParameters struct { + Properties *CacheRuleUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacheruleupdateproperties.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacheruleupdateproperties.go new file mode 100644 index 00000000000..4625c719164 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/model_cacheruleupdateproperties.go @@ -0,0 +1,8 @@ +package cacherules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CacheRuleUpdateProperties struct { + CredentialSetResourceId *string `json:"credentialSetResourceId,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/predicates.go new file mode 100644 index 00000000000..f629c22e244 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/predicates.go @@ -0,0 +1,27 @@ +package cacherules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CacheRuleOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CacheRuleOperationPredicate) Matches(input CacheRule) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/cacherules/version.go b/resource-manager/containerregistry/2023-11-01-preview/cacherules/version.go new file mode 100644 index 00000000000..3efb6e18795 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/cacherules/version.go @@ -0,0 +1,10 @@ +package cacherules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/cacherules/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/client.go b/resource-manager/containerregistry/2023-11-01-preview/client.go new file mode 100644 index 00000000000..36b7904866e --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/client.go @@ -0,0 +1,154 @@ +package v2023_11_01_preview + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/archives" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/archiveversions" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/cacherules" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/connectedregistries" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/credentialsets" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/exportpipelines" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/importpipelines" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/operation" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/pipelineruns" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/registries" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/replications" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/scopemaps" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/tokens" + "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/webhooks" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + ArchiveVersions *archiveversions.ArchiveVersionsClient + Archives *archives.ArchivesClient + CacheRules *cacherules.CacheRulesClient + ConnectedRegistries *connectedregistries.ConnectedRegistriesClient + CredentialSets *credentialsets.CredentialSetsClient + ExportPipelines *exportpipelines.ExportPipelinesClient + ImportPipelines *importpipelines.ImportPipelinesClient + Operation *operation.OperationClient + PipelineRuns *pipelineruns.PipelineRunsClient + PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient + Registries *registries.RegistriesClient + Replications *replications.ReplicationsClient + ScopeMaps *scopemaps.ScopeMapsClient + Tokens *tokens.TokensClient + WebHooks *webhooks.WebHooksClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + archiveVersionsClient, err := archiveversions.NewArchiveVersionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ArchiveVersions client: %+v", err) + } + configureFunc(archiveVersionsClient.Client) + + archivesClient, err := archives.NewArchivesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Archives client: %+v", err) + } + configureFunc(archivesClient.Client) + + cacheRulesClient, err := cacherules.NewCacheRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CacheRules client: %+v", err) + } + configureFunc(cacheRulesClient.Client) + + connectedRegistriesClient, err := connectedregistries.NewConnectedRegistriesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ConnectedRegistries client: %+v", err) + } + configureFunc(connectedRegistriesClient.Client) + + credentialSetsClient, err := credentialsets.NewCredentialSetsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CredentialSets client: %+v", err) + } + configureFunc(credentialSetsClient.Client) + + exportPipelinesClient, err := exportpipelines.NewExportPipelinesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ExportPipelines client: %+v", err) + } + configureFunc(exportPipelinesClient.Client) + + importPipelinesClient, err := importpipelines.NewImportPipelinesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ImportPipelines client: %+v", err) + } + configureFunc(importPipelinesClient.Client) + + operationClient, err := operation.NewOperationClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Operation client: %+v", err) + } + configureFunc(operationClient.Client) + + pipelineRunsClient, err := pipelineruns.NewPipelineRunsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PipelineRuns client: %+v", err) + } + configureFunc(pipelineRunsClient.Client) + + privateEndpointConnectionsClient, err := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateEndpointConnections client: %+v", err) + } + configureFunc(privateEndpointConnectionsClient.Client) + + registriesClient, err := registries.NewRegistriesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Registries client: %+v", err) + } + configureFunc(registriesClient.Client) + + replicationsClient, err := replications.NewReplicationsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Replications client: %+v", err) + } + configureFunc(replicationsClient.Client) + + scopeMapsClient, err := scopemaps.NewScopeMapsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ScopeMaps client: %+v", err) + } + configureFunc(scopeMapsClient.Client) + + tokensClient, err := tokens.NewTokensClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Tokens client: %+v", err) + } + configureFunc(tokensClient.Client) + + webHooksClient, err := webhooks.NewWebHooksClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building WebHooks client: %+v", err) + } + configureFunc(webHooksClient.Client) + + return &Client{ + ArchiveVersions: archiveVersionsClient, + Archives: archivesClient, + CacheRules: cacheRulesClient, + ConnectedRegistries: connectedRegistriesClient, + CredentialSets: credentialSetsClient, + ExportPipelines: exportPipelinesClient, + ImportPipelines: importPipelinesClient, + Operation: operationClient, + PipelineRuns: pipelineRunsClient, + PrivateEndpointConnections: privateEndpointConnectionsClient, + Registries: registriesClient, + Replications: replicationsClient, + ScopeMaps: scopeMapsClient, + Tokens: tokensClient, + WebHooks: webHooksClient, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/README.md b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/README.md new file mode 100644 index 00000000000..fbd73d8244a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/connectedregistries` Documentation + +The `connectedregistries` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/connectedregistries" +``` + + +### Client Initialization + +```go +client := connectedregistries.NewConnectedRegistriesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ConnectedRegistriesClient.Create` + +```go +ctx := context.TODO() +id := connectedregistries.NewConnectedRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "connectedRegistryName") + +payload := connectedregistries.ConnectedRegistry{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ConnectedRegistriesClient.Deactivate` + +```go +ctx := context.TODO() +id := connectedregistries.NewConnectedRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "connectedRegistryName") + +if err := client.DeactivateThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ConnectedRegistriesClient.Delete` + +```go +ctx := context.TODO() +id := connectedregistries.NewConnectedRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "connectedRegistryName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ConnectedRegistriesClient.Get` + +```go +ctx := context.TODO() +id := connectedregistries.NewConnectedRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "connectedRegistryName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConnectedRegistriesClient.List` + +```go +ctx := context.TODO() +id := connectedregistries.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +// alternatively `client.List(ctx, id, connectedregistries.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, connectedregistries.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ConnectedRegistriesClient.Update` + +```go +ctx := context.TODO() +id := connectedregistries.NewConnectedRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "connectedRegistryName") + +payload := connectedregistries.ConnectedRegistryUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/client.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/client.go new file mode 100644 index 00000000000..7580fc11c65 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/client.go @@ -0,0 +1,26 @@ +package connectedregistries + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedRegistriesClient struct { + Client *resourcemanager.Client +} + +func NewConnectedRegistriesClientWithBaseURI(sdkApi sdkEnv.Api) (*ConnectedRegistriesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "connectedregistries", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ConnectedRegistriesClient: %+v", err) + } + + return &ConnectedRegistriesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/constants.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/constants.go new file mode 100644 index 00000000000..a7cf9ad0728 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/constants.go @@ -0,0 +1,368 @@ +package connectedregistries + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActivationStatus string + +const ( + ActivationStatusActive ActivationStatus = "Active" + ActivationStatusInactive ActivationStatus = "Inactive" +) + +func PossibleValuesForActivationStatus() []string { + return []string{ + string(ActivationStatusActive), + string(ActivationStatusInactive), + } +} + +func (s *ActivationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActivationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActivationStatus(input string) (*ActivationStatus, error) { + vals := map[string]ActivationStatus{ + "active": ActivationStatusActive, + "inactive": ActivationStatusInactive, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActivationStatus(input) + return &out, nil +} + +type AuditLogStatus string + +const ( + AuditLogStatusDisabled AuditLogStatus = "Disabled" + AuditLogStatusEnabled AuditLogStatus = "Enabled" +) + +func PossibleValuesForAuditLogStatus() []string { + return []string{ + string(AuditLogStatusDisabled), + string(AuditLogStatusEnabled), + } +} + +func (s *AuditLogStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAuditLogStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAuditLogStatus(input string) (*AuditLogStatus, error) { + vals := map[string]AuditLogStatus{ + "disabled": AuditLogStatusDisabled, + "enabled": AuditLogStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AuditLogStatus(input) + return &out, nil +} + +type CertificateType string + +const ( + CertificateTypeLocalDirectory CertificateType = "LocalDirectory" +) + +func PossibleValuesForCertificateType() []string { + return []string{ + string(CertificateTypeLocalDirectory), + } +} + +func (s *CertificateType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCertificateType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCertificateType(input string) (*CertificateType, error) { + vals := map[string]CertificateType{ + "localdirectory": CertificateTypeLocalDirectory, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CertificateType(input) + return &out, nil +} + +type ConnectedRegistryMode string + +const ( + ConnectedRegistryModeMirror ConnectedRegistryMode = "Mirror" + ConnectedRegistryModeReadOnly ConnectedRegistryMode = "ReadOnly" + ConnectedRegistryModeReadWrite ConnectedRegistryMode = "ReadWrite" + ConnectedRegistryModeRegistry ConnectedRegistryMode = "Registry" +) + +func PossibleValuesForConnectedRegistryMode() []string { + return []string{ + string(ConnectedRegistryModeMirror), + string(ConnectedRegistryModeReadOnly), + string(ConnectedRegistryModeReadWrite), + string(ConnectedRegistryModeRegistry), + } +} + +func (s *ConnectedRegistryMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectedRegistryMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConnectedRegistryMode(input string) (*ConnectedRegistryMode, error) { + vals := map[string]ConnectedRegistryMode{ + "mirror": ConnectedRegistryModeMirror, + "readonly": ConnectedRegistryModeReadOnly, + "readwrite": ConnectedRegistryModeReadWrite, + "registry": ConnectedRegistryModeRegistry, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectedRegistryMode(input) + return &out, nil +} + +type ConnectionState string + +const ( + ConnectionStateOffline ConnectionState = "Offline" + ConnectionStateOnline ConnectionState = "Online" + ConnectionStateSyncing ConnectionState = "Syncing" + ConnectionStateUnhealthy ConnectionState = "Unhealthy" +) + +func PossibleValuesForConnectionState() []string { + return []string{ + string(ConnectionStateOffline), + string(ConnectionStateOnline), + string(ConnectionStateSyncing), + string(ConnectionStateUnhealthy), + } +} + +func (s *ConnectionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConnectionState(input string) (*ConnectionState, error) { + vals := map[string]ConnectionState{ + "offline": ConnectionStateOffline, + "online": ConnectionStateOnline, + "syncing": ConnectionStateSyncing, + "unhealthy": ConnectionStateUnhealthy, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectionState(input) + return &out, nil +} + +type LogLevel string + +const ( + LogLevelDebug LogLevel = "Debug" + LogLevelError LogLevel = "Error" + LogLevelInformation LogLevel = "Information" + LogLevelNone LogLevel = "None" + LogLevelWarning LogLevel = "Warning" +) + +func PossibleValuesForLogLevel() []string { + return []string{ + string(LogLevelDebug), + string(LogLevelError), + string(LogLevelInformation), + string(LogLevelNone), + string(LogLevelWarning), + } +} + +func (s *LogLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLogLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLogLevel(input string) (*LogLevel, error) { + vals := map[string]LogLevel{ + "debug": LogLevelDebug, + "error": LogLevelError, + "information": LogLevelInformation, + "none": LogLevelNone, + "warning": LogLevelWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LogLevel(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type TlsStatus string + +const ( + TlsStatusDisabled TlsStatus = "Disabled" + TlsStatusEnabled TlsStatus = "Enabled" +) + +func PossibleValuesForTlsStatus() []string { + return []string{ + string(TlsStatusDisabled), + string(TlsStatusEnabled), + } +} + +func (s *TlsStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTlsStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTlsStatus(input string) (*TlsStatus, error) { + vals := map[string]TlsStatus{ + "disabled": TlsStatusDisabled, + "enabled": TlsStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TlsStatus(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_connectedregistry.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_connectedregistry.go new file mode 100644 index 00000000000..e055a0c04a6 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_connectedregistry.go @@ -0,0 +1,139 @@ +package connectedregistries + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ConnectedRegistryId{}) +} + +var _ resourceids.ResourceId = &ConnectedRegistryId{} + +// ConnectedRegistryId is a struct representing the Resource ID for a Connected Registry +type ConnectedRegistryId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + ConnectedRegistryName string +} + +// NewConnectedRegistryID returns a new ConnectedRegistryId struct +func NewConnectedRegistryID(subscriptionId string, resourceGroupName string, registryName string, connectedRegistryName string) ConnectedRegistryId { + return ConnectedRegistryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + ConnectedRegistryName: connectedRegistryName, + } +} + +// ParseConnectedRegistryID parses 'input' into a ConnectedRegistryId +func ParseConnectedRegistryID(input string) (*ConnectedRegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedRegistryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedRegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseConnectedRegistryIDInsensitively parses 'input' case-insensitively into a ConnectedRegistryId +// note: this method should only be used for API response data and not user input +func ParseConnectedRegistryIDInsensitively(input string) (*ConnectedRegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&ConnectedRegistryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ConnectedRegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ConnectedRegistryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.ConnectedRegistryName, ok = input.Parsed["connectedRegistryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "connectedRegistryName", input) + } + + return nil +} + +// ValidateConnectedRegistryID checks that 'input' can be parsed as a Connected Registry ID +func ValidateConnectedRegistryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseConnectedRegistryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Connected Registry ID +func (id ConnectedRegistryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/connectedRegistries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.ConnectedRegistryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Connected Registry ID +func (id ConnectedRegistryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticConnectedRegistries", "connectedRegistries", "connectedRegistries"), + resourceids.UserSpecifiedSegment("connectedRegistryName", "connectedRegistryName"), + } +} + +// String returns a human-readable description of this Connected Registry ID +func (id ConnectedRegistryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Connected Registry Name: %q", id.ConnectedRegistryName), + } + return fmt.Sprintf("Connected Registry (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_connectedregistry_test.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_connectedregistry_test.go new file mode 100644 index 00000000000..8a53746fc23 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_connectedregistry_test.go @@ -0,0 +1,327 @@ +package connectedregistries + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ConnectedRegistryId{} + +func TestNewConnectedRegistryID(t *testing.T) { + id := NewConnectedRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "connectedRegistryName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.ConnectedRegistryName != "connectedRegistryName" { + t.Fatalf("Expected %q but got %q for Segment 'ConnectedRegistryName'", id.ConnectedRegistryName, "connectedRegistryName") + } +} + +func TestFormatConnectedRegistryID(t *testing.T) { + actual := NewConnectedRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "connectedRegistryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/connectedRegistries/connectedRegistryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConnectedRegistryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedRegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/connectedRegistries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/connectedRegistries/connectedRegistryName", + Expected: &ConnectedRegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + ConnectedRegistryName: "connectedRegistryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/connectedRegistries/connectedRegistryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedRegistryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.ConnectedRegistryName != v.Expected.ConnectedRegistryName { + t.Fatalf("Expected %q but got %q for ConnectedRegistryName", v.Expected.ConnectedRegistryName, actual.ConnectedRegistryName) + } + + } +} + +func TestParseConnectedRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedRegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/connectedRegistries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/cOnNeCtEdReGiStRiEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/connectedRegistries/connectedRegistryName", + Expected: &ConnectedRegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + ConnectedRegistryName: "connectedRegistryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/connectedRegistries/connectedRegistryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/cOnNeCtEdReGiStRiEs/cOnNeCtEdReGiStRyNaMe", + Expected: &ConnectedRegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + ConnectedRegistryName: "cOnNeCtEdReGiStRyNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/cOnNeCtEdReGiStRiEs/cOnNeCtEdReGiStRyNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.ConnectedRegistryName != v.Expected.ConnectedRegistryName { + t.Fatalf("Expected %q but got %q for ConnectedRegistryName", v.Expected.ConnectedRegistryName, actual.ConnectedRegistryName) + } + + } +} + +func TestSegmentsForConnectedRegistryId(t *testing.T) { + segments := ConnectedRegistryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConnectedRegistryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_registry.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_registry.go new file mode 100644 index 00000000000..6be8ac207ce --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_registry.go @@ -0,0 +1,130 @@ +package connectedregistries + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RegistryId{}) +} + +var _ resourceids.ResourceId = &RegistryId{} + +// RegistryId is a struct representing the Resource ID for a Registry +type RegistryId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string +} + +// NewRegistryID returns a new RegistryId struct +func NewRegistryID(subscriptionId string, resourceGroupName string, registryName string) RegistryId { + return RegistryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + } +} + +// ParseRegistryID parses 'input' into a RegistryId +func ParseRegistryID(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRegistryIDInsensitively parses 'input' case-insensitively into a RegistryId +// note: this method should only be used for API response data and not user input +func ParseRegistryIDInsensitively(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RegistryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + return nil +} + +// ValidateRegistryID checks that 'input' can be parsed as a Registry ID +func ValidateRegistryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRegistryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Registry ID +func (id RegistryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Registry ID +func (id RegistryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + } +} + +// String returns a human-readable description of this Registry ID +func (id RegistryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + } + return fmt.Sprintf("Registry (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_registry_test.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_registry_test.go new file mode 100644 index 00000000000..3b68f02ae01 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/id_registry_test.go @@ -0,0 +1,282 @@ +package connectedregistries + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RegistryId{} + +func TestNewRegistryID(t *testing.T) { + id := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } +} + +func TestFormatRegistryID(t *testing.T) { + actual := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRegistryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestParseRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestSegmentsForRegistryId(t *testing.T) { + segments := RegistryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RegistryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_create.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_create.go new file mode 100644 index 00000000000..c473bdb4d99 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_create.go @@ -0,0 +1,75 @@ +package connectedregistries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ConnectedRegistry +} + +// Create ... +func (c ConnectedRegistriesClient) Create(ctx context.Context, id ConnectedRegistryId, input ConnectedRegistry) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ConnectedRegistriesClient) CreateThenPoll(ctx context.Context, id ConnectedRegistryId, input ConnectedRegistry) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_deactivate.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_deactivate.go new file mode 100644 index 00000000000..0df02019749 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_deactivate.go @@ -0,0 +1,70 @@ +package connectedregistries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeactivateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Deactivate ... +func (c ConnectedRegistriesClient) Deactivate(ctx context.Context, id ConnectedRegistryId) (result DeactivateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/deactivate", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeactivateThenPoll performs Deactivate then polls until it's completed +func (c ConnectedRegistriesClient) DeactivateThenPoll(ctx context.Context, id ConnectedRegistryId) error { + result, err := c.Deactivate(ctx, id) + if err != nil { + return fmt.Errorf("performing Deactivate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Deactivate: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_delete.go new file mode 100644 index 00000000000..6fee46acb46 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_delete.go @@ -0,0 +1,71 @@ +package connectedregistries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ConnectedRegistriesClient) Delete(ctx context.Context, id ConnectedRegistryId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ConnectedRegistriesClient) DeleteThenPoll(ctx context.Context, id ConnectedRegistryId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_get.go new file mode 100644 index 00000000000..4c81bf8b4b1 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_get.go @@ -0,0 +1,53 @@ +package connectedregistries + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ConnectedRegistry +} + +// Get ... +func (c ConnectedRegistriesClient) Get(ctx context.Context, id ConnectedRegistryId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ConnectedRegistry + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_list.go new file mode 100644 index 00000000000..8bb816547bb --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_list.go @@ -0,0 +1,134 @@ +package connectedregistries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ConnectedRegistry +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ConnectedRegistry +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ConnectedRegistriesClient) List(ctx context.Context, id RegistryId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/connectedRegistries", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ConnectedRegistry `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ConnectedRegistriesClient) ListComplete(ctx context.Context, id RegistryId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, ConnectedRegistryOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ConnectedRegistriesClient) ListCompleteMatchingPredicate(ctx context.Context, id RegistryId, options ListOperationOptions, predicate ConnectedRegistryOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ConnectedRegistry, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_update.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_update.go new file mode 100644 index 00000000000..e4eeb4f8b9d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/method_update.go @@ -0,0 +1,75 @@ +package connectedregistries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ConnectedRegistry +} + +// Update ... +func (c ConnectedRegistriesClient) Update(ctx context.Context, id ConnectedRegistryId, input ConnectedRegistryUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ConnectedRegistriesClient) UpdateThenPoll(ctx context.Context, id ConnectedRegistryId, input ConnectedRegistryUpdateParameters) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_activationproperties.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_activationproperties.go new file mode 100644 index 00000000000..822605ddc59 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_activationproperties.go @@ -0,0 +1,8 @@ +package connectedregistries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActivationProperties struct { + Status *ActivationStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistry.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistry.go new file mode 100644 index 00000000000..2f71cf1c83c --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistry.go @@ -0,0 +1,16 @@ +package connectedregistries + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedRegistry struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ConnectedRegistryProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistryproperties.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistryproperties.go new file mode 100644 index 00000000000..8b52a3ba2d2 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistryproperties.go @@ -0,0 +1,37 @@ +package connectedregistries + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedRegistryProperties struct { + Activation *ActivationProperties `json:"activation,omitempty"` + ClientTokenIds *[]string `json:"clientTokenIds,omitempty"` + ConnectionState *ConnectionState `json:"connectionState,omitempty"` + LastActivityTime *string `json:"lastActivityTime,omitempty"` + Logging *LoggingProperties `json:"logging,omitempty"` + LoginServer *LoginServerProperties `json:"loginServer,omitempty"` + Mode ConnectedRegistryMode `json:"mode"` + NotificationsList *[]string `json:"notificationsList,omitempty"` + Parent ParentProperties `json:"parent"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + StatusDetails *[]StatusDetailProperties `json:"statusDetails,omitempty"` + Version *string `json:"version,omitempty"` +} + +func (o *ConnectedRegistryProperties) GetLastActivityTimeAsTime() (*time.Time, error) { + if o.LastActivityTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastActivityTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ConnectedRegistryProperties) SetLastActivityTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastActivityTime = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistryupdateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistryupdateparameters.go new file mode 100644 index 00000000000..53794a29b72 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistryupdateparameters.go @@ -0,0 +1,8 @@ +package connectedregistries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedRegistryUpdateParameters struct { + Properties *ConnectedRegistryUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistryupdateproperties.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistryupdateproperties.go new file mode 100644 index 00000000000..1828e91616a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_connectedregistryupdateproperties.go @@ -0,0 +1,11 @@ +package connectedregistries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedRegistryUpdateProperties struct { + ClientTokenIds *[]string `json:"clientTokenIds,omitempty"` + Logging *LoggingProperties `json:"logging,omitempty"` + NotificationsList *[]string `json:"notificationsList,omitempty"` + SyncProperties *SyncUpdateProperties `json:"syncProperties,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_loggingproperties.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_loggingproperties.go new file mode 100644 index 00000000000..2cc48390538 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_loggingproperties.go @@ -0,0 +1,9 @@ +package connectedregistries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LoggingProperties struct { + AuditLogStatus *AuditLogStatus `json:"auditLogStatus,omitempty"` + LogLevel *LogLevel `json:"logLevel,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_loginserverproperties.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_loginserverproperties.go new file mode 100644 index 00000000000..e1e95b7d59d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_loginserverproperties.go @@ -0,0 +1,9 @@ +package connectedregistries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LoginServerProperties struct { + Host *string `json:"host,omitempty"` + Tls *TlsProperties `json:"tls,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_parentproperties.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_parentproperties.go new file mode 100644 index 00000000000..09a01be73f4 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_parentproperties.go @@ -0,0 +1,9 @@ +package connectedregistries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ParentProperties struct { + Id *string `json:"id,omitempty"` + SyncProperties SyncProperties `json:"syncProperties"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_statusdetailproperties.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_statusdetailproperties.go new file mode 100644 index 00000000000..61b526aa9de --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_statusdetailproperties.go @@ -0,0 +1,30 @@ +package connectedregistries + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StatusDetailProperties struct { + Code *string `json:"code,omitempty"` + CorrelationId *string `json:"correlationId,omitempty"` + Description *string `json:"description,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` + Type *string `json:"type,omitempty"` +} + +func (o *StatusDetailProperties) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *StatusDetailProperties) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_syncproperties.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_syncproperties.go new file mode 100644 index 00000000000..23d99413cfd --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_syncproperties.go @@ -0,0 +1,31 @@ +package connectedregistries + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncProperties struct { + GatewayEndpoint *string `json:"gatewayEndpoint,omitempty"` + LastSyncTime *string `json:"lastSyncTime,omitempty"` + MessageTtl string `json:"messageTtl"` + Schedule *string `json:"schedule,omitempty"` + SyncWindow *string `json:"syncWindow,omitempty"` + TokenId string `json:"tokenId"` +} + +func (o *SyncProperties) GetLastSyncTimeAsTime() (*time.Time, error) { + if o.LastSyncTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSyncTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SyncProperties) SetLastSyncTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSyncTime = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_syncupdateproperties.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_syncupdateproperties.go new file mode 100644 index 00000000000..e0218a66e32 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_syncupdateproperties.go @@ -0,0 +1,10 @@ +package connectedregistries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncUpdateProperties struct { + MessageTtl *string `json:"messageTtl,omitempty"` + Schedule *string `json:"schedule,omitempty"` + SyncWindow *string `json:"syncWindow,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_tlscertificateproperties.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_tlscertificateproperties.go new file mode 100644 index 00000000000..eb149528e07 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_tlscertificateproperties.go @@ -0,0 +1,9 @@ +package connectedregistries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TlsCertificateProperties struct { + Location *string `json:"location,omitempty"` + Type *CertificateType `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_tlsproperties.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_tlsproperties.go new file mode 100644 index 00000000000..443f5f1c1d4 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/model_tlsproperties.go @@ -0,0 +1,9 @@ +package connectedregistries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TlsProperties struct { + Certificate *TlsCertificateProperties `json:"certificate,omitempty"` + Status *TlsStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/predicates.go new file mode 100644 index 00000000000..4308d2cd178 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/predicates.go @@ -0,0 +1,27 @@ +package connectedregistries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedRegistryOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ConnectedRegistryOperationPredicate) Matches(input ConnectedRegistry) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/version.go b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/version.go new file mode 100644 index 00000000000..115138d13c9 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/connectedregistries/version.go @@ -0,0 +1,10 @@ +package connectedregistries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/connectedregistries/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/README.md b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/README.md new file mode 100644 index 00000000000..89478dab0f2 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/credentialsets` Documentation + +The `credentialsets` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/credentialsets" +``` + + +### Client Initialization + +```go +client := credentialsets.NewCredentialSetsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CredentialSetsClient.Create` + +```go +ctx := context.TODO() +id := credentialsets.NewCredentialSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "credentialSetName") + +payload := credentialsets.CredentialSet{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `CredentialSetsClient.Delete` + +```go +ctx := context.TODO() +id := credentialsets.NewCredentialSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "credentialSetName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `CredentialSetsClient.Get` + +```go +ctx := context.TODO() +id := credentialsets.NewCredentialSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "credentialSetName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CredentialSetsClient.List` + +```go +ctx := context.TODO() +id := credentialsets.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CredentialSetsClient.Update` + +```go +ctx := context.TODO() +id := credentialsets.NewCredentialSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "credentialSetName") + +payload := credentialsets.CredentialSetUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/client.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/client.go new file mode 100644 index 00000000000..8a4cdeafb1a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/client.go @@ -0,0 +1,26 @@ +package credentialsets + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialSetsClient struct { + Client *resourcemanager.Client +} + +func NewCredentialSetsClientWithBaseURI(sdkApi sdkEnv.Api) (*CredentialSetsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "credentialsets", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CredentialSetsClient: %+v", err) + } + + return &CredentialSetsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/constants.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/constants.go new file mode 100644 index 00000000000..ff71d8ceaa0 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/constants.go @@ -0,0 +1,142 @@ +package credentialsets + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialHealthStatus string + +const ( + CredentialHealthStatusHealthy CredentialHealthStatus = "Healthy" + CredentialHealthStatusUnhealthy CredentialHealthStatus = "Unhealthy" +) + +func PossibleValuesForCredentialHealthStatus() []string { + return []string{ + string(CredentialHealthStatusHealthy), + string(CredentialHealthStatusUnhealthy), + } +} + +func (s *CredentialHealthStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCredentialHealthStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCredentialHealthStatus(input string) (*CredentialHealthStatus, error) { + vals := map[string]CredentialHealthStatus{ + "healthy": CredentialHealthStatusHealthy, + "unhealthy": CredentialHealthStatusUnhealthy, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CredentialHealthStatus(input) + return &out, nil +} + +type CredentialName string + +const ( + CredentialNameCredentialOne CredentialName = "Credential1" +) + +func PossibleValuesForCredentialName() []string { + return []string{ + string(CredentialNameCredentialOne), + } +} + +func (s *CredentialName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCredentialName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCredentialName(input string) (*CredentialName, error) { + vals := map[string]CredentialName{ + "credential1": CredentialNameCredentialOne, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CredentialName(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_credentialset.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_credentialset.go new file mode 100644 index 00000000000..294e54d8384 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_credentialset.go @@ -0,0 +1,139 @@ +package credentialsets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&CredentialSetId{}) +} + +var _ resourceids.ResourceId = &CredentialSetId{} + +// CredentialSetId is a struct representing the Resource ID for a Credential Set +type CredentialSetId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + CredentialSetName string +} + +// NewCredentialSetID returns a new CredentialSetId struct +func NewCredentialSetID(subscriptionId string, resourceGroupName string, registryName string, credentialSetName string) CredentialSetId { + return CredentialSetId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + CredentialSetName: credentialSetName, + } +} + +// ParseCredentialSetID parses 'input' into a CredentialSetId +func ParseCredentialSetID(input string) (*CredentialSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&CredentialSetId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CredentialSetId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCredentialSetIDInsensitively parses 'input' case-insensitively into a CredentialSetId +// note: this method should only be used for API response data and not user input +func ParseCredentialSetIDInsensitively(input string) (*CredentialSetId, error) { + parser := resourceids.NewParserFromResourceIdType(&CredentialSetId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CredentialSetId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CredentialSetId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.CredentialSetName, ok = input.Parsed["credentialSetName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "credentialSetName", input) + } + + return nil +} + +// ValidateCredentialSetID checks that 'input' can be parsed as a Credential Set ID +func ValidateCredentialSetID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseCredentialSetID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Credential Set ID +func (id CredentialSetId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/credentialSets/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.CredentialSetName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Credential Set ID +func (id CredentialSetId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticCredentialSets", "credentialSets", "credentialSets"), + resourceids.UserSpecifiedSegment("credentialSetName", "credentialSetName"), + } +} + +// String returns a human-readable description of this Credential Set ID +func (id CredentialSetId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Credential Set Name: %q", id.CredentialSetName), + } + return fmt.Sprintf("Credential Set (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_credentialset_test.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_credentialset_test.go new file mode 100644 index 00000000000..7cdf7af2984 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_credentialset_test.go @@ -0,0 +1,327 @@ +package credentialsets + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &CredentialSetId{} + +func TestNewCredentialSetID(t *testing.T) { + id := NewCredentialSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "credentialSetName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.CredentialSetName != "credentialSetName" { + t.Fatalf("Expected %q but got %q for Segment 'CredentialSetName'", id.CredentialSetName, "credentialSetName") + } +} + +func TestFormatCredentialSetID(t *testing.T) { + actual := NewCredentialSetID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "credentialSetName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/credentialSets/credentialSetName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCredentialSetID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CredentialSetId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/credentialSets", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/credentialSets/credentialSetName", + Expected: &CredentialSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + CredentialSetName: "credentialSetName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/credentialSets/credentialSetName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCredentialSetID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.CredentialSetName != v.Expected.CredentialSetName { + t.Fatalf("Expected %q but got %q for CredentialSetName", v.Expected.CredentialSetName, actual.CredentialSetName) + } + + } +} + +func TestParseCredentialSetIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CredentialSetId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/credentialSets", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/cReDeNtIaLsEtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/credentialSets/credentialSetName", + Expected: &CredentialSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + CredentialSetName: "credentialSetName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/credentialSets/credentialSetName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/cReDeNtIaLsEtS/cReDeNtIaLsEtNaMe", + Expected: &CredentialSetId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + CredentialSetName: "cReDeNtIaLsEtNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/cReDeNtIaLsEtS/cReDeNtIaLsEtNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCredentialSetIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.CredentialSetName != v.Expected.CredentialSetName { + t.Fatalf("Expected %q but got %q for CredentialSetName", v.Expected.CredentialSetName, actual.CredentialSetName) + } + + } +} + +func TestSegmentsForCredentialSetId(t *testing.T) { + segments := CredentialSetId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CredentialSetId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_registry.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_registry.go new file mode 100644 index 00000000000..b65f35b83c1 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_registry.go @@ -0,0 +1,130 @@ +package credentialsets + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RegistryId{}) +} + +var _ resourceids.ResourceId = &RegistryId{} + +// RegistryId is a struct representing the Resource ID for a Registry +type RegistryId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string +} + +// NewRegistryID returns a new RegistryId struct +func NewRegistryID(subscriptionId string, resourceGroupName string, registryName string) RegistryId { + return RegistryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + } +} + +// ParseRegistryID parses 'input' into a RegistryId +func ParseRegistryID(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRegistryIDInsensitively parses 'input' case-insensitively into a RegistryId +// note: this method should only be used for API response data and not user input +func ParseRegistryIDInsensitively(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RegistryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + return nil +} + +// ValidateRegistryID checks that 'input' can be parsed as a Registry ID +func ValidateRegistryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRegistryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Registry ID +func (id RegistryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Registry ID +func (id RegistryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + } +} + +// String returns a human-readable description of this Registry ID +func (id RegistryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + } + return fmt.Sprintf("Registry (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_registry_test.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_registry_test.go new file mode 100644 index 00000000000..a963706e681 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/id_registry_test.go @@ -0,0 +1,282 @@ +package credentialsets + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RegistryId{} + +func TestNewRegistryID(t *testing.T) { + id := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } +} + +func TestFormatRegistryID(t *testing.T) { + actual := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRegistryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestParseRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestSegmentsForRegistryId(t *testing.T) { + segments := RegistryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RegistryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_create.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_create.go new file mode 100644 index 00000000000..63256806132 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_create.go @@ -0,0 +1,75 @@ +package credentialsets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CredentialSet +} + +// Create ... +func (c CredentialSetsClient) Create(ctx context.Context, id CredentialSetId, input CredentialSet) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c CredentialSetsClient) CreateThenPoll(ctx context.Context, id CredentialSetId, input CredentialSet) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_delete.go new file mode 100644 index 00000000000..ccf0140f8ef --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_delete.go @@ -0,0 +1,70 @@ +package credentialsets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c CredentialSetsClient) Delete(ctx context.Context, id CredentialSetId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c CredentialSetsClient) DeleteThenPoll(ctx context.Context, id CredentialSetId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_get.go new file mode 100644 index 00000000000..65e3a16b9da --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_get.go @@ -0,0 +1,53 @@ +package credentialsets + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CredentialSet +} + +// Get ... +func (c CredentialSetsClient) Get(ctx context.Context, id CredentialSetId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CredentialSet + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_list.go new file mode 100644 index 00000000000..56fadc1e618 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_list.go @@ -0,0 +1,105 @@ +package credentialsets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CredentialSet +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []CredentialSet +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c CredentialSetsClient) List(ctx context.Context, id RegistryId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/credentialSets", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]CredentialSet `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c CredentialSetsClient) ListComplete(ctx context.Context, id RegistryId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, CredentialSetOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CredentialSetsClient) ListCompleteMatchingPredicate(ctx context.Context, id RegistryId, predicate CredentialSetOperationPredicate) (result ListCompleteResult, err error) { + items := make([]CredentialSet, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_update.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_update.go new file mode 100644 index 00000000000..5451fc9ae4a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/method_update.go @@ -0,0 +1,75 @@ +package credentialsets + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CredentialSet +} + +// Update ... +func (c CredentialSetsClient) Update(ctx context.Context, id CredentialSetId, input CredentialSetUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c CredentialSetsClient) UpdateThenPoll(ctx context.Context, id CredentialSetId, input CredentialSetUpdateParameters) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_authcredential.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_authcredential.go new file mode 100644 index 00000000000..913c42662ac --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_authcredential.go @@ -0,0 +1,11 @@ +package credentialsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthCredential struct { + CredentialHealth *CredentialHealth `json:"credentialHealth,omitempty"` + Name *CredentialName `json:"name,omitempty"` + PasswordSecretIdentifier *string `json:"passwordSecretIdentifier,omitempty"` + UsernameSecretIdentifier *string `json:"usernameSecretIdentifier,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialhealth.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialhealth.go new file mode 100644 index 00000000000..ca30e48d6f2 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialhealth.go @@ -0,0 +1,10 @@ +package credentialsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialHealth struct { + ErrorCode *string `json:"errorCode,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + Status *CredentialHealthStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialset.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialset.go new file mode 100644 index 00000000000..26779ccad5c --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialset.go @@ -0,0 +1,18 @@ +package credentialsets + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialSet struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CredentialSetProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialsetproperties.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialsetproperties.go new file mode 100644 index 00000000000..12298beeb14 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialsetproperties.go @@ -0,0 +1,29 @@ +package credentialsets + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialSetProperties struct { + AuthCredentials *[]AuthCredential `json:"authCredentials,omitempty"` + CreationDate *string `json:"creationDate,omitempty"` + LoginServer *string `json:"loginServer,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} + +func (o *CredentialSetProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *CredentialSetProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialsetupdateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialsetupdateparameters.go new file mode 100644 index 00000000000..b43c63ad176 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialsetupdateparameters.go @@ -0,0 +1,13 @@ +package credentialsets + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialSetUpdateParameters struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *CredentialSetUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialsetupdateproperties.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialsetupdateproperties.go new file mode 100644 index 00000000000..718731e5d24 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/model_credentialsetupdateproperties.go @@ -0,0 +1,8 @@ +package credentialsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialSetUpdateProperties struct { + AuthCredentials *[]AuthCredential `json:"authCredentials,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/predicates.go new file mode 100644 index 00000000000..c8e61730e35 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/predicates.go @@ -0,0 +1,27 @@ +package credentialsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialSetOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CredentialSetOperationPredicate) Matches(input CredentialSet) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/credentialsets/version.go b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/version.go new file mode 100644 index 00000000000..ad6c5e2efa7 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/credentialsets/version.go @@ -0,0 +1,10 @@ +package credentialsets + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/credentialsets/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/README.md b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/README.md new file mode 100644 index 00000000000..3cd5f446085 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/exportpipelines` Documentation + +The `exportpipelines` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/exportpipelines" +``` + + +### Client Initialization + +```go +client := exportpipelines.NewExportPipelinesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ExportPipelinesClient.Create` + +```go +ctx := context.TODO() +id := exportpipelines.NewExportPipelineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "exportPipelineName") + +payload := exportpipelines.ExportPipeline{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ExportPipelinesClient.Delete` + +```go +ctx := context.TODO() +id := exportpipelines.NewExportPipelineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "exportPipelineName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ExportPipelinesClient.Get` + +```go +ctx := context.TODO() +id := exportpipelines.NewExportPipelineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "exportPipelineName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ExportPipelinesClient.List` + +```go +ctx := context.TODO() +id := exportpipelines.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/client.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/client.go new file mode 100644 index 00000000000..2762c473627 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/client.go @@ -0,0 +1,26 @@ +package exportpipelines + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportPipelinesClient struct { + Client *resourcemanager.Client +} + +func NewExportPipelinesClientWithBaseURI(sdkApi sdkEnv.Api) (*ExportPipelinesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "exportpipelines", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ExportPipelinesClient: %+v", err) + } + + return &ExportPipelinesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/constants.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/constants.go new file mode 100644 index 00000000000..fc874650d50 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/constants.go @@ -0,0 +1,110 @@ +package exportpipelines + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineOptions string + +const ( + PipelineOptionsContinueOnErrors PipelineOptions = "ContinueOnErrors" + PipelineOptionsDeleteSourceBlobOnSuccess PipelineOptions = "DeleteSourceBlobOnSuccess" + PipelineOptionsOverwriteBlobs PipelineOptions = "OverwriteBlobs" + PipelineOptionsOverwriteTags PipelineOptions = "OverwriteTags" +) + +func PossibleValuesForPipelineOptions() []string { + return []string{ + string(PipelineOptionsContinueOnErrors), + string(PipelineOptionsDeleteSourceBlobOnSuccess), + string(PipelineOptionsOverwriteBlobs), + string(PipelineOptionsOverwriteTags), + } +} + +func (s *PipelineOptions) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePipelineOptions(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePipelineOptions(input string) (*PipelineOptions, error) { + vals := map[string]PipelineOptions{ + "continueonerrors": PipelineOptionsContinueOnErrors, + "deletesourceblobonsuccess": PipelineOptionsDeleteSourceBlobOnSuccess, + "overwriteblobs": PipelineOptionsOverwriteBlobs, + "overwritetags": PipelineOptionsOverwriteTags, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PipelineOptions(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_exportpipeline.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_exportpipeline.go new file mode 100644 index 00000000000..ded876f133e --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_exportpipeline.go @@ -0,0 +1,139 @@ +package exportpipelines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ExportPipelineId{}) +} + +var _ resourceids.ResourceId = &ExportPipelineId{} + +// ExportPipelineId is a struct representing the Resource ID for a Export Pipeline +type ExportPipelineId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + ExportPipelineName string +} + +// NewExportPipelineID returns a new ExportPipelineId struct +func NewExportPipelineID(subscriptionId string, resourceGroupName string, registryName string, exportPipelineName string) ExportPipelineId { + return ExportPipelineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + ExportPipelineName: exportPipelineName, + } +} + +// ParseExportPipelineID parses 'input' into a ExportPipelineId +func ParseExportPipelineID(input string) (*ExportPipelineId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExportPipelineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExportPipelineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseExportPipelineIDInsensitively parses 'input' case-insensitively into a ExportPipelineId +// note: this method should only be used for API response data and not user input +func ParseExportPipelineIDInsensitively(input string) (*ExportPipelineId, error) { + parser := resourceids.NewParserFromResourceIdType(&ExportPipelineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ExportPipelineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ExportPipelineId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.ExportPipelineName, ok = input.Parsed["exportPipelineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "exportPipelineName", input) + } + + return nil +} + +// ValidateExportPipelineID checks that 'input' can be parsed as a Export Pipeline ID +func ValidateExportPipelineID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseExportPipelineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Export Pipeline ID +func (id ExportPipelineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/exportPipelines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.ExportPipelineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Export Pipeline ID +func (id ExportPipelineId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticExportPipelines", "exportPipelines", "exportPipelines"), + resourceids.UserSpecifiedSegment("exportPipelineName", "exportPipelineName"), + } +} + +// String returns a human-readable description of this Export Pipeline ID +func (id ExportPipelineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Export Pipeline Name: %q", id.ExportPipelineName), + } + return fmt.Sprintf("Export Pipeline (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_exportpipeline_test.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_exportpipeline_test.go new file mode 100644 index 00000000000..ae2491f30db --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_exportpipeline_test.go @@ -0,0 +1,327 @@ +package exportpipelines + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ExportPipelineId{} + +func TestNewExportPipelineID(t *testing.T) { + id := NewExportPipelineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "exportPipelineName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.ExportPipelineName != "exportPipelineName" { + t.Fatalf("Expected %q but got %q for Segment 'ExportPipelineName'", id.ExportPipelineName, "exportPipelineName") + } +} + +func TestFormatExportPipelineID(t *testing.T) { + actual := NewExportPipelineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "exportPipelineName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/exportPipelines/exportPipelineName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseExportPipelineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExportPipelineId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/exportPipelines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/exportPipelines/exportPipelineName", + Expected: &ExportPipelineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + ExportPipelineName: "exportPipelineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/exportPipelines/exportPipelineName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExportPipelineID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.ExportPipelineName != v.Expected.ExportPipelineName { + t.Fatalf("Expected %q but got %q for ExportPipelineName", v.Expected.ExportPipelineName, actual.ExportPipelineName) + } + + } +} + +func TestParseExportPipelineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ExportPipelineId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/exportPipelines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/eXpOrTpIpElInEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/exportPipelines/exportPipelineName", + Expected: &ExportPipelineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + ExportPipelineName: "exportPipelineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/exportPipelines/exportPipelineName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/eXpOrTpIpElInEs/eXpOrTpIpElInEnAmE", + Expected: &ExportPipelineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + ExportPipelineName: "eXpOrTpIpElInEnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/eXpOrTpIpElInEs/eXpOrTpIpElInEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseExportPipelineIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.ExportPipelineName != v.Expected.ExportPipelineName { + t.Fatalf("Expected %q but got %q for ExportPipelineName", v.Expected.ExportPipelineName, actual.ExportPipelineName) + } + + } +} + +func TestSegmentsForExportPipelineId(t *testing.T) { + segments := ExportPipelineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ExportPipelineId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_registry.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_registry.go new file mode 100644 index 00000000000..e16e6721741 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_registry.go @@ -0,0 +1,130 @@ +package exportpipelines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RegistryId{}) +} + +var _ resourceids.ResourceId = &RegistryId{} + +// RegistryId is a struct representing the Resource ID for a Registry +type RegistryId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string +} + +// NewRegistryID returns a new RegistryId struct +func NewRegistryID(subscriptionId string, resourceGroupName string, registryName string) RegistryId { + return RegistryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + } +} + +// ParseRegistryID parses 'input' into a RegistryId +func ParseRegistryID(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRegistryIDInsensitively parses 'input' case-insensitively into a RegistryId +// note: this method should only be used for API response data and not user input +func ParseRegistryIDInsensitively(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RegistryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + return nil +} + +// ValidateRegistryID checks that 'input' can be parsed as a Registry ID +func ValidateRegistryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRegistryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Registry ID +func (id RegistryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Registry ID +func (id RegistryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + } +} + +// String returns a human-readable description of this Registry ID +func (id RegistryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + } + return fmt.Sprintf("Registry (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_registry_test.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_registry_test.go new file mode 100644 index 00000000000..11d56df5011 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/id_registry_test.go @@ -0,0 +1,282 @@ +package exportpipelines + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RegistryId{} + +func TestNewRegistryID(t *testing.T) { + id := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } +} + +func TestFormatRegistryID(t *testing.T) { + actual := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRegistryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestParseRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestSegmentsForRegistryId(t *testing.T) { + segments := RegistryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RegistryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_create.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_create.go new file mode 100644 index 00000000000..ff9553140e6 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_create.go @@ -0,0 +1,75 @@ +package exportpipelines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ExportPipeline +} + +// Create ... +func (c ExportPipelinesClient) Create(ctx context.Context, id ExportPipelineId, input ExportPipeline) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ExportPipelinesClient) CreateThenPoll(ctx context.Context, id ExportPipelineId, input ExportPipeline) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_delete.go new file mode 100644 index 00000000000..bf53e4c4264 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_delete.go @@ -0,0 +1,71 @@ +package exportpipelines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ExportPipelinesClient) Delete(ctx context.Context, id ExportPipelineId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ExportPipelinesClient) DeleteThenPoll(ctx context.Context, id ExportPipelineId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_get.go new file mode 100644 index 00000000000..fc95722aa94 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_get.go @@ -0,0 +1,53 @@ +package exportpipelines + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ExportPipeline +} + +// Get ... +func (c ExportPipelinesClient) Get(ctx context.Context, id ExportPipelineId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ExportPipeline + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_list.go new file mode 100644 index 00000000000..69b38c5ad45 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/method_list.go @@ -0,0 +1,105 @@ +package exportpipelines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ExportPipeline +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ExportPipeline +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ExportPipelinesClient) List(ctx context.Context, id RegistryId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/exportPipelines", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ExportPipeline `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ExportPipelinesClient) ListComplete(ctx context.Context, id RegistryId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ExportPipelineOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ExportPipelinesClient) ListCompleteMatchingPredicate(ctx context.Context, id RegistryId, predicate ExportPipelineOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ExportPipeline, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/model_exportpipeline.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/model_exportpipeline.go new file mode 100644 index 00000000000..6bdf3334dff --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/model_exportpipeline.go @@ -0,0 +1,19 @@ +package exportpipelines + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportPipeline struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ExportPipelineProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/model_exportpipelineproperties.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/model_exportpipelineproperties.go new file mode 100644 index 00000000000..32e1fc4359b --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/model_exportpipelineproperties.go @@ -0,0 +1,10 @@ +package exportpipelines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportPipelineProperties struct { + Options *[]PipelineOptions `json:"options,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + Target ExportPipelineTargetProperties `json:"target"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/model_exportpipelinetargetproperties.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/model_exportpipelinetargetproperties.go new file mode 100644 index 00000000000..b9038edd5f4 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/model_exportpipelinetargetproperties.go @@ -0,0 +1,10 @@ +package exportpipelines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportPipelineTargetProperties struct { + KeyVaultUri string `json:"keyVaultUri"` + Type *string `json:"type,omitempty"` + Uri *string `json:"uri,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/predicates.go new file mode 100644 index 00000000000..f7a0a3584b0 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/predicates.go @@ -0,0 +1,32 @@ +package exportpipelines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportPipelineOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ExportPipelineOperationPredicate) Matches(input ExportPipeline) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/version.go b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/version.go new file mode 100644 index 00000000000..69301112eab --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/exportpipelines/version.go @@ -0,0 +1,10 @@ +package exportpipelines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/exportpipelines/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/README.md b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/README.md new file mode 100644 index 00000000000..eae9ec27d02 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/importpipelines` Documentation + +The `importpipelines` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/importpipelines" +``` + + +### Client Initialization + +```go +client := importpipelines.NewImportPipelinesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ImportPipelinesClient.Create` + +```go +ctx := context.TODO() +id := importpipelines.NewImportPipelineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "importPipelineName") + +payload := importpipelines.ImportPipeline{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ImportPipelinesClient.Delete` + +```go +ctx := context.TODO() +id := importpipelines.NewImportPipelineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "importPipelineName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ImportPipelinesClient.Get` + +```go +ctx := context.TODO() +id := importpipelines.NewImportPipelineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "importPipelineName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ImportPipelinesClient.List` + +```go +ctx := context.TODO() +id := importpipelines.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/client.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/client.go new file mode 100644 index 00000000000..ef442ee8ef8 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/client.go @@ -0,0 +1,26 @@ +package importpipelines + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportPipelinesClient struct { + Client *resourcemanager.Client +} + +func NewImportPipelinesClientWithBaseURI(sdkApi sdkEnv.Api) (*ImportPipelinesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "importpipelines", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ImportPipelinesClient: %+v", err) + } + + return &ImportPipelinesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/constants.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/constants.go new file mode 100644 index 00000000000..96dac242623 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/constants.go @@ -0,0 +1,189 @@ +package importpipelines + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineOptions string + +const ( + PipelineOptionsContinueOnErrors PipelineOptions = "ContinueOnErrors" + PipelineOptionsDeleteSourceBlobOnSuccess PipelineOptions = "DeleteSourceBlobOnSuccess" + PipelineOptionsOverwriteBlobs PipelineOptions = "OverwriteBlobs" + PipelineOptionsOverwriteTags PipelineOptions = "OverwriteTags" +) + +func PossibleValuesForPipelineOptions() []string { + return []string{ + string(PipelineOptionsContinueOnErrors), + string(PipelineOptionsDeleteSourceBlobOnSuccess), + string(PipelineOptionsOverwriteBlobs), + string(PipelineOptionsOverwriteTags), + } +} + +func (s *PipelineOptions) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePipelineOptions(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePipelineOptions(input string) (*PipelineOptions, error) { + vals := map[string]PipelineOptions{ + "continueonerrors": PipelineOptionsContinueOnErrors, + "deletesourceblobonsuccess": PipelineOptionsDeleteSourceBlobOnSuccess, + "overwriteblobs": PipelineOptionsOverwriteBlobs, + "overwritetags": PipelineOptionsOverwriteTags, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PipelineOptions(input) + return &out, nil +} + +type PipelineSourceType string + +const ( + PipelineSourceTypeAzureStorageBlobContainer PipelineSourceType = "AzureStorageBlobContainer" +) + +func PossibleValuesForPipelineSourceType() []string { + return []string{ + string(PipelineSourceTypeAzureStorageBlobContainer), + } +} + +func (s *PipelineSourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePipelineSourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePipelineSourceType(input string) (*PipelineSourceType, error) { + vals := map[string]PipelineSourceType{ + "azurestorageblobcontainer": PipelineSourceTypeAzureStorageBlobContainer, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PipelineSourceType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type TriggerStatus string + +const ( + TriggerStatusDisabled TriggerStatus = "Disabled" + TriggerStatusEnabled TriggerStatus = "Enabled" +) + +func PossibleValuesForTriggerStatus() []string { + return []string{ + string(TriggerStatusDisabled), + string(TriggerStatusEnabled), + } +} + +func (s *TriggerStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTriggerStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTriggerStatus(input string) (*TriggerStatus, error) { + vals := map[string]TriggerStatus{ + "disabled": TriggerStatusDisabled, + "enabled": TriggerStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TriggerStatus(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_importpipeline.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_importpipeline.go new file mode 100644 index 00000000000..980990c866b --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_importpipeline.go @@ -0,0 +1,139 @@ +package importpipelines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ImportPipelineId{}) +} + +var _ resourceids.ResourceId = &ImportPipelineId{} + +// ImportPipelineId is a struct representing the Resource ID for a Import Pipeline +type ImportPipelineId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + ImportPipelineName string +} + +// NewImportPipelineID returns a new ImportPipelineId struct +func NewImportPipelineID(subscriptionId string, resourceGroupName string, registryName string, importPipelineName string) ImportPipelineId { + return ImportPipelineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + ImportPipelineName: importPipelineName, + } +} + +// ParseImportPipelineID parses 'input' into a ImportPipelineId +func ParseImportPipelineID(input string) (*ImportPipelineId, error) { + parser := resourceids.NewParserFromResourceIdType(&ImportPipelineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ImportPipelineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseImportPipelineIDInsensitively parses 'input' case-insensitively into a ImportPipelineId +// note: this method should only be used for API response data and not user input +func ParseImportPipelineIDInsensitively(input string) (*ImportPipelineId, error) { + parser := resourceids.NewParserFromResourceIdType(&ImportPipelineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ImportPipelineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ImportPipelineId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.ImportPipelineName, ok = input.Parsed["importPipelineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "importPipelineName", input) + } + + return nil +} + +// ValidateImportPipelineID checks that 'input' can be parsed as a Import Pipeline ID +func ValidateImportPipelineID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseImportPipelineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Import Pipeline ID +func (id ImportPipelineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/importPipelines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.ImportPipelineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Import Pipeline ID +func (id ImportPipelineId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticImportPipelines", "importPipelines", "importPipelines"), + resourceids.UserSpecifiedSegment("importPipelineName", "importPipelineName"), + } +} + +// String returns a human-readable description of this Import Pipeline ID +func (id ImportPipelineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Import Pipeline Name: %q", id.ImportPipelineName), + } + return fmt.Sprintf("Import Pipeline (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_importpipeline_test.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_importpipeline_test.go new file mode 100644 index 00000000000..ab9b8415ebc --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_importpipeline_test.go @@ -0,0 +1,327 @@ +package importpipelines + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ImportPipelineId{} + +func TestNewImportPipelineID(t *testing.T) { + id := NewImportPipelineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "importPipelineName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.ImportPipelineName != "importPipelineName" { + t.Fatalf("Expected %q but got %q for Segment 'ImportPipelineName'", id.ImportPipelineName, "importPipelineName") + } +} + +func TestFormatImportPipelineID(t *testing.T) { + actual := NewImportPipelineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "importPipelineName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/importPipelines/importPipelineName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseImportPipelineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ImportPipelineId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/importPipelines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/importPipelines/importPipelineName", + Expected: &ImportPipelineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + ImportPipelineName: "importPipelineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/importPipelines/importPipelineName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseImportPipelineID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.ImportPipelineName != v.Expected.ImportPipelineName { + t.Fatalf("Expected %q but got %q for ImportPipelineName", v.Expected.ImportPipelineName, actual.ImportPipelineName) + } + + } +} + +func TestParseImportPipelineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ImportPipelineId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/importPipelines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/iMpOrTpIpElInEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/importPipelines/importPipelineName", + Expected: &ImportPipelineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + ImportPipelineName: "importPipelineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/importPipelines/importPipelineName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/iMpOrTpIpElInEs/iMpOrTpIpElInEnAmE", + Expected: &ImportPipelineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + ImportPipelineName: "iMpOrTpIpElInEnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/iMpOrTpIpElInEs/iMpOrTpIpElInEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseImportPipelineIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.ImportPipelineName != v.Expected.ImportPipelineName { + t.Fatalf("Expected %q but got %q for ImportPipelineName", v.Expected.ImportPipelineName, actual.ImportPipelineName) + } + + } +} + +func TestSegmentsForImportPipelineId(t *testing.T) { + segments := ImportPipelineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ImportPipelineId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_registry.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_registry.go new file mode 100644 index 00000000000..273a48c845d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_registry.go @@ -0,0 +1,130 @@ +package importpipelines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RegistryId{}) +} + +var _ resourceids.ResourceId = &RegistryId{} + +// RegistryId is a struct representing the Resource ID for a Registry +type RegistryId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string +} + +// NewRegistryID returns a new RegistryId struct +func NewRegistryID(subscriptionId string, resourceGroupName string, registryName string) RegistryId { + return RegistryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + } +} + +// ParseRegistryID parses 'input' into a RegistryId +func ParseRegistryID(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRegistryIDInsensitively parses 'input' case-insensitively into a RegistryId +// note: this method should only be used for API response data and not user input +func ParseRegistryIDInsensitively(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RegistryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + return nil +} + +// ValidateRegistryID checks that 'input' can be parsed as a Registry ID +func ValidateRegistryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRegistryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Registry ID +func (id RegistryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Registry ID +func (id RegistryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + } +} + +// String returns a human-readable description of this Registry ID +func (id RegistryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + } + return fmt.Sprintf("Registry (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_registry_test.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_registry_test.go new file mode 100644 index 00000000000..84c73eb18b3 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/id_registry_test.go @@ -0,0 +1,282 @@ +package importpipelines + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RegistryId{} + +func TestNewRegistryID(t *testing.T) { + id := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } +} + +func TestFormatRegistryID(t *testing.T) { + actual := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRegistryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestParseRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestSegmentsForRegistryId(t *testing.T) { + segments := RegistryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RegistryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_create.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_create.go new file mode 100644 index 00000000000..1646d54c8b2 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_create.go @@ -0,0 +1,75 @@ +package importpipelines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ImportPipeline +} + +// Create ... +func (c ImportPipelinesClient) Create(ctx context.Context, id ImportPipelineId, input ImportPipeline) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ImportPipelinesClient) CreateThenPoll(ctx context.Context, id ImportPipelineId, input ImportPipeline) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_delete.go new file mode 100644 index 00000000000..c2a97938994 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_delete.go @@ -0,0 +1,71 @@ +package importpipelines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ImportPipelinesClient) Delete(ctx context.Context, id ImportPipelineId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ImportPipelinesClient) DeleteThenPoll(ctx context.Context, id ImportPipelineId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_get.go new file mode 100644 index 00000000000..d392563356d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_get.go @@ -0,0 +1,53 @@ +package importpipelines + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ImportPipeline +} + +// Get ... +func (c ImportPipelinesClient) Get(ctx context.Context, id ImportPipelineId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ImportPipeline + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_list.go new file mode 100644 index 00000000000..01c65aef568 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/method_list.go @@ -0,0 +1,105 @@ +package importpipelines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ImportPipeline +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ImportPipeline +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ImportPipelinesClient) List(ctx context.Context, id RegistryId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/importPipelines", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ImportPipeline `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ImportPipelinesClient) ListComplete(ctx context.Context, id RegistryId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ImportPipelineOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ImportPipelinesClient) ListCompleteMatchingPredicate(ctx context.Context, id RegistryId, predicate ImportPipelineOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ImportPipeline, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_importpipeline.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_importpipeline.go new file mode 100644 index 00000000000..d6d3c5f4a49 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_importpipeline.go @@ -0,0 +1,19 @@ +package importpipelines + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportPipeline struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ImportPipelineProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_importpipelineproperties.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_importpipelineproperties.go new file mode 100644 index 00000000000..fd6608aa0db --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_importpipelineproperties.go @@ -0,0 +1,11 @@ +package importpipelines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportPipelineProperties struct { + Options *[]PipelineOptions `json:"options,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + Source ImportPipelineSourceProperties `json:"source"` + Trigger *PipelineTriggerProperties `json:"trigger,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_importpipelinesourceproperties.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_importpipelinesourceproperties.go new file mode 100644 index 00000000000..e4610a61665 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_importpipelinesourceproperties.go @@ -0,0 +1,10 @@ +package importpipelines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportPipelineSourceProperties struct { + KeyVaultUri string `json:"keyVaultUri"` + Type *PipelineSourceType `json:"type,omitempty"` + Uri *string `json:"uri,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_pipelinesourcetriggerproperties.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_pipelinesourcetriggerproperties.go new file mode 100644 index 00000000000..37b09a34cbb --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_pipelinesourcetriggerproperties.go @@ -0,0 +1,8 @@ +package importpipelines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineSourceTriggerProperties struct { + Status TriggerStatus `json:"status"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_pipelinetriggerproperties.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_pipelinetriggerproperties.go new file mode 100644 index 00000000000..fe8e8923df5 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/model_pipelinetriggerproperties.go @@ -0,0 +1,8 @@ +package importpipelines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineTriggerProperties struct { + SourceTrigger *PipelineSourceTriggerProperties `json:"sourceTrigger,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/predicates.go new file mode 100644 index 00000000000..2d0ba9d965e --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/predicates.go @@ -0,0 +1,32 @@ +package importpipelines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportPipelineOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ImportPipelineOperationPredicate) Matches(input ImportPipeline) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/importpipelines/version.go b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/version.go new file mode 100644 index 00000000000..9a63a61ed05 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/importpipelines/version.go @@ -0,0 +1,10 @@ +package importpipelines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/importpipelines/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/operation/README.md b/resource-manager/containerregistry/2023-11-01-preview/operation/README.md new file mode 100644 index 00000000000..4f6c04d9ef1 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/operation/README.md @@ -0,0 +1,42 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/operation` Documentation + +The `operation` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/operation" +``` + + +### Client Initialization + +```go +client := operation.NewOperationClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `OperationClient.RegistriesCheckNameAvailability` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := operation.RegistryNameCheckRequest{ + // ... +} + + +read, err := client.RegistriesCheckNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/operation/client.go b/resource-manager/containerregistry/2023-11-01-preview/operation/client.go new file mode 100644 index 00000000000..d7880ff0414 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/operation/client.go @@ -0,0 +1,26 @@ +package operation + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationClient struct { + Client *resourcemanager.Client +} + +func NewOperationClientWithBaseURI(sdkApi sdkEnv.Api) (*OperationClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "operation", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating OperationClient: %+v", err) + } + + return &OperationClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/operation/constants.go b/resource-manager/containerregistry/2023-11-01-preview/operation/constants.go new file mode 100644 index 00000000000..9582d637d75 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/operation/constants.go @@ -0,0 +1,48 @@ +package operation + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerRegistryResourceType string + +const ( + ContainerRegistryResourceTypeMicrosoftPointContainerRegistryRegistries ContainerRegistryResourceType = "Microsoft.ContainerRegistry/registries" +) + +func PossibleValuesForContainerRegistryResourceType() []string { + return []string{ + string(ContainerRegistryResourceTypeMicrosoftPointContainerRegistryRegistries), + } +} + +func (s *ContainerRegistryResourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContainerRegistryResourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseContainerRegistryResourceType(input string) (*ContainerRegistryResourceType, error) { + vals := map[string]ContainerRegistryResourceType{ + "microsoft.containerregistry/registries": ContainerRegistryResourceTypeMicrosoftPointContainerRegistryRegistries, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ContainerRegistryResourceType(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/operation/method_registrieschecknameavailability.go b/resource-manager/containerregistry/2023-11-01-preview/operation/method_registrieschecknameavailability.go new file mode 100644 index 00000000000..971af5b4587 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/operation/method_registrieschecknameavailability.go @@ -0,0 +1,59 @@ +package operation + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistriesCheckNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RegistryNameStatus +} + +// RegistriesCheckNameAvailability ... +func (c OperationClient) RegistriesCheckNameAvailability(ctx context.Context, id commonids.SubscriptionId, input RegistryNameCheckRequest) (result RegistriesCheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.ContainerRegistry/checkNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RegistryNameStatus + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/operation/model_registrynamecheckrequest.go b/resource-manager/containerregistry/2023-11-01-preview/operation/model_registrynamecheckrequest.go new file mode 100644 index 00000000000..1f540d0ab5e --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/operation/model_registrynamecheckrequest.go @@ -0,0 +1,9 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryNameCheckRequest struct { + Name string `json:"name"` + Type ContainerRegistryResourceType `json:"type"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/operation/model_registrynamestatus.go b/resource-manager/containerregistry/2023-11-01-preview/operation/model_registrynamestatus.go new file mode 100644 index 00000000000..cd64ec3c5fe --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/operation/model_registrynamestatus.go @@ -0,0 +1,10 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryNameStatus struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *string `json:"reason,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/operation/version.go b/resource-manager/containerregistry/2023-11-01-preview/operation/version.go new file mode 100644 index 00000000000..95b72e73097 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/operation/version.go @@ -0,0 +1,10 @@ +package operation + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/operation/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/README.md b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/README.md new file mode 100644 index 00000000000..fcb01245a9f --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/pipelineruns` Documentation + +The `pipelineruns` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/pipelineruns" +``` + + +### Client Initialization + +```go +client := pipelineruns.NewPipelineRunsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PipelineRunsClient.Create` + +```go +ctx := context.TODO() +id := pipelineruns.NewPipelineRunID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "pipelineRunName") + +payload := pipelineruns.PipelineRun{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PipelineRunsClient.Delete` + +```go +ctx := context.TODO() +id := pipelineruns.NewPipelineRunID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "pipelineRunName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PipelineRunsClient.Get` + +```go +ctx := context.TODO() +id := pipelineruns.NewPipelineRunID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "pipelineRunName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PipelineRunsClient.List` + +```go +ctx := context.TODO() +id := pipelineruns.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/client.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/client.go new file mode 100644 index 00000000000..f5e877b401a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/client.go @@ -0,0 +1,26 @@ +package pipelineruns + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineRunsClient struct { + Client *resourcemanager.Client +} + +func NewPipelineRunsClientWithBaseURI(sdkApi sdkEnv.Api) (*PipelineRunsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "pipelineruns", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PipelineRunsClient: %+v", err) + } + + return &PipelineRunsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/constants.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/constants.go new file mode 100644 index 00000000000..dc8aba16c43 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/constants.go @@ -0,0 +1,177 @@ +package pipelineruns + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineRunSourceType string + +const ( + PipelineRunSourceTypeAzureStorageBlob PipelineRunSourceType = "AzureStorageBlob" +) + +func PossibleValuesForPipelineRunSourceType() []string { + return []string{ + string(PipelineRunSourceTypeAzureStorageBlob), + } +} + +func (s *PipelineRunSourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePipelineRunSourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePipelineRunSourceType(input string) (*PipelineRunSourceType, error) { + vals := map[string]PipelineRunSourceType{ + "azurestorageblob": PipelineRunSourceTypeAzureStorageBlob, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PipelineRunSourceType(input) + return &out, nil +} + +type PipelineRunTargetType string + +const ( + PipelineRunTargetTypeAzureStorageBlob PipelineRunTargetType = "AzureStorageBlob" +) + +func PossibleValuesForPipelineRunTargetType() []string { + return []string{ + string(PipelineRunTargetTypeAzureStorageBlob), + } +} + +func (s *PipelineRunTargetType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePipelineRunTargetType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePipelineRunTargetType(input string) (*PipelineRunTargetType, error) { + vals := map[string]PipelineRunTargetType{ + "azurestorageblob": PipelineRunTargetTypeAzureStorageBlob, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PipelineRunTargetType(input) + return &out, nil +} + +type PipelineSourceType string + +const ( + PipelineSourceTypeAzureStorageBlobContainer PipelineSourceType = "AzureStorageBlobContainer" +) + +func PossibleValuesForPipelineSourceType() []string { + return []string{ + string(PipelineSourceTypeAzureStorageBlobContainer), + } +} + +func (s *PipelineSourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePipelineSourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePipelineSourceType(input string) (*PipelineSourceType, error) { + vals := map[string]PipelineSourceType{ + "azurestorageblobcontainer": PipelineSourceTypeAzureStorageBlobContainer, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PipelineSourceType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_pipelinerun.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_pipelinerun.go new file mode 100644 index 00000000000..c00c3b469c7 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_pipelinerun.go @@ -0,0 +1,139 @@ +package pipelineruns + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PipelineRunId{}) +} + +var _ resourceids.ResourceId = &PipelineRunId{} + +// PipelineRunId is a struct representing the Resource ID for a Pipeline Run +type PipelineRunId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + PipelineRunName string +} + +// NewPipelineRunID returns a new PipelineRunId struct +func NewPipelineRunID(subscriptionId string, resourceGroupName string, registryName string, pipelineRunName string) PipelineRunId { + return PipelineRunId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + PipelineRunName: pipelineRunName, + } +} + +// ParsePipelineRunID parses 'input' into a PipelineRunId +func ParsePipelineRunID(input string) (*PipelineRunId, error) { + parser := resourceids.NewParserFromResourceIdType(&PipelineRunId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PipelineRunId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePipelineRunIDInsensitively parses 'input' case-insensitively into a PipelineRunId +// note: this method should only be used for API response data and not user input +func ParsePipelineRunIDInsensitively(input string) (*PipelineRunId, error) { + parser := resourceids.NewParserFromResourceIdType(&PipelineRunId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PipelineRunId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PipelineRunId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.PipelineRunName, ok = input.Parsed["pipelineRunName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "pipelineRunName", input) + } + + return nil +} + +// ValidatePipelineRunID checks that 'input' can be parsed as a Pipeline Run ID +func ValidatePipelineRunID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePipelineRunID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Pipeline Run ID +func (id PipelineRunId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/pipelineRuns/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.PipelineRunName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Pipeline Run ID +func (id PipelineRunId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticPipelineRuns", "pipelineRuns", "pipelineRuns"), + resourceids.UserSpecifiedSegment("pipelineRunName", "pipelineRunName"), + } +} + +// String returns a human-readable description of this Pipeline Run ID +func (id PipelineRunId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Pipeline Run Name: %q", id.PipelineRunName), + } + return fmt.Sprintf("Pipeline Run (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_pipelinerun_test.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_pipelinerun_test.go new file mode 100644 index 00000000000..e6e18d94fbe --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_pipelinerun_test.go @@ -0,0 +1,327 @@ +package pipelineruns + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PipelineRunId{} + +func TestNewPipelineRunID(t *testing.T) { + id := NewPipelineRunID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "pipelineRunName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.PipelineRunName != "pipelineRunName" { + t.Fatalf("Expected %q but got %q for Segment 'PipelineRunName'", id.PipelineRunName, "pipelineRunName") + } +} + +func TestFormatPipelineRunID(t *testing.T) { + actual := NewPipelineRunID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "pipelineRunName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/pipelineRuns/pipelineRunName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePipelineRunID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PipelineRunId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/pipelineRuns", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/pipelineRuns/pipelineRunName", + Expected: &PipelineRunId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PipelineRunName: "pipelineRunName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/pipelineRuns/pipelineRunName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePipelineRunID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PipelineRunName != v.Expected.PipelineRunName { + t.Fatalf("Expected %q but got %q for PipelineRunName", v.Expected.PipelineRunName, actual.PipelineRunName) + } + + } +} + +func TestParsePipelineRunIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PipelineRunId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/pipelineRuns", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pIpElInErUnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/pipelineRuns/pipelineRunName", + Expected: &PipelineRunId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PipelineRunName: "pipelineRunName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/pipelineRuns/pipelineRunName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pIpElInErUnS/pIpElInErUnNaMe", + Expected: &PipelineRunId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + PipelineRunName: "pIpElInErUnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pIpElInErUnS/pIpElInErUnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePipelineRunIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PipelineRunName != v.Expected.PipelineRunName { + t.Fatalf("Expected %q but got %q for PipelineRunName", v.Expected.PipelineRunName, actual.PipelineRunName) + } + + } +} + +func TestSegmentsForPipelineRunId(t *testing.T) { + segments := PipelineRunId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PipelineRunId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_registry.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_registry.go new file mode 100644 index 00000000000..33472048744 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_registry.go @@ -0,0 +1,130 @@ +package pipelineruns + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RegistryId{}) +} + +var _ resourceids.ResourceId = &RegistryId{} + +// RegistryId is a struct representing the Resource ID for a Registry +type RegistryId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string +} + +// NewRegistryID returns a new RegistryId struct +func NewRegistryID(subscriptionId string, resourceGroupName string, registryName string) RegistryId { + return RegistryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + } +} + +// ParseRegistryID parses 'input' into a RegistryId +func ParseRegistryID(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRegistryIDInsensitively parses 'input' case-insensitively into a RegistryId +// note: this method should only be used for API response data and not user input +func ParseRegistryIDInsensitively(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RegistryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + return nil +} + +// ValidateRegistryID checks that 'input' can be parsed as a Registry ID +func ValidateRegistryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRegistryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Registry ID +func (id RegistryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Registry ID +func (id RegistryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + } +} + +// String returns a human-readable description of this Registry ID +func (id RegistryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + } + return fmt.Sprintf("Registry (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_registry_test.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_registry_test.go new file mode 100644 index 00000000000..5016963e063 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/id_registry_test.go @@ -0,0 +1,282 @@ +package pipelineruns + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RegistryId{} + +func TestNewRegistryID(t *testing.T) { + id := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } +} + +func TestFormatRegistryID(t *testing.T) { + actual := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRegistryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestParseRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestSegmentsForRegistryId(t *testing.T) { + segments := RegistryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RegistryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_create.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_create.go new file mode 100644 index 00000000000..14f4b6404ec --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_create.go @@ -0,0 +1,75 @@ +package pipelineruns + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PipelineRun +} + +// Create ... +func (c PipelineRunsClient) Create(ctx context.Context, id PipelineRunId, input PipelineRun) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c PipelineRunsClient) CreateThenPoll(ctx context.Context, id PipelineRunId, input PipelineRun) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_delete.go new file mode 100644 index 00000000000..053ce6b4c7b --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_delete.go @@ -0,0 +1,71 @@ +package pipelineruns + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c PipelineRunsClient) Delete(ctx context.Context, id PipelineRunId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PipelineRunsClient) DeleteThenPoll(ctx context.Context, id PipelineRunId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_get.go new file mode 100644 index 00000000000..572b20c19cd --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_get.go @@ -0,0 +1,53 @@ +package pipelineruns + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PipelineRun +} + +// Get ... +func (c PipelineRunsClient) Get(ctx context.Context, id PipelineRunId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PipelineRun + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_list.go new file mode 100644 index 00000000000..f4121f68882 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/method_list.go @@ -0,0 +1,105 @@ +package pipelineruns + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PipelineRun +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PipelineRun +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c PipelineRunsClient) List(ctx context.Context, id RegistryId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/pipelineRuns", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PipelineRun `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c PipelineRunsClient) ListComplete(ctx context.Context, id RegistryId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, PipelineRunOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PipelineRunsClient) ListCompleteMatchingPredicate(ctx context.Context, id RegistryId, predicate PipelineRunOperationPredicate) (result ListCompleteResult, err error) { + items := make([]PipelineRun, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_exportpipelinetargetproperties.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_exportpipelinetargetproperties.go new file mode 100644 index 00000000000..74e183e7b37 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_exportpipelinetargetproperties.go @@ -0,0 +1,10 @@ +package pipelineruns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportPipelineTargetProperties struct { + KeyVaultUri string `json:"keyVaultUri"` + Type *string `json:"type,omitempty"` + Uri *string `json:"uri,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_importpipelinesourceproperties.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_importpipelinesourceproperties.go new file mode 100644 index 00000000000..27193aa15d0 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_importpipelinesourceproperties.go @@ -0,0 +1,10 @@ +package pipelineruns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportPipelineSourceProperties struct { + KeyVaultUri string `json:"keyVaultUri"` + Type *PipelineSourceType `json:"type,omitempty"` + Uri *string `json:"uri,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerun.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerun.go new file mode 100644 index 00000000000..2df653ea7f1 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerun.go @@ -0,0 +1,16 @@ +package pipelineruns + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineRun struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PipelineRunProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunproperties.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunproperties.go new file mode 100644 index 00000000000..f555d50364d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunproperties.go @@ -0,0 +1,11 @@ +package pipelineruns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineRunProperties struct { + ForceUpdateTag *string `json:"forceUpdateTag,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + Request *PipelineRunRequest `json:"request,omitempty"` + Response *PipelineRunResponse `json:"response,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunrequest.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunrequest.go new file mode 100644 index 00000000000..11968633a77 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunrequest.go @@ -0,0 +1,12 @@ +package pipelineruns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineRunRequest struct { + Artifacts *[]string `json:"artifacts,omitempty"` + CatalogDigest *string `json:"catalogDigest,omitempty"` + PipelineResourceId *string `json:"pipelineResourceId,omitempty"` + Source *PipelineRunSourceProperties `json:"source,omitempty"` + Target *PipelineRunTargetProperties `json:"target,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunresponse.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunresponse.go new file mode 100644 index 00000000000..7e8b9bea21d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunresponse.go @@ -0,0 +1,47 @@ +package pipelineruns + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineRunResponse struct { + CatalogDigest *string `json:"catalogDigest,omitempty"` + FinishTime *string `json:"finishTime,omitempty"` + ImportedArtifacts *[]string `json:"importedArtifacts,omitempty"` + PipelineRunErrorMessage *string `json:"pipelineRunErrorMessage,omitempty"` + Progress *ProgressProperties `json:"progress,omitempty"` + Source *ImportPipelineSourceProperties `json:"source,omitempty"` + StartTime *string `json:"startTime,omitempty"` + Status *string `json:"status,omitempty"` + Target *ExportPipelineTargetProperties `json:"target,omitempty"` + Trigger *PipelineTriggerDescriptor `json:"trigger,omitempty"` +} + +func (o *PipelineRunResponse) GetFinishTimeAsTime() (*time.Time, error) { + if o.FinishTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.FinishTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *PipelineRunResponse) SetFinishTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.FinishTime = &formatted +} + +func (o *PipelineRunResponse) GetStartTimeAsTime() (*time.Time, error) { + if o.StartTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *PipelineRunResponse) SetStartTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartTime = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunsourceproperties.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunsourceproperties.go new file mode 100644 index 00000000000..60eae9b2a4c --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinerunsourceproperties.go @@ -0,0 +1,9 @@ +package pipelineruns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineRunSourceProperties struct { + Name *string `json:"name,omitempty"` + Type *PipelineRunSourceType `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelineruntargetproperties.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelineruntargetproperties.go new file mode 100644 index 00000000000..00221baad99 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelineruntargetproperties.go @@ -0,0 +1,9 @@ +package pipelineruns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineRunTargetProperties struct { + Name *string `json:"name,omitempty"` + Type *PipelineRunTargetType `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinesourcetriggerdescriptor.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinesourcetriggerdescriptor.go new file mode 100644 index 00000000000..64ad2afb2ef --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinesourcetriggerdescriptor.go @@ -0,0 +1,26 @@ +package pipelineruns + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineSourceTriggerDescriptor struct { + Timestamp *string `json:"timestamp,omitempty"` +} + +func (o *PipelineSourceTriggerDescriptor) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *PipelineSourceTriggerDescriptor) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinetriggerdescriptor.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinetriggerdescriptor.go new file mode 100644 index 00000000000..29e95e374ae --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_pipelinetriggerdescriptor.go @@ -0,0 +1,8 @@ +package pipelineruns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineTriggerDescriptor struct { + SourceTrigger *PipelineSourceTriggerDescriptor `json:"sourceTrigger,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_progressproperties.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_progressproperties.go new file mode 100644 index 00000000000..3e26a0c9845 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/model_progressproperties.go @@ -0,0 +1,8 @@ +package pipelineruns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProgressProperties struct { + Percentage *string `json:"percentage,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/predicates.go new file mode 100644 index 00000000000..4fd721a59b6 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/predicates.go @@ -0,0 +1,27 @@ +package pipelineruns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PipelineRunOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PipelineRunOperationPredicate) Matches(input PipelineRun) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/version.go b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/version.go new file mode 100644 index 00000000000..31d3b22d044 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/pipelineruns/version.go @@ -0,0 +1,10 @@ +package pipelineruns + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/pipelineruns/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/README.md b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/README.md new file mode 100644 index 00000000000..2660e35a06a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections" +``` + + +### Client Initialization + +```go +client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "privateEndpointConnectionName") + +payload := privateendpointconnections.PrivateEndpointConnection{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "privateEndpointConnectionName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Get` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "privateEndpointConnectionName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.List` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/client.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/client.go new file mode 100644 index 00000000000..50eaf09dcce --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/client.go @@ -0,0 +1,26 @@ +package privateendpointconnections + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateEndpointConnectionsClient: %+v", err) + } + + return &PrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/constants.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/constants.go new file mode 100644 index 00000000000..d1ec47a5f33 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/constants.go @@ -0,0 +1,151 @@ +package privateendpointconnections + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActionsRequired string + +const ( + ActionsRequiredNone ActionsRequired = "None" + ActionsRequiredRecreate ActionsRequired = "Recreate" +) + +func PossibleValuesForActionsRequired() []string { + return []string{ + string(ActionsRequiredNone), + string(ActionsRequiredRecreate), + } +} + +func (s *ActionsRequired) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionsRequired(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActionsRequired(input string) (*ActionsRequired, error) { + vals := map[string]ActionsRequired{ + "none": ActionsRequiredNone, + "recreate": ActionsRequiredRecreate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActionsRequired(input) + return &out, nil +} + +type ConnectionStatus string + +const ( + ConnectionStatusApproved ConnectionStatus = "Approved" + ConnectionStatusDisconnected ConnectionStatus = "Disconnected" + ConnectionStatusPending ConnectionStatus = "Pending" + ConnectionStatusRejected ConnectionStatus = "Rejected" +) + +func PossibleValuesForConnectionStatus() []string { + return []string{ + string(ConnectionStatusApproved), + string(ConnectionStatusDisconnected), + string(ConnectionStatusPending), + string(ConnectionStatusRejected), + } +} + +func (s *ConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConnectionStatus(input string) (*ConnectionStatus, error) { + vals := map[string]ConnectionStatus{ + "approved": ConnectionStatusApproved, + "disconnected": ConnectionStatusDisconnected, + "pending": ConnectionStatusPending, + "rejected": ConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectionStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_privateendpointconnection.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 00000000000..18e5540952a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,139 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateEndpointConnectionId{}) +} + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, registryName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionName"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..52fde89e4e4 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "privateEndpointConnectionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionName") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "privateEndpointConnectionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateEndpointConnections/privateEndpointConnectionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_registry.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_registry.go new file mode 100644 index 00000000000..cbb9543515a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_registry.go @@ -0,0 +1,130 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RegistryId{}) +} + +var _ resourceids.ResourceId = &RegistryId{} + +// RegistryId is a struct representing the Resource ID for a Registry +type RegistryId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string +} + +// NewRegistryID returns a new RegistryId struct +func NewRegistryID(subscriptionId string, resourceGroupName string, registryName string) RegistryId { + return RegistryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + } +} + +// ParseRegistryID parses 'input' into a RegistryId +func ParseRegistryID(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRegistryIDInsensitively parses 'input' case-insensitively into a RegistryId +// note: this method should only be used for API response data and not user input +func ParseRegistryIDInsensitively(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RegistryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + return nil +} + +// ValidateRegistryID checks that 'input' can be parsed as a Registry ID +func ValidateRegistryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRegistryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Registry ID +func (id RegistryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Registry ID +func (id RegistryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + } +} + +// String returns a human-readable description of this Registry ID +func (id RegistryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + } + return fmt.Sprintf("Registry (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_registry_test.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_registry_test.go new file mode 100644 index 00000000000..083160b31c8 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/id_registry_test.go @@ -0,0 +1,282 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RegistryId{} + +func TestNewRegistryID(t *testing.T) { + id := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } +} + +func TestFormatRegistryID(t *testing.T) { + actual := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRegistryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestParseRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestSegmentsForRegistryId(t *testing.T) { + segments := RegistryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RegistryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_createorupdate.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_createorupdate.go new file mode 100644 index 00000000000..73fb1683a66 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_createorupdate.go @@ -0,0 +1,75 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// CreateOrUpdate ... +func (c PrivateEndpointConnectionsClient) CreateOrUpdate(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c PrivateEndpointConnectionsClient) CreateOrUpdateThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_delete.go new file mode 100644 index 00000000000..63c26e8f27f --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_delete.go @@ -0,0 +1,71 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c PrivateEndpointConnectionsClient) Delete(ctx context.Context, id PrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateEndpointConnectionsClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_get.go new file mode 100644 index 00000000000..351242746d4 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_get.go @@ -0,0 +1,53 @@ +package privateendpointconnections + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Get ... +func (c PrivateEndpointConnectionsClient) Get(ctx context.Context, id PrivateEndpointConnectionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_list.go new file mode 100644 index 00000000000..257f7c9fb89 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/method_list.go @@ -0,0 +1,105 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateEndpointConnection +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateEndpointConnection +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c PrivateEndpointConnectionsClient) List(ctx context.Context, id RegistryId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateEndpointConnection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c PrivateEndpointConnectionsClient) ListComplete(ctx context.Context, id RegistryId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, PrivateEndpointConnectionOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PrivateEndpointConnectionsClient) ListCompleteMatchingPredicate(ctx context.Context, id RegistryId, predicate PrivateEndpointConnectionOperationPredicate) (result ListCompleteResult, err error) { + items := make([]PrivateEndpointConnection, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privateendpoint.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privateendpoint.go new file mode 100644 index 00000000000..1bc8cf2a97c --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privateendpoint.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 00000000000..977fe056fe3 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package privateendpointconnections + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..26d6b8a9464 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstate.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..4501bc5a3f1 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *ActionsRequired `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *ConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/predicates.go new file mode 100644 index 00000000000..4a03a91ce52 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/predicates.go @@ -0,0 +1,27 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateEndpointConnectionOperationPredicate) Matches(input PrivateEndpointConnection) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/version.go b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/version.go new file mode 100644 index 00000000000..3fa3b04a719 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/privateendpointconnections/version.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privateendpointconnections/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/README.md b/resource-manager/containerregistry/2023-11-01-preview/registries/README.md new file mode 100644 index 00000000000..d633c7eb54b --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/README.md @@ -0,0 +1,237 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/registries` Documentation + +The `registries` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/registries" +``` + + +### Client Initialization + +```go +client := registries.NewRegistriesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RegistriesClient.Create` + +```go +ctx := context.TODO() +id := registries.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +payload := registries.Registry{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RegistriesClient.Delete` + +```go +ctx := context.TODO() +id := registries.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RegistriesClient.GenerateCredentials` + +```go +ctx := context.TODO() +id := registries.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +payload := registries.GenerateCredentialsParameters{ + // ... +} + + +if err := client.GenerateCredentialsThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RegistriesClient.Get` + +```go +ctx := context.TODO() +id := registries.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RegistriesClient.GetPrivateLinkResource` + +```go +ctx := context.TODO() +id := registries.NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "privateLinkResourceName") + +read, err := client.GetPrivateLinkResource(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RegistriesClient.ImportImage` + +```go +ctx := context.TODO() +id := registries.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +payload := registries.ImportImageParameters{ + // ... +} + + +if err := client.ImportImageThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RegistriesClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RegistriesClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RegistriesClient.ListCredentials` + +```go +ctx := context.TODO() +id := registries.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +read, err := client.ListCredentials(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RegistriesClient.ListPrivateLinkResources` + +```go +ctx := context.TODO() +id := registries.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +// alternatively `client.ListPrivateLinkResources(ctx, id)` can be used to do batched pagination +items, err := client.ListPrivateLinkResourcesComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RegistriesClient.ListUsages` + +```go +ctx := context.TODO() +id := registries.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +read, err := client.ListUsages(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RegistriesClient.RegenerateCredential` + +```go +ctx := context.TODO() +id := registries.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +payload := registries.RegenerateCredentialParameters{ + // ... +} + + +read, err := client.RegenerateCredential(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RegistriesClient.Update` + +```go +ctx := context.TODO() +id := registries.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +payload := registries.RegistryUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/client.go b/resource-manager/containerregistry/2023-11-01-preview/registries/client.go new file mode 100644 index 00000000000..19546ba8db3 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/client.go @@ -0,0 +1,26 @@ +package registries + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistriesClient struct { + Client *resourcemanager.Client +} + +func NewRegistriesClientWithBaseURI(sdkApi sdkEnv.Api) (*RegistriesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "registries", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RegistriesClient: %+v", err) + } + + return &RegistriesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/constants.go b/resource-manager/containerregistry/2023-11-01-preview/registries/constants.go new file mode 100644 index 00000000000..4ba9b8662f3 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/constants.go @@ -0,0 +1,854 @@ +package registries + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Action string + +const ( + ActionAllow Action = "Allow" +) + +func PossibleValuesForAction() []string { + return []string{ + string(ActionAllow), + } +} + +func (s *Action) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAction(input string) (*Action, error) { + vals := map[string]Action{ + "allow": ActionAllow, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Action(input) + return &out, nil +} + +type ActionsRequired string + +const ( + ActionsRequiredNone ActionsRequired = "None" + ActionsRequiredRecreate ActionsRequired = "Recreate" +) + +func PossibleValuesForActionsRequired() []string { + return []string{ + string(ActionsRequiredNone), + string(ActionsRequiredRecreate), + } +} + +func (s *ActionsRequired) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseActionsRequired(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseActionsRequired(input string) (*ActionsRequired, error) { + vals := map[string]ActionsRequired{ + "none": ActionsRequiredNone, + "recreate": ActionsRequiredRecreate, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ActionsRequired(input) + return &out, nil +} + +type AzureADAuthenticationAsArmPolicyStatus string + +const ( + AzureADAuthenticationAsArmPolicyStatusDisabled AzureADAuthenticationAsArmPolicyStatus = "disabled" + AzureADAuthenticationAsArmPolicyStatusEnabled AzureADAuthenticationAsArmPolicyStatus = "enabled" +) + +func PossibleValuesForAzureADAuthenticationAsArmPolicyStatus() []string { + return []string{ + string(AzureADAuthenticationAsArmPolicyStatusDisabled), + string(AzureADAuthenticationAsArmPolicyStatusEnabled), + } +} + +func (s *AzureADAuthenticationAsArmPolicyStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAzureADAuthenticationAsArmPolicyStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAzureADAuthenticationAsArmPolicyStatus(input string) (*AzureADAuthenticationAsArmPolicyStatus, error) { + vals := map[string]AzureADAuthenticationAsArmPolicyStatus{ + "disabled": AzureADAuthenticationAsArmPolicyStatusDisabled, + "enabled": AzureADAuthenticationAsArmPolicyStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AzureADAuthenticationAsArmPolicyStatus(input) + return &out, nil +} + +type ConnectionStatus string + +const ( + ConnectionStatusApproved ConnectionStatus = "Approved" + ConnectionStatusDisconnected ConnectionStatus = "Disconnected" + ConnectionStatusPending ConnectionStatus = "Pending" + ConnectionStatusRejected ConnectionStatus = "Rejected" +) + +func PossibleValuesForConnectionStatus() []string { + return []string{ + string(ConnectionStatusApproved), + string(ConnectionStatusDisconnected), + string(ConnectionStatusPending), + string(ConnectionStatusRejected), + } +} + +func (s *ConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseConnectionStatus(input string) (*ConnectionStatus, error) { + vals := map[string]ConnectionStatus{ + "approved": ConnectionStatusApproved, + "disconnected": ConnectionStatusDisconnected, + "pending": ConnectionStatusPending, + "rejected": ConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectionStatus(input) + return &out, nil +} + +type DefaultAction string + +const ( + DefaultActionAllow DefaultAction = "Allow" + DefaultActionDeny DefaultAction = "Deny" +) + +func PossibleValuesForDefaultAction() []string { + return []string{ + string(DefaultActionAllow), + string(DefaultActionDeny), + } +} + +func (s *DefaultAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDefaultAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDefaultAction(input string) (*DefaultAction, error) { + vals := map[string]DefaultAction{ + "allow": DefaultActionAllow, + "deny": DefaultActionDeny, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DefaultAction(input) + return &out, nil +} + +type EncryptionStatus string + +const ( + EncryptionStatusDisabled EncryptionStatus = "disabled" + EncryptionStatusEnabled EncryptionStatus = "enabled" +) + +func PossibleValuesForEncryptionStatus() []string { + return []string{ + string(EncryptionStatusDisabled), + string(EncryptionStatusEnabled), + } +} + +func (s *EncryptionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEncryptionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEncryptionStatus(input string) (*EncryptionStatus, error) { + vals := map[string]EncryptionStatus{ + "disabled": EncryptionStatusDisabled, + "enabled": EncryptionStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EncryptionStatus(input) + return &out, nil +} + +type ExportPolicyStatus string + +const ( + ExportPolicyStatusDisabled ExportPolicyStatus = "disabled" + ExportPolicyStatusEnabled ExportPolicyStatus = "enabled" +) + +func PossibleValuesForExportPolicyStatus() []string { + return []string{ + string(ExportPolicyStatusDisabled), + string(ExportPolicyStatusEnabled), + } +} + +func (s *ExportPolicyStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseExportPolicyStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseExportPolicyStatus(input string) (*ExportPolicyStatus, error) { + vals := map[string]ExportPolicyStatus{ + "disabled": ExportPolicyStatusDisabled, + "enabled": ExportPolicyStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ExportPolicyStatus(input) + return &out, nil +} + +type ImportMode string + +const ( + ImportModeForce ImportMode = "Force" + ImportModeNoForce ImportMode = "NoForce" +) + +func PossibleValuesForImportMode() []string { + return []string{ + string(ImportModeForce), + string(ImportModeNoForce), + } +} + +func (s *ImportMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseImportMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseImportMode(input string) (*ImportMode, error) { + vals := map[string]ImportMode{ + "force": ImportModeForce, + "noforce": ImportModeNoForce, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ImportMode(input) + return &out, nil +} + +type MetadataSearch string + +const ( + MetadataSearchDisabled MetadataSearch = "Disabled" + MetadataSearchEnabled MetadataSearch = "Enabled" +) + +func PossibleValuesForMetadataSearch() []string { + return []string{ + string(MetadataSearchDisabled), + string(MetadataSearchEnabled), + } +} + +func (s *MetadataSearch) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMetadataSearch(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMetadataSearch(input string) (*MetadataSearch, error) { + vals := map[string]MetadataSearch{ + "disabled": MetadataSearchDisabled, + "enabled": MetadataSearchEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MetadataSearch(input) + return &out, nil +} + +type NetworkRuleBypassOptions string + +const ( + NetworkRuleBypassOptionsAzureServices NetworkRuleBypassOptions = "AzureServices" + NetworkRuleBypassOptionsNone NetworkRuleBypassOptions = "None" +) + +func PossibleValuesForNetworkRuleBypassOptions() []string { + return []string{ + string(NetworkRuleBypassOptionsAzureServices), + string(NetworkRuleBypassOptionsNone), + } +} + +func (s *NetworkRuleBypassOptions) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNetworkRuleBypassOptions(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNetworkRuleBypassOptions(input string) (*NetworkRuleBypassOptions, error) { + vals := map[string]NetworkRuleBypassOptions{ + "azureservices": NetworkRuleBypassOptionsAzureServices, + "none": NetworkRuleBypassOptionsNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NetworkRuleBypassOptions(input) + return &out, nil +} + +type PasswordName string + +const ( + PasswordNamePassword PasswordName = "password" + PasswordNamePasswordTwo PasswordName = "password2" +) + +func PossibleValuesForPasswordName() []string { + return []string{ + string(PasswordNamePassword), + string(PasswordNamePasswordTwo), + } +} + +func (s *PasswordName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePasswordName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePasswordName(input string) (*PasswordName, error) { + vals := map[string]PasswordName{ + "password": PasswordNamePassword, + "password2": PasswordNamePasswordTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PasswordName(input) + return &out, nil +} + +type PolicyStatus string + +const ( + PolicyStatusDisabled PolicyStatus = "disabled" + PolicyStatusEnabled PolicyStatus = "enabled" +) + +func PossibleValuesForPolicyStatus() []string { + return []string{ + string(PolicyStatusDisabled), + string(PolicyStatusEnabled), + } +} + +func (s *PolicyStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyStatus(input string) (*PolicyStatus, error) { + vals := map[string]PolicyStatus{ + "disabled": PolicyStatusDisabled, + "enabled": PolicyStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func (s *PublicNetworkAccess) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePublicNetworkAccess(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": PublicNetworkAccessDisabled, + "enabled": PublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccess(input) + return &out, nil +} + +type RegistryUsageUnit string + +const ( + RegistryUsageUnitBytes RegistryUsageUnit = "Bytes" + RegistryUsageUnitCount RegistryUsageUnit = "Count" +) + +func PossibleValuesForRegistryUsageUnit() []string { + return []string{ + string(RegistryUsageUnitBytes), + string(RegistryUsageUnitCount), + } +} + +func (s *RegistryUsageUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRegistryUsageUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRegistryUsageUnit(input string) (*RegistryUsageUnit, error) { + vals := map[string]RegistryUsageUnit{ + "bytes": RegistryUsageUnitBytes, + "count": RegistryUsageUnitCount, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RegistryUsageUnit(input) + return &out, nil +} + +type SkuName string + +const ( + SkuNameBasic SkuName = "Basic" + SkuNameClassic SkuName = "Classic" + SkuNamePremium SkuName = "Premium" + SkuNameStandard SkuName = "Standard" +) + +func PossibleValuesForSkuName() []string { + return []string{ + string(SkuNameBasic), + string(SkuNameClassic), + string(SkuNamePremium), + string(SkuNameStandard), + } +} + +func (s *SkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuName(input string) (*SkuName, error) { + vals := map[string]SkuName{ + "basic": SkuNameBasic, + "classic": SkuNameClassic, + "premium": SkuNamePremium, + "standard": SkuNameStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuName(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierClassic SkuTier = "Classic" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierClassic), + string(SkuTierPremium), + string(SkuTierStandard), + } +} + +func (s *SkuTier) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuTier(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuTier(input string) (*SkuTier, error) { + vals := map[string]SkuTier{ + "basic": SkuTierBasic, + "classic": SkuTierClassic, + "premium": SkuTierPremium, + "standard": SkuTierStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuTier(input) + return &out, nil +} + +type TokenPasswordName string + +const ( + TokenPasswordNamePasswordOne TokenPasswordName = "password1" + TokenPasswordNamePasswordTwo TokenPasswordName = "password2" +) + +func PossibleValuesForTokenPasswordName() []string { + return []string{ + string(TokenPasswordNamePasswordOne), + string(TokenPasswordNamePasswordTwo), + } +} + +func (s *TokenPasswordName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTokenPasswordName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTokenPasswordName(input string) (*TokenPasswordName, error) { + vals := map[string]TokenPasswordName{ + "password1": TokenPasswordNamePasswordOne, + "password2": TokenPasswordNamePasswordTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TokenPasswordName(input) + return &out, nil +} + +type TrustPolicyType string + +const ( + TrustPolicyTypeNotary TrustPolicyType = "Notary" +) + +func PossibleValuesForTrustPolicyType() []string { + return []string{ + string(TrustPolicyTypeNotary), + } +} + +func (s *TrustPolicyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTrustPolicyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTrustPolicyType(input string) (*TrustPolicyType, error) { + vals := map[string]TrustPolicyType{ + "notary": TrustPolicyTypeNotary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TrustPolicyType(input) + return &out, nil +} + +type ZoneRedundancy string + +const ( + ZoneRedundancyDisabled ZoneRedundancy = "Disabled" + ZoneRedundancyEnabled ZoneRedundancy = "Enabled" +) + +func PossibleValuesForZoneRedundancy() []string { + return []string{ + string(ZoneRedundancyDisabled), + string(ZoneRedundancyEnabled), + } +} + +func (s *ZoneRedundancy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseZoneRedundancy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseZoneRedundancy(input string) (*ZoneRedundancy, error) { + vals := map[string]ZoneRedundancy{ + "disabled": ZoneRedundancyDisabled, + "enabled": ZoneRedundancyEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ZoneRedundancy(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/id_privatelinkresource.go b/resource-manager/containerregistry/2023-11-01-preview/registries/id_privatelinkresource.go new file mode 100644 index 00000000000..2d9dd7144e7 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/id_privatelinkresource.go @@ -0,0 +1,139 @@ +package registries + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateLinkResourceId{}) +} + +var _ resourceids.ResourceId = &PrivateLinkResourceId{} + +// PrivateLinkResourceId is a struct representing the Resource ID for a Private Link Resource +type PrivateLinkResourceId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + PrivateLinkResourceName string +} + +// NewPrivateLinkResourceID returns a new PrivateLinkResourceId struct +func NewPrivateLinkResourceID(subscriptionId string, resourceGroupName string, registryName string, privateLinkResourceName string) PrivateLinkResourceId { + return PrivateLinkResourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + PrivateLinkResourceName: privateLinkResourceName, + } +} + +// ParsePrivateLinkResourceID parses 'input' into a PrivateLinkResourceId +func ParsePrivateLinkResourceID(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkResourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a PrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkResourceIDInsensitively(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateLinkResourceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateLinkResourceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.PrivateLinkResourceName, ok = input.Parsed["privateLinkResourceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateLinkResourceName", input) + } + + return nil +} + +// ValidatePrivateLinkResourceID checks that 'input' can be parsed as a Private Link Resource ID +func ValidatePrivateLinkResourceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Resource ID +func (id PrivateLinkResourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/privateLinkResources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.PrivateLinkResourceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Resource ID +func (id PrivateLinkResourceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticPrivateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("privateLinkResourceName", "privateLinkResourceName"), + } +} + +// String returns a human-readable description of this Private Link Resource ID +func (id PrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Private Link Resource Name: %q", id.PrivateLinkResourceName), + } + return fmt.Sprintf("Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/id_privatelinkresource_test.go b/resource-manager/containerregistry/2023-11-01-preview/registries/id_privatelinkresource_test.go new file mode 100644 index 00000000000..e83aeba74d2 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/id_privatelinkresource_test.go @@ -0,0 +1,327 @@ +package registries + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateLinkResourceId{} + +func TestNewPrivateLinkResourceID(t *testing.T) { + id := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "privateLinkResourceName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.PrivateLinkResourceName != "privateLinkResourceName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateLinkResourceName'", id.PrivateLinkResourceName, "privateLinkResourceName") + } +} + +func TestFormatPrivateLinkResourceID(t *testing.T) { + actual := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "privateLinkResourceName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateLinkResources/privateLinkResourceName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateLinkResources/privateLinkResourceName", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PrivateLinkResourceName: "privateLinkResourceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateLinkResources/privateLinkResourceName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestParsePrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateLinkResources/privateLinkResourceName", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + PrivateLinkResourceName: "privateLinkResourceName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/privateLinkResources/privateLinkResourceName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeNaMe", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + PrivateLinkResourceName: "pRiVaTeLiNkReSoUrCeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/pRiVaTeLiNkReSoUrCeS/pRiVaTeLiNkReSoUrCeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.PrivateLinkResourceName != v.Expected.PrivateLinkResourceName { + t.Fatalf("Expected %q but got %q for PrivateLinkResourceName", v.Expected.PrivateLinkResourceName, actual.PrivateLinkResourceName) + } + + } +} + +func TestSegmentsForPrivateLinkResourceId(t *testing.T) { + segments := PrivateLinkResourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkResourceId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/id_registry.go b/resource-manager/containerregistry/2023-11-01-preview/registries/id_registry.go new file mode 100644 index 00000000000..9271561c3be --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/id_registry.go @@ -0,0 +1,130 @@ +package registries + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RegistryId{}) +} + +var _ resourceids.ResourceId = &RegistryId{} + +// RegistryId is a struct representing the Resource ID for a Registry +type RegistryId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string +} + +// NewRegistryID returns a new RegistryId struct +func NewRegistryID(subscriptionId string, resourceGroupName string, registryName string) RegistryId { + return RegistryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + } +} + +// ParseRegistryID parses 'input' into a RegistryId +func ParseRegistryID(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRegistryIDInsensitively parses 'input' case-insensitively into a RegistryId +// note: this method should only be used for API response data and not user input +func ParseRegistryIDInsensitively(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RegistryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + return nil +} + +// ValidateRegistryID checks that 'input' can be parsed as a Registry ID +func ValidateRegistryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRegistryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Registry ID +func (id RegistryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Registry ID +func (id RegistryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + } +} + +// String returns a human-readable description of this Registry ID +func (id RegistryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + } + return fmt.Sprintf("Registry (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/id_registry_test.go b/resource-manager/containerregistry/2023-11-01-preview/registries/id_registry_test.go new file mode 100644 index 00000000000..43560885bf2 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/id_registry_test.go @@ -0,0 +1,282 @@ +package registries + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RegistryId{} + +func TestNewRegistryID(t *testing.T) { + id := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } +} + +func TestFormatRegistryID(t *testing.T) { + actual := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRegistryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestParseRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestSegmentsForRegistryId(t *testing.T) { + segments := RegistryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RegistryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/method_create.go b/resource-manager/containerregistry/2023-11-01-preview/registries/method_create.go new file mode 100644 index 00000000000..5b8db55a0b0 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/method_create.go @@ -0,0 +1,75 @@ +package registries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Registry +} + +// Create ... +func (c RegistriesClient) Create(ctx context.Context, id RegistryId, input Registry) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c RegistriesClient) CreateThenPoll(ctx context.Context, id RegistryId, input Registry) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/registries/method_delete.go new file mode 100644 index 00000000000..4a0877f344a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/method_delete.go @@ -0,0 +1,71 @@ +package registries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c RegistriesClient) Delete(ctx context.Context, id RegistryId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c RegistriesClient) DeleteThenPoll(ctx context.Context, id RegistryId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/method_generatecredentials.go b/resource-manager/containerregistry/2023-11-01-preview/registries/method_generatecredentials.go new file mode 100644 index 00000000000..12d06ca2ab4 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/method_generatecredentials.go @@ -0,0 +1,75 @@ +package registries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateCredentialsOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *GenerateCredentialsResult +} + +// GenerateCredentials ... +func (c RegistriesClient) GenerateCredentials(ctx context.Context, id RegistryId, input GenerateCredentialsParameters) (result GenerateCredentialsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/generateCredentials", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// GenerateCredentialsThenPoll performs GenerateCredentials then polls until it's completed +func (c RegistriesClient) GenerateCredentialsThenPoll(ctx context.Context, id RegistryId, input GenerateCredentialsParameters) error { + result, err := c.GenerateCredentials(ctx, id, input) + if err != nil { + return fmt.Errorf("performing GenerateCredentials: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after GenerateCredentials: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/registries/method_get.go new file mode 100644 index 00000000000..35c99ecc4a6 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/method_get.go @@ -0,0 +1,53 @@ +package registries + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Registry +} + +// Get ... +func (c RegistriesClient) Get(ctx context.Context, id RegistryId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Registry + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/method_getprivatelinkresource.go b/resource-manager/containerregistry/2023-11-01-preview/registries/method_getprivatelinkresource.go new file mode 100644 index 00000000000..163aa93ca75 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/method_getprivatelinkresource.go @@ -0,0 +1,53 @@ +package registries + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetPrivateLinkResourceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkResource +} + +// GetPrivateLinkResource ... +func (c RegistriesClient) GetPrivateLinkResource(ctx context.Context, id PrivateLinkResourceId) (result GetPrivateLinkResourceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateLinkResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/method_importimage.go b/resource-manager/containerregistry/2023-11-01-preview/registries/method_importimage.go new file mode 100644 index 00000000000..73da0c5ca7b --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/method_importimage.go @@ -0,0 +1,74 @@ +package registries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportImageOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ImportImage ... +func (c RegistriesClient) ImportImage(ctx context.Context, id RegistryId, input ImportImageParameters) (result ImportImageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/importImage", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ImportImageThenPoll performs ImportImage then polls until it's completed +func (c RegistriesClient) ImportImageThenPoll(ctx context.Context, id RegistryId, input ImportImageParameters) error { + result, err := c.ImportImage(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ImportImage: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ImportImage: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/registries/method_list.go new file mode 100644 index 00000000000..0c9d895db4e --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/method_list.go @@ -0,0 +1,106 @@ +package registries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Registry +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Registry +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c RegistriesClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.ContainerRegistry/registries", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Registry `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c RegistriesClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, RegistryOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RegistriesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate RegistryOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Registry, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/method_listbyresourcegroup.go b/resource-manager/containerregistry/2023-11-01-preview/registries/method_listbyresourcegroup.go new file mode 100644 index 00000000000..ba9e98edfc1 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package registries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Registry +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Registry +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c RegistriesClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.ContainerRegistry/registries", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Registry `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c RegistriesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, RegistryOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RegistriesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate RegistryOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Registry, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/method_listcredentials.go b/resource-manager/containerregistry/2023-11-01-preview/registries/method_listcredentials.go new file mode 100644 index 00000000000..2c9ddf64535 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/method_listcredentials.go @@ -0,0 +1,54 @@ +package registries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListCredentialsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RegistryListCredentialsResult +} + +// ListCredentials ... +func (c RegistriesClient) ListCredentials(ctx context.Context, id RegistryId) (result ListCredentialsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listCredentials", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RegistryListCredentialsResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/method_listprivatelinkresources.go b/resource-manager/containerregistry/2023-11-01-preview/registries/method_listprivatelinkresources.go new file mode 100644 index 00000000000..96d44cfd991 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/method_listprivatelinkresources.go @@ -0,0 +1,105 @@ +package registries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListPrivateLinkResourcesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PrivateLinkResource +} + +type ListPrivateLinkResourcesCompleteResult struct { + LatestHttpResponse *http.Response + Items []PrivateLinkResource +} + +type ListPrivateLinkResourcesCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListPrivateLinkResourcesCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListPrivateLinkResources ... +func (c RegistriesClient) ListPrivateLinkResources(ctx context.Context, id RegistryId) (result ListPrivateLinkResourcesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListPrivateLinkResourcesCustomPager{}, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PrivateLinkResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListPrivateLinkResourcesComplete retrieves all the results into a single object +func (c RegistriesClient) ListPrivateLinkResourcesComplete(ctx context.Context, id RegistryId) (ListPrivateLinkResourcesCompleteResult, error) { + return c.ListPrivateLinkResourcesCompleteMatchingPredicate(ctx, id, PrivateLinkResourceOperationPredicate{}) +} + +// ListPrivateLinkResourcesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RegistriesClient) ListPrivateLinkResourcesCompleteMatchingPredicate(ctx context.Context, id RegistryId, predicate PrivateLinkResourceOperationPredicate) (result ListPrivateLinkResourcesCompleteResult, err error) { + items := make([]PrivateLinkResource, 0) + + resp, err := c.ListPrivateLinkResources(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListPrivateLinkResourcesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/method_listusages.go b/resource-manager/containerregistry/2023-11-01-preview/registries/method_listusages.go new file mode 100644 index 00000000000..d5f43985b7b --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/method_listusages.go @@ -0,0 +1,54 @@ +package registries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListUsagesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RegistryUsageListResult +} + +// ListUsages ... +func (c RegistriesClient) ListUsages(ctx context.Context, id RegistryId) (result ListUsagesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/listUsages", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RegistryUsageListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/method_regeneratecredential.go b/resource-manager/containerregistry/2023-11-01-preview/registries/method_regeneratecredential.go new file mode 100644 index 00000000000..03fa33af49d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/method_regeneratecredential.go @@ -0,0 +1,58 @@ +package registries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateCredentialOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RegistryListCredentialsResult +} + +// RegenerateCredential ... +func (c RegistriesClient) RegenerateCredential(ctx context.Context, id RegistryId, input RegenerateCredentialParameters) (result RegenerateCredentialOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateCredential", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model RegistryListCredentialsResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/method_update.go b/resource-manager/containerregistry/2023-11-01-preview/registries/method_update.go new file mode 100644 index 00000000000..61af909a492 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/method_update.go @@ -0,0 +1,75 @@ +package registries + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Registry +} + +// Update ... +func (c RegistriesClient) Update(ctx context.Context, id RegistryId, input RegistryUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c RegistriesClient) UpdateThenPoll(ctx context.Context, id RegistryId, input RegistryUpdateParameters) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_azureadauthenticationasarmpolicy.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_azureadauthenticationasarmpolicy.go new file mode 100644 index 00000000000..35c552f0341 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_azureadauthenticationasarmpolicy.go @@ -0,0 +1,8 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AzureADAuthenticationAsArmPolicy struct { + Status *AzureADAuthenticationAsArmPolicyStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_encryptionproperty.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_encryptionproperty.go new file mode 100644 index 00000000000..44af317bc4e --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_encryptionproperty.go @@ -0,0 +1,9 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionProperty struct { + KeyVaultProperties *KeyVaultProperties `json:"keyVaultProperties,omitempty"` + Status *EncryptionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_exportpolicy.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_exportpolicy.go new file mode 100644 index 00000000000..bcbc7e5b8e0 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_exportpolicy.go @@ -0,0 +1,8 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportPolicy struct { + Status *ExportPolicyStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_generatecredentialsparameters.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_generatecredentialsparameters.go new file mode 100644 index 00000000000..c06016d18ba --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_generatecredentialsparameters.go @@ -0,0 +1,28 @@ +package registries + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateCredentialsParameters struct { + Expiry *string `json:"expiry,omitempty"` + Name *TokenPasswordName `json:"name,omitempty"` + TokenId *string `json:"tokenId,omitempty"` +} + +func (o *GenerateCredentialsParameters) GetExpiryAsTime() (*time.Time, error) { + if o.Expiry == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Expiry, "2006-01-02T15:04:05Z07:00") +} + +func (o *GenerateCredentialsParameters) SetExpiryAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Expiry = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_generatecredentialsresult.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_generatecredentialsresult.go new file mode 100644 index 00000000000..04e9f2ca4e1 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_generatecredentialsresult.go @@ -0,0 +1,9 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GenerateCredentialsResult struct { + Passwords *[]TokenPassword `json:"passwords,omitempty"` + Username *string `json:"username,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_importimageparameters.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_importimageparameters.go new file mode 100644 index 00000000000..87cf41482e0 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_importimageparameters.go @@ -0,0 +1,11 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportImageParameters struct { + Mode *ImportMode `json:"mode,omitempty"` + Source ImportSource `json:"source"` + TargetTags *[]string `json:"targetTags,omitempty"` + UntaggedTargetRepositories *[]string `json:"untaggedTargetRepositories,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_importsource.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_importsource.go new file mode 100644 index 00000000000..31af2344645 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_importsource.go @@ -0,0 +1,11 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportSource struct { + Credentials *ImportSourceCredentials `json:"credentials,omitempty"` + RegistryUri *string `json:"registryUri,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + SourceImage string `json:"sourceImage"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_importsourcecredentials.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_importsourcecredentials.go new file mode 100644 index 00000000000..58089b0fb0d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_importsourcecredentials.go @@ -0,0 +1,9 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportSourceCredentials struct { + Password string `json:"password"` + Username *string `json:"username,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_iprule.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_iprule.go new file mode 100644 index 00000000000..dd326aa73f3 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_iprule.go @@ -0,0 +1,9 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPRule struct { + Action *Action `json:"action,omitempty"` + Value string `json:"value"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_keyvaultproperties.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_keyvaultproperties.go new file mode 100644 index 00000000000..897c6dd8d9b --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_keyvaultproperties.go @@ -0,0 +1,30 @@ +package registries + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultProperties struct { + Identity *string `json:"identity,omitempty"` + KeyIdentifier *string `json:"keyIdentifier,omitempty"` + KeyRotationEnabled *bool `json:"keyRotationEnabled,omitempty"` + LastKeyRotationTimestamp *string `json:"lastKeyRotationTimestamp,omitempty"` + VersionedKeyIdentifier *string `json:"versionedKeyIdentifier,omitempty"` +} + +func (o *KeyVaultProperties) GetLastKeyRotationTimestampAsTime() (*time.Time, error) { + if o.LastKeyRotationTimestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastKeyRotationTimestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *KeyVaultProperties) SetLastKeyRotationTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastKeyRotationTimestamp = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_networkruleset.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_networkruleset.go new file mode 100644 index 00000000000..dec8b58f5ce --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_networkruleset.go @@ -0,0 +1,9 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkRuleSet struct { + DefaultAction DefaultAction `json:"defaultAction"` + IPRules *[]IPRule `json:"ipRules,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_policies.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_policies.go new file mode 100644 index 00000000000..64655913cf7 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_policies.go @@ -0,0 +1,13 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Policies struct { + AzureADAuthenticationAsArmPolicy *AzureADAuthenticationAsArmPolicy `json:"azureADAuthenticationAsArmPolicy,omitempty"` + ExportPolicy *ExportPolicy `json:"exportPolicy,omitempty"` + QuarantinePolicy *QuarantinePolicy `json:"quarantinePolicy,omitempty"` + RetentionPolicy *RetentionPolicy `json:"retentionPolicy,omitempty"` + SoftDeletePolicy *SoftDeletePolicy `json:"softDeletePolicy,omitempty"` + TrustPolicy *TrustPolicy `json:"trustPolicy,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_privateendpoint.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_privateendpoint.go new file mode 100644 index 00000000000..411a1e09e74 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_privateendpoint.go @@ -0,0 +1,8 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_privateendpointconnection.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_privateendpointconnection.go new file mode 100644 index 00000000000..788154720bc --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package registries + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_privateendpointconnectionproperties.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..4c8ee66a879 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_privatelinkresource.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_privatelinkresource.go new file mode 100644 index 00000000000..bd76ad62e19 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_privatelinkresource.go @@ -0,0 +1,11 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_privatelinkresourceproperties.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..bc9bc51fac7 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_privatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_privatelinkserviceconnectionstate.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..574d08caf18 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *ActionsRequired `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *ConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_quarantinepolicy.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_quarantinepolicy.go new file mode 100644 index 00000000000..3d620232e94 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_quarantinepolicy.go @@ -0,0 +1,8 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuarantinePolicy struct { + Status *PolicyStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_regeneratecredentialparameters.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_regeneratecredentialparameters.go new file mode 100644 index 00000000000..755b01c4e9d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_regeneratecredentialparameters.go @@ -0,0 +1,8 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateCredentialParameters struct { + Name PasswordName `json:"name"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_registry.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registry.go new file mode 100644 index 00000000000..5717ef0c63e --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registry.go @@ -0,0 +1,21 @@ +package registries + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Registry struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *RegistryProperties `json:"properties,omitempty"` + Sku Sku `json:"sku"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_registrylistcredentialsresult.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registrylistcredentialsresult.go new file mode 100644 index 00000000000..73bbbf96138 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registrylistcredentialsresult.go @@ -0,0 +1,9 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryListCredentialsResult struct { + Passwords *[]RegistryPassword `json:"passwords,omitempty"` + Username *string `json:"username,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_registrypassword.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registrypassword.go new file mode 100644 index 00000000000..774a3c4a080 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registrypassword.go @@ -0,0 +1,9 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryPassword struct { + Name *PasswordName `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_registryproperties.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registryproperties.go new file mode 100644 index 00000000000..b85bae63d22 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registryproperties.go @@ -0,0 +1,41 @@ +package registries + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryProperties struct { + AdminUserEnabled *bool `json:"adminUserEnabled,omitempty"` + AnonymousPullEnabled *bool `json:"anonymousPullEnabled,omitempty"` + CreationDate *string `json:"creationDate,omitempty"` + DataEndpointEnabled *bool `json:"dataEndpointEnabled,omitempty"` + DataEndpointHostNames *[]string `json:"dataEndpointHostNames,omitempty"` + Encryption *EncryptionProperty `json:"encryption,omitempty"` + LoginServer *string `json:"loginServer,omitempty"` + MetadataSearch *MetadataSearch `json:"metadataSearch,omitempty"` + NetworkRuleBypassOptions *NetworkRuleBypassOptions `json:"networkRuleBypassOptions,omitempty"` + NetworkRuleSet *NetworkRuleSet `json:"networkRuleSet,omitempty"` + Policies *Policies `json:"policies,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + Status *Status `json:"status,omitempty"` + ZoneRedundancy *ZoneRedundancy `json:"zoneRedundancy,omitempty"` +} + +func (o *RegistryProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *RegistryProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_registrypropertiesupdateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registrypropertiesupdateparameters.go new file mode 100644 index 00000000000..48dc2212976 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registrypropertiesupdateparameters.go @@ -0,0 +1,16 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryPropertiesUpdateParameters struct { + AdminUserEnabled *bool `json:"adminUserEnabled,omitempty"` + AnonymousPullEnabled *bool `json:"anonymousPullEnabled,omitempty"` + DataEndpointEnabled *bool `json:"dataEndpointEnabled,omitempty"` + Encryption *EncryptionProperty `json:"encryption,omitempty"` + MetadataSearch *MetadataSearch `json:"metadataSearch,omitempty"` + NetworkRuleBypassOptions *NetworkRuleBypassOptions `json:"networkRuleBypassOptions,omitempty"` + NetworkRuleSet *NetworkRuleSet `json:"networkRuleSet,omitempty"` + Policies *Policies `json:"policies,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_registryupdateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registryupdateparameters.go new file mode 100644 index 00000000000..faaef3805a3 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registryupdateparameters.go @@ -0,0 +1,15 @@ +package registries + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryUpdateParameters struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *RegistryPropertiesUpdateParameters `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_registryusage.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registryusage.go new file mode 100644 index 00000000000..360e66a853a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registryusage.go @@ -0,0 +1,11 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryUsage struct { + CurrentValue *int64 `json:"currentValue,omitempty"` + Limit *int64 `json:"limit,omitempty"` + Name *string `json:"name,omitempty"` + Unit *RegistryUsageUnit `json:"unit,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_registryusagelistresult.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registryusagelistresult.go new file mode 100644 index 00000000000..34f8adfe239 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_registryusagelistresult.go @@ -0,0 +1,8 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistryUsageListResult struct { + Value *[]RegistryUsage `json:"value,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_retentionpolicy.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_retentionpolicy.go new file mode 100644 index 00000000000..1db918f1041 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_retentionpolicy.go @@ -0,0 +1,28 @@ +package registries + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RetentionPolicy struct { + Days *int64 `json:"days,omitempty"` + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + Status *PolicyStatus `json:"status,omitempty"` +} + +func (o *RetentionPolicy) GetLastUpdatedTimeAsTime() (*time.Time, error) { + if o.LastUpdatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *RetentionPolicy) SetLastUpdatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdatedTime = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_sku.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_sku.go new file mode 100644 index 00000000000..2b0fae22fea --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_sku.go @@ -0,0 +1,9 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Name SkuName `json:"name"` + Tier *SkuTier `json:"tier,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_softdeletepolicy.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_softdeletepolicy.go new file mode 100644 index 00000000000..99254855359 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_softdeletepolicy.go @@ -0,0 +1,28 @@ +package registries + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SoftDeletePolicy struct { + LastUpdatedTime *string `json:"lastUpdatedTime,omitempty"` + RetentionDays *int64 `json:"retentionDays,omitempty"` + Status *PolicyStatus `json:"status,omitempty"` +} + +func (o *SoftDeletePolicy) GetLastUpdatedTimeAsTime() (*time.Time, error) { + if o.LastUpdatedTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastUpdatedTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *SoftDeletePolicy) SetLastUpdatedTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastUpdatedTime = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_status.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_status.go new file mode 100644 index 00000000000..2d04c2f49b4 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_status.go @@ -0,0 +1,28 @@ +package registries + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Status struct { + DisplayStatus *string `json:"displayStatus,omitempty"` + Message *string `json:"message,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` +} + +func (o *Status) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *Status) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_tokenpassword.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_tokenpassword.go new file mode 100644 index 00000000000..437fa0813f4 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_tokenpassword.go @@ -0,0 +1,41 @@ +package registries + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TokenPassword struct { + CreationTime *string `json:"creationTime,omitempty"` + Expiry *string `json:"expiry,omitempty"` + Name *TokenPasswordName `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} + +func (o *TokenPassword) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *TokenPassword) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} + +func (o *TokenPassword) GetExpiryAsTime() (*time.Time, error) { + if o.Expiry == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Expiry, "2006-01-02T15:04:05Z07:00") +} + +func (o *TokenPassword) SetExpiryAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Expiry = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/model_trustpolicy.go b/resource-manager/containerregistry/2023-11-01-preview/registries/model_trustpolicy.go new file mode 100644 index 00000000000..33b15d9cc34 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/model_trustpolicy.go @@ -0,0 +1,9 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TrustPolicy struct { + Status *PolicyStatus `json:"status,omitempty"` + Type *TrustPolicyType `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/registries/predicates.go new file mode 100644 index 00000000000..2fd7c412260 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/predicates.go @@ -0,0 +1,55 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PrivateLinkResourceOperationPredicate) Matches(input PrivateLinkResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type RegistryOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p RegistryOperationPredicate) Matches(input Registry) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/registries/version.go b/resource-manager/containerregistry/2023-11-01-preview/registries/version.go new file mode 100644 index 00000000000..871c0d122a5 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/registries/version.go @@ -0,0 +1,10 @@ +package registries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/registries/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/README.md b/resource-manager/containerregistry/2023-11-01-preview/replications/README.md new file mode 100644 index 00000000000..cdad53cf67b --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/replications` Documentation + +The `replications` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/replications" +``` + + +### Client Initialization + +```go +client := replications.NewReplicationsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ReplicationsClient.Create` + +```go +ctx := context.TODO() +id := replications.NewReplicationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "replicationName") + +payload := replications.Replication{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationsClient.Delete` + +```go +ctx := context.TODO() +id := replications.NewReplicationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "replicationName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ReplicationsClient.Get` + +```go +ctx := context.TODO() +id := replications.NewReplicationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "replicationName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ReplicationsClient.List` + +```go +ctx := context.TODO() +id := replications.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ReplicationsClient.Update` + +```go +ctx := context.TODO() +id := replications.NewReplicationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "replicationName") + +payload := replications.ReplicationUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/client.go b/resource-manager/containerregistry/2023-11-01-preview/replications/client.go new file mode 100644 index 00000000000..3728690aaae --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/client.go @@ -0,0 +1,26 @@ +package replications + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationsClient struct { + Client *resourcemanager.Client +} + +func NewReplicationsClientWithBaseURI(sdkApi sdkEnv.Api) (*ReplicationsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "replications", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ReplicationsClient: %+v", err) + } + + return &ReplicationsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/constants.go b/resource-manager/containerregistry/2023-11-01-preview/replications/constants.go new file mode 100644 index 00000000000..6161484bd73 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/constants.go @@ -0,0 +1,104 @@ +package replications + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type ZoneRedundancy string + +const ( + ZoneRedundancyDisabled ZoneRedundancy = "Disabled" + ZoneRedundancyEnabled ZoneRedundancy = "Enabled" +) + +func PossibleValuesForZoneRedundancy() []string { + return []string{ + string(ZoneRedundancyDisabled), + string(ZoneRedundancyEnabled), + } +} + +func (s *ZoneRedundancy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseZoneRedundancy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseZoneRedundancy(input string) (*ZoneRedundancy, error) { + vals := map[string]ZoneRedundancy{ + "disabled": ZoneRedundancyDisabled, + "enabled": ZoneRedundancyEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ZoneRedundancy(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/id_registry.go b/resource-manager/containerregistry/2023-11-01-preview/replications/id_registry.go new file mode 100644 index 00000000000..401151f5c11 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/id_registry.go @@ -0,0 +1,130 @@ +package replications + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RegistryId{}) +} + +var _ resourceids.ResourceId = &RegistryId{} + +// RegistryId is a struct representing the Resource ID for a Registry +type RegistryId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string +} + +// NewRegistryID returns a new RegistryId struct +func NewRegistryID(subscriptionId string, resourceGroupName string, registryName string) RegistryId { + return RegistryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + } +} + +// ParseRegistryID parses 'input' into a RegistryId +func ParseRegistryID(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRegistryIDInsensitively parses 'input' case-insensitively into a RegistryId +// note: this method should only be used for API response data and not user input +func ParseRegistryIDInsensitively(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RegistryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + return nil +} + +// ValidateRegistryID checks that 'input' can be parsed as a Registry ID +func ValidateRegistryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRegistryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Registry ID +func (id RegistryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Registry ID +func (id RegistryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + } +} + +// String returns a human-readable description of this Registry ID +func (id RegistryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + } + return fmt.Sprintf("Registry (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/id_registry_test.go b/resource-manager/containerregistry/2023-11-01-preview/replications/id_registry_test.go new file mode 100644 index 00000000000..a86eaae560d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/id_registry_test.go @@ -0,0 +1,282 @@ +package replications + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RegistryId{} + +func TestNewRegistryID(t *testing.T) { + id := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } +} + +func TestFormatRegistryID(t *testing.T) { + actual := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRegistryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestParseRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestSegmentsForRegistryId(t *testing.T) { + segments := RegistryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RegistryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/id_replication.go b/resource-manager/containerregistry/2023-11-01-preview/replications/id_replication.go new file mode 100644 index 00000000000..b862238852f --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/id_replication.go @@ -0,0 +1,139 @@ +package replications + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ReplicationId{}) +} + +var _ resourceids.ResourceId = &ReplicationId{} + +// ReplicationId is a struct representing the Resource ID for a Replication +type ReplicationId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + ReplicationName string +} + +// NewReplicationID returns a new ReplicationId struct +func NewReplicationID(subscriptionId string, resourceGroupName string, registryName string, replicationName string) ReplicationId { + return ReplicationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + ReplicationName: replicationName, + } +} + +// ParseReplicationID parses 'input' into a ReplicationId +func ParseReplicationID(input string) (*ReplicationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReplicationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReplicationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseReplicationIDInsensitively parses 'input' case-insensitively into a ReplicationId +// note: this method should only be used for API response data and not user input +func ParseReplicationIDInsensitively(input string) (*ReplicationId, error) { + parser := resourceids.NewParserFromResourceIdType(&ReplicationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ReplicationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ReplicationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.ReplicationName, ok = input.Parsed["replicationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "replicationName", input) + } + + return nil +} + +// ValidateReplicationID checks that 'input' can be parsed as a Replication ID +func ValidateReplicationID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseReplicationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Replication ID +func (id ReplicationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/replications/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.ReplicationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Replication ID +func (id ReplicationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticReplications", "replications", "replications"), + resourceids.UserSpecifiedSegment("replicationName", "replicationName"), + } +} + +// String returns a human-readable description of this Replication ID +func (id ReplicationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Replication Name: %q", id.ReplicationName), + } + return fmt.Sprintf("Replication (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/id_replication_test.go b/resource-manager/containerregistry/2023-11-01-preview/replications/id_replication_test.go new file mode 100644 index 00000000000..aa5bf163782 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/id_replication_test.go @@ -0,0 +1,327 @@ +package replications + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ReplicationId{} + +func TestNewReplicationID(t *testing.T) { + id := NewReplicationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "replicationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.ReplicationName != "replicationName" { + t.Fatalf("Expected %q but got %q for Segment 'ReplicationName'", id.ReplicationName, "replicationName") + } +} + +func TestFormatReplicationID(t *testing.T) { + actual := NewReplicationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "replicationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/replications/replicationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseReplicationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/replications", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/replications/replicationName", + Expected: &ReplicationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + ReplicationName: "replicationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/replications/replicationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.ReplicationName != v.Expected.ReplicationName { + t.Fatalf("Expected %q but got %q for ReplicationName", v.Expected.ReplicationName, actual.ReplicationName) + } + + } +} + +func TestParseReplicationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ReplicationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/replications", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/rEpLiCaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/replications/replicationName", + Expected: &ReplicationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + ReplicationName: "replicationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/replications/replicationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/rEpLiCaTiOnS/rEpLiCaTiOnNaMe", + Expected: &ReplicationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + ReplicationName: "rEpLiCaTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/rEpLiCaTiOnS/rEpLiCaTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseReplicationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.ReplicationName != v.Expected.ReplicationName { + t.Fatalf("Expected %q but got %q for ReplicationName", v.Expected.ReplicationName, actual.ReplicationName) + } + + } +} + +func TestSegmentsForReplicationId(t *testing.T) { + segments := ReplicationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ReplicationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/method_create.go b/resource-manager/containerregistry/2023-11-01-preview/replications/method_create.go new file mode 100644 index 00000000000..f591043caae --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/method_create.go @@ -0,0 +1,75 @@ +package replications + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Replication +} + +// Create ... +func (c ReplicationsClient) Create(ctx context.Context, id ReplicationId, input Replication) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ReplicationsClient) CreateThenPoll(ctx context.Context, id ReplicationId, input Replication) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/replications/method_delete.go new file mode 100644 index 00000000000..29cc8f8370a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/method_delete.go @@ -0,0 +1,71 @@ +package replications + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ReplicationsClient) Delete(ctx context.Context, id ReplicationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ReplicationsClient) DeleteThenPoll(ctx context.Context, id ReplicationId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/replications/method_get.go new file mode 100644 index 00000000000..2e98060169b --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/method_get.go @@ -0,0 +1,53 @@ +package replications + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Replication +} + +// Get ... +func (c ReplicationsClient) Get(ctx context.Context, id ReplicationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Replication + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/replications/method_list.go new file mode 100644 index 00000000000..b2a62f6087f --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/method_list.go @@ -0,0 +1,105 @@ +package replications + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Replication +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Replication +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ReplicationsClient) List(ctx context.Context, id RegistryId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/replications", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Replication `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ReplicationsClient) ListComplete(ctx context.Context, id RegistryId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ReplicationOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ReplicationsClient) ListCompleteMatchingPredicate(ctx context.Context, id RegistryId, predicate ReplicationOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Replication, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/method_update.go b/resource-manager/containerregistry/2023-11-01-preview/replications/method_update.go new file mode 100644 index 00000000000..329dc24b163 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/method_update.go @@ -0,0 +1,75 @@ +package replications + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Replication +} + +// Update ... +func (c ReplicationsClient) Update(ctx context.Context, id ReplicationId, input ReplicationUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ReplicationsClient) UpdateThenPoll(ctx context.Context, id ReplicationId, input ReplicationUpdateParameters) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/model_replication.go b/resource-manager/containerregistry/2023-11-01-preview/replications/model_replication.go new file mode 100644 index 00000000000..932be700cb9 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/model_replication.go @@ -0,0 +1,18 @@ +package replications + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Replication struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ReplicationProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/model_replicationproperties.go b/resource-manager/containerregistry/2023-11-01-preview/replications/model_replicationproperties.go new file mode 100644 index 00000000000..3f63c28dc2b --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/model_replicationproperties.go @@ -0,0 +1,11 @@ +package replications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationProperties struct { + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RegionEndpointEnabled *bool `json:"regionEndpointEnabled,omitempty"` + Status *Status `json:"status,omitempty"` + ZoneRedundancy *ZoneRedundancy `json:"zoneRedundancy,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/model_replicationupdateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/replications/model_replicationupdateparameters.go new file mode 100644 index 00000000000..828a1fbc4ab --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/model_replicationupdateparameters.go @@ -0,0 +1,9 @@ +package replications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationUpdateParameters struct { + Properties *ReplicationUpdateParametersProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/model_replicationupdateparametersproperties.go b/resource-manager/containerregistry/2023-11-01-preview/replications/model_replicationupdateparametersproperties.go new file mode 100644 index 00000000000..856e3b415ff --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/model_replicationupdateparametersproperties.go @@ -0,0 +1,8 @@ +package replications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationUpdateParametersProperties struct { + RegionEndpointEnabled *bool `json:"regionEndpointEnabled,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/model_status.go b/resource-manager/containerregistry/2023-11-01-preview/replications/model_status.go new file mode 100644 index 00000000000..0e6acd8d6af --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/model_status.go @@ -0,0 +1,28 @@ +package replications + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Status struct { + DisplayStatus *string `json:"displayStatus,omitempty"` + Message *string `json:"message,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` +} + +func (o *Status) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *Status) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/replications/predicates.go new file mode 100644 index 00000000000..fbba0b6c312 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/predicates.go @@ -0,0 +1,32 @@ +package replications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ReplicationOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ReplicationOperationPredicate) Matches(input Replication) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/replications/version.go b/resource-manager/containerregistry/2023-11-01-preview/replications/version.go new file mode 100644 index 00000000000..ad77e3d8834 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/replications/version.go @@ -0,0 +1,10 @@ +package replications + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/replications/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/README.md b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/README.md new file mode 100644 index 00000000000..ae457d80f2c --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/scopemaps` Documentation + +The `scopemaps` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/scopemaps" +``` + + +### Client Initialization + +```go +client := scopemaps.NewScopeMapsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ScopeMapsClient.Create` + +```go +ctx := context.TODO() +id := scopemaps.NewScopeMapID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "scopeMapName") + +payload := scopemaps.ScopeMap{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ScopeMapsClient.Delete` + +```go +ctx := context.TODO() +id := scopemaps.NewScopeMapID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "scopeMapName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ScopeMapsClient.Get` + +```go +ctx := context.TODO() +id := scopemaps.NewScopeMapID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "scopeMapName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ScopeMapsClient.List` + +```go +ctx := context.TODO() +id := scopemaps.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ScopeMapsClient.Update` + +```go +ctx := context.TODO() +id := scopemaps.NewScopeMapID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "scopeMapName") + +payload := scopemaps.ScopeMapUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/client.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/client.go new file mode 100644 index 00000000000..fe18db9d17a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/client.go @@ -0,0 +1,26 @@ +package scopemaps + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScopeMapsClient struct { + Client *resourcemanager.Client +} + +func NewScopeMapsClientWithBaseURI(sdkApi sdkEnv.Api) (*ScopeMapsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "scopemaps", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ScopeMapsClient: %+v", err) + } + + return &ScopeMapsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/constants.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/constants.go new file mode 100644 index 00000000000..a3cdf65bba1 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/constants.go @@ -0,0 +1,63 @@ +package scopemaps + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_registry.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_registry.go new file mode 100644 index 00000000000..44d9827008d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_registry.go @@ -0,0 +1,130 @@ +package scopemaps + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RegistryId{}) +} + +var _ resourceids.ResourceId = &RegistryId{} + +// RegistryId is a struct representing the Resource ID for a Registry +type RegistryId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string +} + +// NewRegistryID returns a new RegistryId struct +func NewRegistryID(subscriptionId string, resourceGroupName string, registryName string) RegistryId { + return RegistryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + } +} + +// ParseRegistryID parses 'input' into a RegistryId +func ParseRegistryID(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRegistryIDInsensitively parses 'input' case-insensitively into a RegistryId +// note: this method should only be used for API response data and not user input +func ParseRegistryIDInsensitively(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RegistryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + return nil +} + +// ValidateRegistryID checks that 'input' can be parsed as a Registry ID +func ValidateRegistryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRegistryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Registry ID +func (id RegistryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Registry ID +func (id RegistryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + } +} + +// String returns a human-readable description of this Registry ID +func (id RegistryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + } + return fmt.Sprintf("Registry (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_registry_test.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_registry_test.go new file mode 100644 index 00000000000..36b644f14f8 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_registry_test.go @@ -0,0 +1,282 @@ +package scopemaps + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RegistryId{} + +func TestNewRegistryID(t *testing.T) { + id := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } +} + +func TestFormatRegistryID(t *testing.T) { + actual := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRegistryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestParseRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestSegmentsForRegistryId(t *testing.T) { + segments := RegistryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RegistryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_scopemap.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_scopemap.go new file mode 100644 index 00000000000..8bd3e7878e8 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_scopemap.go @@ -0,0 +1,139 @@ +package scopemaps + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ScopeMapId{}) +} + +var _ resourceids.ResourceId = &ScopeMapId{} + +// ScopeMapId is a struct representing the Resource ID for a Scope Map +type ScopeMapId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + ScopeMapName string +} + +// NewScopeMapID returns a new ScopeMapId struct +func NewScopeMapID(subscriptionId string, resourceGroupName string, registryName string, scopeMapName string) ScopeMapId { + return ScopeMapId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + ScopeMapName: scopeMapName, + } +} + +// ParseScopeMapID parses 'input' into a ScopeMapId +func ParseScopeMapID(input string) (*ScopeMapId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopeMapId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopeMapId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScopeMapIDInsensitively parses 'input' case-insensitively into a ScopeMapId +// note: this method should only be used for API response data and not user input +func ParseScopeMapIDInsensitively(input string) (*ScopeMapId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScopeMapId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScopeMapId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScopeMapId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.ScopeMapName, ok = input.Parsed["scopeMapName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scopeMapName", input) + } + + return nil +} + +// ValidateScopeMapID checks that 'input' can be parsed as a Scope Map ID +func ValidateScopeMapID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseScopeMapID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scope Map ID +func (id ScopeMapId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/scopeMaps/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.ScopeMapName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scope Map ID +func (id ScopeMapId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticScopeMaps", "scopeMaps", "scopeMaps"), + resourceids.UserSpecifiedSegment("scopeMapName", "scopeMapName"), + } +} + +// String returns a human-readable description of this Scope Map ID +func (id ScopeMapId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Scope Map Name: %q", id.ScopeMapName), + } + return fmt.Sprintf("Scope Map (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_scopemap_test.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_scopemap_test.go new file mode 100644 index 00000000000..993a27c7c45 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/id_scopemap_test.go @@ -0,0 +1,327 @@ +package scopemaps + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &ScopeMapId{} + +func TestNewScopeMapID(t *testing.T) { + id := NewScopeMapID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "scopeMapName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.ScopeMapName != "scopeMapName" { + t.Fatalf("Expected %q but got %q for Segment 'ScopeMapName'", id.ScopeMapName, "scopeMapName") + } +} + +func TestFormatScopeMapID(t *testing.T) { + actual := NewScopeMapID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "scopeMapName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/scopeMaps/scopeMapName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScopeMapID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopeMapId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/scopeMaps", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/scopeMaps/scopeMapName", + Expected: &ScopeMapId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + ScopeMapName: "scopeMapName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/scopeMaps/scopeMapName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopeMapID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.ScopeMapName != v.Expected.ScopeMapName { + t.Fatalf("Expected %q but got %q for ScopeMapName", v.Expected.ScopeMapName, actual.ScopeMapName) + } + + } +} + +func TestParseScopeMapIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScopeMapId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/scopeMaps", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/sCoPeMaPs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/scopeMaps/scopeMapName", + Expected: &ScopeMapId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + ScopeMapName: "scopeMapName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/scopeMaps/scopeMapName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/sCoPeMaPs/sCoPeMaPnAmE", + Expected: &ScopeMapId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + ScopeMapName: "sCoPeMaPnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/sCoPeMaPs/sCoPeMaPnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScopeMapIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.ScopeMapName != v.Expected.ScopeMapName { + t.Fatalf("Expected %q but got %q for ScopeMapName", v.Expected.ScopeMapName, actual.ScopeMapName) + } + + } +} + +func TestSegmentsForScopeMapId(t *testing.T) { + segments := ScopeMapId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScopeMapId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_create.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_create.go new file mode 100644 index 00000000000..d85a26ae4cc --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_create.go @@ -0,0 +1,75 @@ +package scopemaps + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ScopeMap +} + +// Create ... +func (c ScopeMapsClient) Create(ctx context.Context, id ScopeMapId, input ScopeMap) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c ScopeMapsClient) CreateThenPoll(ctx context.Context, id ScopeMapId, input ScopeMap) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_delete.go new file mode 100644 index 00000000000..6a6cd2fa49b --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_delete.go @@ -0,0 +1,71 @@ +package scopemaps + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c ScopeMapsClient) Delete(ctx context.Context, id ScopeMapId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c ScopeMapsClient) DeleteThenPoll(ctx context.Context, id ScopeMapId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_get.go new file mode 100644 index 00000000000..851cf9e9c46 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_get.go @@ -0,0 +1,53 @@ +package scopemaps + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ScopeMap +} + +// Get ... +func (c ScopeMapsClient) Get(ctx context.Context, id ScopeMapId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ScopeMap + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_list.go new file mode 100644 index 00000000000..6946f908ba2 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_list.go @@ -0,0 +1,105 @@ +package scopemaps + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ScopeMap +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ScopeMap +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ScopeMapsClient) List(ctx context.Context, id RegistryId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/scopeMaps", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ScopeMap `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ScopeMapsClient) ListComplete(ctx context.Context, id RegistryId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ScopeMapOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ScopeMapsClient) ListCompleteMatchingPredicate(ctx context.Context, id RegistryId, predicate ScopeMapOperationPredicate) (result ListCompleteResult, err error) { + items := make([]ScopeMap, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_update.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_update.go new file mode 100644 index 00000000000..5ca984a76ad --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/method_update.go @@ -0,0 +1,75 @@ +package scopemaps + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *ScopeMap +} + +// Update ... +func (c ScopeMapsClient) Update(ctx context.Context, id ScopeMapId, input ScopeMapUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ScopeMapsClient) UpdateThenPoll(ctx context.Context, id ScopeMapId, input ScopeMapUpdateParameters) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemap.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemap.go new file mode 100644 index 00000000000..844e87fc814 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemap.go @@ -0,0 +1,16 @@ +package scopemaps + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScopeMap struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ScopeMapProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemapproperties.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemapproperties.go new file mode 100644 index 00000000000..52d2be4afcf --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemapproperties.go @@ -0,0 +1,30 @@ +package scopemaps + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScopeMapProperties struct { + Actions []string `json:"actions"` + CreationDate *string `json:"creationDate,omitempty"` + Description *string `json:"description,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + Type *string `json:"type,omitempty"` +} + +func (o *ScopeMapProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ScopeMapProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemappropertiesupdateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemappropertiesupdateparameters.go new file mode 100644 index 00000000000..fb7304188c9 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemappropertiesupdateparameters.go @@ -0,0 +1,9 @@ +package scopemaps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScopeMapPropertiesUpdateParameters struct { + Actions *[]string `json:"actions,omitempty"` + Description *string `json:"description,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemapupdateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemapupdateparameters.go new file mode 100644 index 00000000000..d735edef15d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/model_scopemapupdateparameters.go @@ -0,0 +1,8 @@ +package scopemaps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScopeMapUpdateParameters struct { + Properties *ScopeMapPropertiesUpdateParameters `json:"properties,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/predicates.go new file mode 100644 index 00000000000..7ea335c428c --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/predicates.go @@ -0,0 +1,27 @@ +package scopemaps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScopeMapOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ScopeMapOperationPredicate) Matches(input ScopeMap) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/scopemaps/version.go b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/version.go new file mode 100644 index 00000000000..d765be028ca --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/scopemaps/version.go @@ -0,0 +1,10 @@ +package scopemaps + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/scopemaps/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/README.md b/resource-manager/containerregistry/2023-11-01-preview/tokens/README.md new file mode 100644 index 00000000000..83a28ec4c47 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/tokens` Documentation + +The `tokens` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/tokens" +``` + + +### Client Initialization + +```go +client := tokens.NewTokensClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TokensClient.Create` + +```go +ctx := context.TODO() +id := tokens.NewTokenID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "tokenName") + +payload := tokens.Token{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TokensClient.Delete` + +```go +ctx := context.TODO() +id := tokens.NewTokenID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "tokenName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `TokensClient.Get` + +```go +ctx := context.TODO() +id := tokens.NewTokenID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "tokenName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TokensClient.List` + +```go +ctx := context.TODO() +id := tokens.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `TokensClient.Update` + +```go +ctx := context.TODO() +id := tokens.NewTokenID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "tokenName") + +payload := tokens.TokenUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/client.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/client.go new file mode 100644 index 00000000000..496fade07ad --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/client.go @@ -0,0 +1,26 @@ +package tokens + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TokensClient struct { + Client *resourcemanager.Client +} + +func NewTokensClientWithBaseURI(sdkApi sdkEnv.Api) (*TokensClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "tokens", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TokensClient: %+v", err) + } + + return &TokensClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/constants.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/constants.go new file mode 100644 index 00000000000..85997819ca3 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/constants.go @@ -0,0 +1,186 @@ +package tokens + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type TokenCertificateName string + +const ( + TokenCertificateNameCertificateOne TokenCertificateName = "certificate1" + TokenCertificateNameCertificateTwo TokenCertificateName = "certificate2" +) + +func PossibleValuesForTokenCertificateName() []string { + return []string{ + string(TokenCertificateNameCertificateOne), + string(TokenCertificateNameCertificateTwo), + } +} + +func (s *TokenCertificateName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTokenCertificateName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTokenCertificateName(input string) (*TokenCertificateName, error) { + vals := map[string]TokenCertificateName{ + "certificate1": TokenCertificateNameCertificateOne, + "certificate2": TokenCertificateNameCertificateTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TokenCertificateName(input) + return &out, nil +} + +type TokenPasswordName string + +const ( + TokenPasswordNamePasswordOne TokenPasswordName = "password1" + TokenPasswordNamePasswordTwo TokenPasswordName = "password2" +) + +func PossibleValuesForTokenPasswordName() []string { + return []string{ + string(TokenPasswordNamePasswordOne), + string(TokenPasswordNamePasswordTwo), + } +} + +func (s *TokenPasswordName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTokenPasswordName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTokenPasswordName(input string) (*TokenPasswordName, error) { + vals := map[string]TokenPasswordName{ + "password1": TokenPasswordNamePasswordOne, + "password2": TokenPasswordNamePasswordTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TokenPasswordName(input) + return &out, nil +} + +type TokenStatus string + +const ( + TokenStatusDisabled TokenStatus = "disabled" + TokenStatusEnabled TokenStatus = "enabled" +) + +func PossibleValuesForTokenStatus() []string { + return []string{ + string(TokenStatusDisabled), + string(TokenStatusEnabled), + } +} + +func (s *TokenStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTokenStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTokenStatus(input string) (*TokenStatus, error) { + vals := map[string]TokenStatus{ + "disabled": TokenStatusDisabled, + "enabled": TokenStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TokenStatus(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/id_registry.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/id_registry.go new file mode 100644 index 00000000000..d282875d3e1 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/id_registry.go @@ -0,0 +1,130 @@ +package tokens + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RegistryId{}) +} + +var _ resourceids.ResourceId = &RegistryId{} + +// RegistryId is a struct representing the Resource ID for a Registry +type RegistryId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string +} + +// NewRegistryID returns a new RegistryId struct +func NewRegistryID(subscriptionId string, resourceGroupName string, registryName string) RegistryId { + return RegistryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + } +} + +// ParseRegistryID parses 'input' into a RegistryId +func ParseRegistryID(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRegistryIDInsensitively parses 'input' case-insensitively into a RegistryId +// note: this method should only be used for API response data and not user input +func ParseRegistryIDInsensitively(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RegistryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + return nil +} + +// ValidateRegistryID checks that 'input' can be parsed as a Registry ID +func ValidateRegistryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRegistryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Registry ID +func (id RegistryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Registry ID +func (id RegistryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + } +} + +// String returns a human-readable description of this Registry ID +func (id RegistryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + } + return fmt.Sprintf("Registry (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/id_registry_test.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/id_registry_test.go new file mode 100644 index 00000000000..7ad32e526fd --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/id_registry_test.go @@ -0,0 +1,282 @@ +package tokens + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RegistryId{} + +func TestNewRegistryID(t *testing.T) { + id := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } +} + +func TestFormatRegistryID(t *testing.T) { + actual := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRegistryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestParseRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestSegmentsForRegistryId(t *testing.T) { + segments := RegistryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RegistryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/id_token.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/id_token.go new file mode 100644 index 00000000000..5abaa812d77 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/id_token.go @@ -0,0 +1,139 @@ +package tokens + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TokenId{}) +} + +var _ resourceids.ResourceId = &TokenId{} + +// TokenId is a struct representing the Resource ID for a Token +type TokenId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + TokenName string +} + +// NewTokenID returns a new TokenId struct +func NewTokenID(subscriptionId string, resourceGroupName string, registryName string, tokenName string) TokenId { + return TokenId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + TokenName: tokenName, + } +} + +// ParseTokenID parses 'input' into a TokenId +func ParseTokenID(input string) (*TokenId, error) { + parser := resourceids.NewParserFromResourceIdType(&TokenId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TokenId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTokenIDInsensitively parses 'input' case-insensitively into a TokenId +// note: this method should only be used for API response data and not user input +func ParseTokenIDInsensitively(input string) (*TokenId, error) { + parser := resourceids.NewParserFromResourceIdType(&TokenId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TokenId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TokenId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.TokenName, ok = input.Parsed["tokenName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tokenName", input) + } + + return nil +} + +// ValidateTokenID checks that 'input' can be parsed as a Token ID +func ValidateTokenID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseTokenID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Token ID +func (id TokenId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/tokens/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.TokenName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Token ID +func (id TokenId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticTokens", "tokens", "tokens"), + resourceids.UserSpecifiedSegment("tokenName", "tokenName"), + } +} + +// String returns a human-readable description of this Token ID +func (id TokenId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Token Name: %q", id.TokenName), + } + return fmt.Sprintf("Token (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/id_token_test.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/id_token_test.go new file mode 100644 index 00000000000..4f2d22e49d6 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/id_token_test.go @@ -0,0 +1,327 @@ +package tokens + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TokenId{} + +func TestNewTokenID(t *testing.T) { + id := NewTokenID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "tokenName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.TokenName != "tokenName" { + t.Fatalf("Expected %q but got %q for Segment 'TokenName'", id.TokenName, "tokenName") + } +} + +func TestFormatTokenID(t *testing.T) { + actual := NewTokenID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "tokenName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/tokens/tokenName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTokenID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TokenId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/tokens", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/tokens/tokenName", + Expected: &TokenId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + TokenName: "tokenName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/tokens/tokenName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTokenID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.TokenName != v.Expected.TokenName { + t.Fatalf("Expected %q but got %q for TokenName", v.Expected.TokenName, actual.TokenName) + } + + } +} + +func TestParseTokenIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TokenId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/tokens", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/tOkEnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/tokens/tokenName", + Expected: &TokenId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + TokenName: "tokenName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/tokens/tokenName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/tOkEnS/tOkEnNaMe", + Expected: &TokenId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + TokenName: "tOkEnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/tOkEnS/tOkEnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTokenIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.TokenName != v.Expected.TokenName { + t.Fatalf("Expected %q but got %q for TokenName", v.Expected.TokenName, actual.TokenName) + } + + } +} + +func TestSegmentsForTokenId(t *testing.T) { + segments := TokenId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TokenId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/method_create.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/method_create.go new file mode 100644 index 00000000000..acafb7916a6 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/method_create.go @@ -0,0 +1,75 @@ +package tokens + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Token +} + +// Create ... +func (c TokensClient) Create(ctx context.Context, id TokenId, input Token) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c TokensClient) CreateThenPoll(ctx context.Context, id TokenId, input Token) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/method_delete.go new file mode 100644 index 00000000000..7ed822bf15b --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/method_delete.go @@ -0,0 +1,71 @@ +package tokens + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c TokensClient) Delete(ctx context.Context, id TokenId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c TokensClient) DeleteThenPoll(ctx context.Context, id TokenId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/method_get.go new file mode 100644 index 00000000000..6f07e5caa5a --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/method_get.go @@ -0,0 +1,53 @@ +package tokens + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Token +} + +// Get ... +func (c TokensClient) Get(ctx context.Context, id TokenId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Token + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/method_list.go new file mode 100644 index 00000000000..fddf1b402cb --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/method_list.go @@ -0,0 +1,105 @@ +package tokens + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Token +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Token +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c TokensClient) List(ctx context.Context, id RegistryId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/tokens", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Token `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c TokensClient) ListComplete(ctx context.Context, id RegistryId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, TokenOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TokensClient) ListCompleteMatchingPredicate(ctx context.Context, id RegistryId, predicate TokenOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Token, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/method_update.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/method_update.go new file mode 100644 index 00000000000..a6865eadc35 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/method_update.go @@ -0,0 +1,75 @@ +package tokens + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Token +} + +// Update ... +func (c TokensClient) Update(ctx context.Context, id TokenId, input TokenUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c TokensClient) UpdateThenPoll(ctx context.Context, id TokenId, input TokenUpdateParameters) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/model_token.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_token.go new file mode 100644 index 00000000000..c459084be8e --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_token.go @@ -0,0 +1,16 @@ +package tokens + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Token struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *TokenProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokencertificate.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokencertificate.go new file mode 100644 index 00000000000..8e4a5d3cde7 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokencertificate.go @@ -0,0 +1,29 @@ +package tokens + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TokenCertificate struct { + EncodedPemCertificate *string `json:"encodedPemCertificate,omitempty"` + Expiry *string `json:"expiry,omitempty"` + Name *TokenCertificateName `json:"name,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` +} + +func (o *TokenCertificate) GetExpiryAsTime() (*time.Time, error) { + if o.Expiry == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Expiry, "2006-01-02T15:04:05Z07:00") +} + +func (o *TokenCertificate) SetExpiryAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Expiry = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokencredentialsproperties.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokencredentialsproperties.go new file mode 100644 index 00000000000..de0203f7e63 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokencredentialsproperties.go @@ -0,0 +1,9 @@ +package tokens + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TokenCredentialsProperties struct { + Certificates *[]TokenCertificate `json:"certificates,omitempty"` + Passwords *[]TokenPassword `json:"passwords,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenpassword.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenpassword.go new file mode 100644 index 00000000000..f46a71eab86 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenpassword.go @@ -0,0 +1,41 @@ +package tokens + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TokenPassword struct { + CreationTime *string `json:"creationTime,omitempty"` + Expiry *string `json:"expiry,omitempty"` + Name *TokenPasswordName `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} + +func (o *TokenPassword) GetCreationTimeAsTime() (*time.Time, error) { + if o.CreationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *TokenPassword) SetCreationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationTime = &formatted +} + +func (o *TokenPassword) GetExpiryAsTime() (*time.Time, error) { + if o.Expiry == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Expiry, "2006-01-02T15:04:05Z07:00") +} + +func (o *TokenPassword) SetExpiryAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Expiry = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenproperties.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenproperties.go new file mode 100644 index 00000000000..a2f60da2fa5 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenproperties.go @@ -0,0 +1,30 @@ +package tokens + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TokenProperties struct { + CreationDate *string `json:"creationDate,omitempty"` + Credentials *TokenCredentialsProperties `json:"credentials,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ScopeMapId *string `json:"scopeMapId,omitempty"` + Status *TokenStatus `json:"status,omitempty"` +} + +func (o *TokenProperties) GetCreationDateAsTime() (*time.Time, error) { + if o.CreationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *TokenProperties) SetCreationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreationDate = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenupdateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenupdateparameters.go new file mode 100644 index 00000000000..3a13b669078 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenupdateparameters.go @@ -0,0 +1,8 @@ +package tokens + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TokenUpdateParameters struct { + Properties *TokenUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenupdateproperties.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenupdateproperties.go new file mode 100644 index 00000000000..c02a611e1cd --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/model_tokenupdateproperties.go @@ -0,0 +1,10 @@ +package tokens + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TokenUpdateProperties struct { + Credentials *TokenCredentialsProperties `json:"credentials,omitempty"` + ScopeMapId *string `json:"scopeMapId,omitempty"` + Status *TokenStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/predicates.go new file mode 100644 index 00000000000..e76d969798d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/predicates.go @@ -0,0 +1,27 @@ +package tokens + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TokenOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p TokenOperationPredicate) Matches(input Token) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/tokens/version.go b/resource-manager/containerregistry/2023-11-01-preview/tokens/version.go new file mode 100644 index 00000000000..b929d26d429 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/tokens/version.go @@ -0,0 +1,10 @@ +package tokens + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/tokens/2023-11-01-preview" +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/README.md b/resource-manager/containerregistry/2023-11-01-preview/webhooks/README.md new file mode 100644 index 00000000000..bf7f2c18531 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/README.md @@ -0,0 +1,148 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/webhooks` Documentation + +The `webhooks` SDK allows for interaction with Azure Resource Manager `containerregistry` (API Version `2023-11-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-11-01-preview/webhooks" +``` + + +### Client Initialization + +```go +client := webhooks.NewWebHooksClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `WebHooksClient.Create` + +```go +ctx := context.TODO() +id := webhooks.NewWebHookID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "webHookName") + +payload := webhooks.WebhookCreateParameters{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebHooksClient.Delete` + +```go +ctx := context.TODO() +id := webhooks.NewWebHookID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "webHookName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `WebHooksClient.Get` + +```go +ctx := context.TODO() +id := webhooks.NewWebHookID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "webHookName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebHooksClient.GetCallbackConfig` + +```go +ctx := context.TODO() +id := webhooks.NewWebHookID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "webHookName") + +read, err := client.GetCallbackConfig(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebHooksClient.List` + +```go +ctx := context.TODO() +id := webhooks.NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WebHooksClient.ListEvents` + +```go +ctx := context.TODO() +id := webhooks.NewWebHookID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "webHookName") + +// alternatively `client.ListEvents(ctx, id)` can be used to do batched pagination +items, err := client.ListEventsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `WebHooksClient.Ping` + +```go +ctx := context.TODO() +id := webhooks.NewWebHookID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "webHookName") + +read, err := client.Ping(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `WebHooksClient.Update` + +```go +ctx := context.TODO() +id := webhooks.NewWebHookID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "webHookName") + +payload := webhooks.WebhookUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/client.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/client.go new file mode 100644 index 00000000000..8fce4a9da49 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/client.go @@ -0,0 +1,26 @@ +package webhooks + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebHooksClient struct { + Client *resourcemanager.Client +} + +func NewWebHooksClientWithBaseURI(sdkApi sdkEnv.Api) (*WebHooksClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "webhooks", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating WebHooksClient: %+v", err) + } + + return &WebHooksClient{ + Client: client, + }, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/constants.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/constants.go new file mode 100644 index 00000000000..8da25bd4a15 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/constants.go @@ -0,0 +1,154 @@ +package webhooks + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type WebhookAction string + +const ( + WebhookActionChartDelete WebhookAction = "chart_delete" + WebhookActionChartPush WebhookAction = "chart_push" + WebhookActionDelete WebhookAction = "delete" + WebhookActionPush WebhookAction = "push" + WebhookActionQuarantine WebhookAction = "quarantine" +) + +func PossibleValuesForWebhookAction() []string { + return []string{ + string(WebhookActionChartDelete), + string(WebhookActionChartPush), + string(WebhookActionDelete), + string(WebhookActionPush), + string(WebhookActionQuarantine), + } +} + +func (s *WebhookAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWebhookAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWebhookAction(input string) (*WebhookAction, error) { + vals := map[string]WebhookAction{ + "chart_delete": WebhookActionChartDelete, + "chart_push": WebhookActionChartPush, + "delete": WebhookActionDelete, + "push": WebhookActionPush, + "quarantine": WebhookActionQuarantine, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WebhookAction(input) + return &out, nil +} + +type WebhookStatus string + +const ( + WebhookStatusDisabled WebhookStatus = "disabled" + WebhookStatusEnabled WebhookStatus = "enabled" +) + +func PossibleValuesForWebhookStatus() []string { + return []string{ + string(WebhookStatusDisabled), + string(WebhookStatusEnabled), + } +} + +func (s *WebhookStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseWebhookStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseWebhookStatus(input string) (*WebhookStatus, error) { + vals := map[string]WebhookStatus{ + "disabled": WebhookStatusDisabled, + "enabled": WebhookStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := WebhookStatus(input) + return &out, nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/id_registry.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/id_registry.go new file mode 100644 index 00000000000..a6a3919b565 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/id_registry.go @@ -0,0 +1,130 @@ +package webhooks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RegistryId{}) +} + +var _ resourceids.ResourceId = &RegistryId{} + +// RegistryId is a struct representing the Resource ID for a Registry +type RegistryId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string +} + +// NewRegistryID returns a new RegistryId struct +func NewRegistryID(subscriptionId string, resourceGroupName string, registryName string) RegistryId { + return RegistryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + } +} + +// ParseRegistryID parses 'input' into a RegistryId +func ParseRegistryID(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRegistryIDInsensitively parses 'input' case-insensitively into a RegistryId +// note: this method should only be used for API response data and not user input +func ParseRegistryIDInsensitively(input string) (*RegistryId, error) { + parser := resourceids.NewParserFromResourceIdType(&RegistryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RegistryId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RegistryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + return nil +} + +// ValidateRegistryID checks that 'input' can be parsed as a Registry ID +func ValidateRegistryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRegistryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Registry ID +func (id RegistryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Registry ID +func (id RegistryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + } +} + +// String returns a human-readable description of this Registry ID +func (id RegistryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + } + return fmt.Sprintf("Registry (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/id_registry_test.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/id_registry_test.go new file mode 100644 index 00000000000..cd195b31d98 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/id_registry_test.go @@ -0,0 +1,282 @@ +package webhooks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RegistryId{} + +func TestNewRegistryID(t *testing.T) { + id := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } +} + +func TestFormatRegistryID(t *testing.T) { + actual := NewRegistryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRegistryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestParseRegistryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RegistryId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Expected: &RegistryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRegistryIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + } +} + +func TestSegmentsForRegistryId(t *testing.T) { + segments := RegistryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RegistryId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/id_webhook.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/id_webhook.go new file mode 100644 index 00000000000..aac7b42f1e7 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/id_webhook.go @@ -0,0 +1,139 @@ +package webhooks + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WebHookId{}) +} + +var _ resourceids.ResourceId = &WebHookId{} + +// WebHookId is a struct representing the Resource ID for a Web Hook +type WebHookId struct { + SubscriptionId string + ResourceGroupName string + RegistryName string + WebHookName string +} + +// NewWebHookID returns a new WebHookId struct +func NewWebHookID(subscriptionId string, resourceGroupName string, registryName string, webHookName string) WebHookId { + return WebHookId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RegistryName: registryName, + WebHookName: webHookName, + } +} + +// ParseWebHookID parses 'input' into a WebHookId +func ParseWebHookID(input string) (*WebHookId, error) { + parser := resourceids.NewParserFromResourceIdType(&WebHookId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WebHookId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWebHookIDInsensitively parses 'input' case-insensitively into a WebHookId +// note: this method should only be used for API response data and not user input +func ParseWebHookIDInsensitively(input string) (*WebHookId, error) { + parser := resourceids.NewParserFromResourceIdType(&WebHookId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WebHookId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WebHookId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RegistryName, ok = input.Parsed["registryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "registryName", input) + } + + if id.WebHookName, ok = input.Parsed["webHookName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "webHookName", input) + } + + return nil +} + +// ValidateWebHookID checks that 'input' can be parsed as a Web Hook ID +func ValidateWebHookID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWebHookID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Web Hook ID +func (id WebHookId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerRegistry/registries/%s/webHooks/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RegistryName, id.WebHookName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Web Hook ID +func (id WebHookId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftContainerRegistry", "Microsoft.ContainerRegistry", "Microsoft.ContainerRegistry"), + resourceids.StaticSegment("staticRegistries", "registries", "registries"), + resourceids.UserSpecifiedSegment("registryName", "registryName"), + resourceids.StaticSegment("staticWebHooks", "webHooks", "webHooks"), + resourceids.UserSpecifiedSegment("webHookName", "webHookName"), + } +} + +// String returns a human-readable description of this Web Hook ID +func (id WebHookId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Registry Name: %q", id.RegistryName), + fmt.Sprintf("Web Hook Name: %q", id.WebHookName), + } + return fmt.Sprintf("Web Hook (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/id_webhook_test.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/id_webhook_test.go new file mode 100644 index 00000000000..48b371ec679 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/id_webhook_test.go @@ -0,0 +1,327 @@ +package webhooks + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &WebHookId{} + +func TestNewWebHookID(t *testing.T) { + id := NewWebHookID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "webHookName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RegistryName != "registryName" { + t.Fatalf("Expected %q but got %q for Segment 'RegistryName'", id.RegistryName, "registryName") + } + + if id.WebHookName != "webHookName" { + t.Fatalf("Expected %q but got %q for Segment 'WebHookName'", id.WebHookName, "webHookName") + } +} + +func TestFormatWebHookID(t *testing.T) { + actual := NewWebHookID("12345678-1234-9876-4563-123456789012", "example-resource-group", "registryName", "webHookName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/webHooks/webHookName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseWebHookID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WebHookId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/webHooks", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/webHooks/webHookName", + Expected: &WebHookId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + WebHookName: "webHookName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/webHooks/webHookName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWebHookID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.WebHookName != v.Expected.WebHookName { + t.Fatalf("Expected %q but got %q for WebHookName", v.Expected.WebHookName, actual.WebHookName) + } + + } +} + +func TestParseWebHookIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WebHookId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/webHooks", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/wEbHoOkS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/webHooks/webHookName", + Expected: &WebHookId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RegistryName: "registryName", + WebHookName: "webHookName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ContainerRegistry/registries/registryName/webHooks/webHookName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/wEbHoOkS/wEbHoOkNaMe", + Expected: &WebHookId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RegistryName: "rEgIsTrYnAmE", + WebHookName: "wEbHoOkNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOnTaInErReGiStRy/rEgIsTrIeS/rEgIsTrYnAmE/wEbHoOkS/wEbHoOkNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseWebHookIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RegistryName != v.Expected.RegistryName { + t.Fatalf("Expected %q but got %q for RegistryName", v.Expected.RegistryName, actual.RegistryName) + } + + if actual.WebHookName != v.Expected.WebHookName { + t.Fatalf("Expected %q but got %q for WebHookName", v.Expected.WebHookName, actual.WebHookName) + } + + } +} + +func TestSegmentsForWebHookId(t *testing.T) { + segments := WebHookId{}.Segments() + if len(segments) == 0 { + t.Fatalf("WebHookId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_create.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_create.go new file mode 100644 index 00000000000..03efa380344 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_create.go @@ -0,0 +1,75 @@ +package webhooks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Webhook +} + +// Create ... +func (c WebHooksClient) Create(ctx context.Context, id WebHookId, input WebhookCreateParameters) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c WebHooksClient) CreateThenPoll(ctx context.Context, id WebHookId, input WebhookCreateParameters) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_delete.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_delete.go new file mode 100644 index 00000000000..0ec1675fc79 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_delete.go @@ -0,0 +1,71 @@ +package webhooks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c WebHooksClient) Delete(ctx context.Context, id WebHookId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c WebHooksClient) DeleteThenPoll(ctx context.Context, id WebHookId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_get.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_get.go new file mode 100644 index 00000000000..dfb306899c1 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_get.go @@ -0,0 +1,53 @@ +package webhooks + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Webhook +} + +// Get ... +func (c WebHooksClient) Get(ctx context.Context, id WebHookId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Webhook + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_getcallbackconfig.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_getcallbackconfig.go new file mode 100644 index 00000000000..ecb3c8aded6 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_getcallbackconfig.go @@ -0,0 +1,54 @@ +package webhooks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetCallbackConfigOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CallbackConfig +} + +// GetCallbackConfig ... +func (c WebHooksClient) GetCallbackConfig(ctx context.Context, id WebHookId) (result GetCallbackConfigOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getCallbackConfig", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CallbackConfig + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_list.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_list.go new file mode 100644 index 00000000000..9f1e715304c --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_list.go @@ -0,0 +1,105 @@ +package webhooks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Webhook +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Webhook +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c WebHooksClient) List(ctx context.Context, id RegistryId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/webHooks", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Webhook `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c WebHooksClient) ListComplete(ctx context.Context, id RegistryId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, WebhookOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WebHooksClient) ListCompleteMatchingPredicate(ctx context.Context, id RegistryId, predicate WebhookOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Webhook, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_listevents.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_listevents.go new file mode 100644 index 00000000000..c43b2895799 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_listevents.go @@ -0,0 +1,105 @@ +package webhooks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListEventsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Event +} + +type ListEventsCompleteResult struct { + LatestHttpResponse *http.Response + Items []Event +} + +type ListEventsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListEventsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListEvents ... +func (c WebHooksClient) ListEvents(ctx context.Context, id WebHookId) (result ListEventsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &ListEventsCustomPager{}, + Path: fmt.Sprintf("%s/listEvents", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Event `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListEventsComplete retrieves all the results into a single object +func (c WebHooksClient) ListEventsComplete(ctx context.Context, id WebHookId) (ListEventsCompleteResult, error) { + return c.ListEventsCompleteMatchingPredicate(ctx, id, EventOperationPredicate{}) +} + +// ListEventsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c WebHooksClient) ListEventsCompleteMatchingPredicate(ctx context.Context, id WebHookId, predicate EventOperationPredicate) (result ListEventsCompleteResult, err error) { + items := make([]Event, 0) + + resp, err := c.ListEvents(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListEventsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_ping.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_ping.go new file mode 100644 index 00000000000..a56359e2560 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_ping.go @@ -0,0 +1,54 @@ +package webhooks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PingOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EventInfo +} + +// Ping ... +func (c WebHooksClient) Ping(ctx context.Context, id WebHookId) (result PingOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/ping", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model EventInfo + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_update.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_update.go new file mode 100644 index 00000000000..99522fc1d57 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/method_update.go @@ -0,0 +1,75 @@ +package webhooks + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Webhook +} + +// Update ... +func (c WebHooksClient) Update(ctx context.Context, id WebHookId, input WebhookUpdateParameters) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c WebHooksClient) UpdateThenPoll(ctx context.Context, id WebHookId, input WebhookUpdateParameters) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_actor.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_actor.go new file mode 100644 index 00000000000..76f36dcfea3 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_actor.go @@ -0,0 +1,8 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Actor struct { + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_callbackconfig.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_callbackconfig.go new file mode 100644 index 00000000000..70c51edd742 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_callbackconfig.go @@ -0,0 +1,9 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CallbackConfig struct { + CustomHeaders *map[string]string `json:"customHeaders,omitempty"` + ServiceUri string `json:"serviceUri"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_event.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_event.go new file mode 100644 index 00000000000..485b94a1cde --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_event.go @@ -0,0 +1,10 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Event struct { + EventRequestMessage *EventRequestMessage `json:"eventRequestMessage,omitempty"` + EventResponseMessage *EventResponseMessage `json:"eventResponseMessage,omitempty"` + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventcontent.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventcontent.go new file mode 100644 index 00000000000..ea6b275bec2 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventcontent.go @@ -0,0 +1,32 @@ +package webhooks + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventContent struct { + Action *string `json:"action,omitempty"` + Actor *Actor `json:"actor,omitempty"` + Id *string `json:"id,omitempty"` + Request *Request `json:"request,omitempty"` + Source *Source `json:"source,omitempty"` + Target *Target `json:"target,omitempty"` + Timestamp *string `json:"timestamp,omitempty"` +} + +func (o *EventContent) GetTimestampAsTime() (*time.Time, error) { + if o.Timestamp == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Timestamp, "2006-01-02T15:04:05Z07:00") +} + +func (o *EventContent) SetTimestampAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Timestamp = &formatted +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventinfo.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventinfo.go new file mode 100644 index 00000000000..87c33e7f07d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventinfo.go @@ -0,0 +1,8 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventInfo struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventrequestmessage.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventrequestmessage.go new file mode 100644 index 00000000000..56f335b1ea9 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventrequestmessage.go @@ -0,0 +1,12 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventRequestMessage struct { + Content *EventContent `json:"content,omitempty"` + Headers *map[string]string `json:"headers,omitempty"` + Method *string `json:"method,omitempty"` + RequestUri *string `json:"requestUri,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventresponsemessage.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventresponsemessage.go new file mode 100644 index 00000000000..ece546cd808 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_eventresponsemessage.go @@ -0,0 +1,12 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventResponseMessage struct { + Content *string `json:"content,omitempty"` + Headers *map[string]string `json:"headers,omitempty"` + ReasonPhrase *string `json:"reasonPhrase,omitempty"` + StatusCode *string `json:"statusCode,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_request.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_request.go new file mode 100644 index 00000000000..87e35e6473d --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_request.go @@ -0,0 +1,12 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Request struct { + Addr *string `json:"addr,omitempty"` + Host *string `json:"host,omitempty"` + Id *string `json:"id,omitempty"` + Method *string `json:"method,omitempty"` + Useragent *string `json:"useragent,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_source.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_source.go new file mode 100644 index 00000000000..6c986c31c04 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_source.go @@ -0,0 +1,9 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Source struct { + Addr *string `json:"addr,omitempty"` + InstanceID *string `json:"instanceID,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_target.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_target.go new file mode 100644 index 00000000000..4cbc07d50de --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_target.go @@ -0,0 +1,16 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Target struct { + Digest *string `json:"digest,omitempty"` + Length *int64 `json:"length,omitempty"` + MediaType *string `json:"mediaType,omitempty"` + Name *string `json:"name,omitempty"` + Repository *string `json:"repository,omitempty"` + Size *int64 `json:"size,omitempty"` + Tag *string `json:"tag,omitempty"` + Url *string `json:"url,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhook.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhook.go new file mode 100644 index 00000000000..66a677d90be --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhook.go @@ -0,0 +1,18 @@ +package webhooks + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Webhook struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *WebhookProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookcreateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookcreateparameters.go new file mode 100644 index 00000000000..7a7d23fef42 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookcreateparameters.go @@ -0,0 +1,10 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebhookCreateParameters struct { + Location string `json:"location"` + Properties *WebhookPropertiesCreateParameters `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookproperties.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookproperties.go new file mode 100644 index 00000000000..987c402d3c1 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookproperties.go @@ -0,0 +1,11 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebhookProperties struct { + Actions []WebhookAction `json:"actions"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + Scope *string `json:"scope,omitempty"` + Status *WebhookStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookpropertiescreateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookpropertiescreateparameters.go new file mode 100644 index 00000000000..5c31614b8c7 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookpropertiescreateparameters.go @@ -0,0 +1,12 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebhookPropertiesCreateParameters struct { + Actions []WebhookAction `json:"actions"` + CustomHeaders *map[string]string `json:"customHeaders,omitempty"` + Scope *string `json:"scope,omitempty"` + ServiceUri string `json:"serviceUri"` + Status *WebhookStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookpropertiesupdateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookpropertiesupdateparameters.go new file mode 100644 index 00000000000..17d1bcfa8ce --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookpropertiesupdateparameters.go @@ -0,0 +1,12 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebhookPropertiesUpdateParameters struct { + Actions *[]WebhookAction `json:"actions,omitempty"` + CustomHeaders *map[string]string `json:"customHeaders,omitempty"` + Scope *string `json:"scope,omitempty"` + ServiceUri *string `json:"serviceUri,omitempty"` + Status *WebhookStatus `json:"status,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookupdateparameters.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookupdateparameters.go new file mode 100644 index 00000000000..2cf0241fdf6 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/model_webhookupdateparameters.go @@ -0,0 +1,9 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WebhookUpdateParameters struct { + Properties *WebhookPropertiesUpdateParameters `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/predicates.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/predicates.go new file mode 100644 index 00000000000..946905715c8 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/predicates.go @@ -0,0 +1,45 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EventOperationPredicate struct { + Id *string +} + +func (p EventOperationPredicate) Matches(input Event) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + return true +} + +type WebhookOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p WebhookOperationPredicate) Matches(input Webhook) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/containerregistry/2023-11-01-preview/webhooks/version.go b/resource-manager/containerregistry/2023-11-01-preview/webhooks/version.go new file mode 100644 index 00000000000..122c100eee8 --- /dev/null +++ b/resource-manager/containerregistry/2023-11-01-preview/webhooks/version.go @@ -0,0 +1,10 @@ +package webhooks + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-11-01-preview" + +func userAgent() string { + return "hashicorp/go-azure-sdk/webhooks/2023-11-01-preview" +} diff --git a/resource-manager/netapp/2024-07-01/snapshotpolicylistvolumes/model_replicationobject.go b/resource-manager/netapp/2024-07-01/snapshotpolicylistvolumes/model_replicationobject.go index 9b3d69a13d1..dc5ec9e68aa 100644 --- a/resource-manager/netapp/2024-07-01/snapshotpolicylistvolumes/model_replicationobject.go +++ b/resource-manager/netapp/2024-07-01/snapshotpolicylistvolumes/model_replicationobject.go @@ -7,7 +7,7 @@ type ReplicationObject struct { EndpointType *EndpointType `json:"endpointType,omitempty"` RemotePath *RemotePath `json:"remotePath,omitempty"` RemoteVolumeRegion *string `json:"remoteVolumeRegion,omitempty"` - RemoteVolumeResourceId string `json:"remoteVolumeResourceId"` + RemoteVolumeResourceId *string `json:"remoteVolumeResourceId,omitempty"` ReplicationId *string `json:"replicationId,omitempty"` ReplicationSchedule *ReplicationSchedule `json:"replicationSchedule,omitempty"` } diff --git a/resource-manager/netapp/2024-07-01/volumegroups/model_replicationobject.go b/resource-manager/netapp/2024-07-01/volumegroups/model_replicationobject.go index 9762765c472..cfd29860cb0 100644 --- a/resource-manager/netapp/2024-07-01/volumegroups/model_replicationobject.go +++ b/resource-manager/netapp/2024-07-01/volumegroups/model_replicationobject.go @@ -7,7 +7,7 @@ type ReplicationObject struct { EndpointType *EndpointType `json:"endpointType,omitempty"` RemotePath *RemotePath `json:"remotePath,omitempty"` RemoteVolumeRegion *string `json:"remoteVolumeRegion,omitempty"` - RemoteVolumeResourceId string `json:"remoteVolumeResourceId"` + RemoteVolumeResourceId *string `json:"remoteVolumeResourceId,omitempty"` ReplicationId *string `json:"replicationId,omitempty"` ReplicationSchedule *ReplicationSchedule `json:"replicationSchedule,omitempty"` } diff --git a/resource-manager/netapp/2024-07-01/volumes/model_replicationobject.go b/resource-manager/netapp/2024-07-01/volumes/model_replicationobject.go index 724f0c50bd0..23def4d7281 100644 --- a/resource-manager/netapp/2024-07-01/volumes/model_replicationobject.go +++ b/resource-manager/netapp/2024-07-01/volumes/model_replicationobject.go @@ -7,7 +7,7 @@ type ReplicationObject struct { EndpointType *EndpointType `json:"endpointType,omitempty"` RemotePath *RemotePath `json:"remotePath,omitempty"` RemoteVolumeRegion *string `json:"remoteVolumeRegion,omitempty"` - RemoteVolumeResourceId string `json:"remoteVolumeResourceId"` + RemoteVolumeResourceId *string `json:"remoteVolumeResourceId,omitempty"` ReplicationId *string `json:"replicationId,omitempty"` ReplicationSchedule *ReplicationSchedule `json:"replicationSchedule,omitempty"` } diff --git a/resource-manager/redisenterprise/2024-10-01/client.go b/resource-manager/redisenterprise/2024-10-01/client.go new file mode 100644 index 00000000000..a1d63b47993 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/client.go @@ -0,0 +1,55 @@ +package v2024_10_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2024-10-01/databases" + "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2024-10-01/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2024-10-01/privatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2024-10-01/redisenterprise" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + Databases *databases.DatabasesClient + PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient + PrivateLinkResources *privatelinkresources.PrivateLinkResourcesClient + RedisEnterprise *redisenterprise.RedisEnterpriseClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + databasesClient, err := databases.NewDatabasesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Databases client: %+v", err) + } + configureFunc(databasesClient.Client) + + privateEndpointConnectionsClient, err := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateEndpointConnections client: %+v", err) + } + configureFunc(privateEndpointConnectionsClient.Client) + + privateLinkResourcesClient, err := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateLinkResources client: %+v", err) + } + configureFunc(privateLinkResourcesClient.Client) + + redisEnterpriseClient, err := redisenterprise.NewRedisEnterpriseClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RedisEnterprise client: %+v", err) + } + configureFunc(redisEnterpriseClient.Client) + + return &Client{ + Databases: databasesClient, + PrivateEndpointConnections: privateEndpointConnectionsClient, + PrivateLinkResources: privateLinkResourcesClient, + RedisEnterprise: redisEnterpriseClient, + }, nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/README.md b/resource-manager/redisenterprise/2024-10-01/databases/README.md new file mode 100644 index 00000000000..5a538577fdc --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/README.md @@ -0,0 +1,217 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2024-10-01/databases` Documentation + +The `databases` SDK allows for interaction with Azure Resource Manager `redisenterprise` (API Version `2024-10-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2024-10-01/databases" +``` + + +### Client Initialization + +```go +client := databases.NewDatabasesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DatabasesClient.Create` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.Database{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Delete` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Export` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.ExportClusterParameters{ + // ... +} + + +if err := client.ExportThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Flush` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.FlushParameters{ + // ... +} + + +if err := client.FlushThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.ForceLinkToReplicationGroup` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.ForceLinkParameters{ + // ... +} + + +if err := client.ForceLinkToReplicationGroupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.ForceUnlink` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.ForceUnlinkParameters{ + // ... +} + + +if err := client.ForceUnlinkThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Get` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabasesClient.Import` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.ImportClusterParameters{ + // ... +} + + +if err := client.ImportThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.ListByCluster` + +```go +ctx := context.TODO() +id := databases.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +// alternatively `client.ListByCluster(ctx, id)` can be used to do batched pagination +items, err := client.ListByClusterComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DatabasesClient.ListKeys` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +read, err := client.ListKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DatabasesClient.RegenerateKey` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.RegenerateKeyParameters{ + // ... +} + + +if err := client.RegenerateKeyThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DatabasesClient.Update` + +```go +ctx := context.TODO() +id := databases.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := databases.DatabaseUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/redisenterprise/2024-10-01/databases/client.go b/resource-manager/redisenterprise/2024-10-01/databases/client.go new file mode 100644 index 00000000000..87de2d4fe59 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/client.go @@ -0,0 +1,26 @@ +package databases + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasesClient struct { + Client *resourcemanager.Client +} + +func NewDatabasesClientWithBaseURI(sdkApi sdkEnv.Api) (*DatabasesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "databases", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DatabasesClient: %+v", err) + } + + return &DatabasesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/constants.go b/resource-manager/redisenterprise/2024-10-01/databases/constants.go new file mode 100644 index 00000000000..e6c274c2c21 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/constants.go @@ -0,0 +1,457 @@ +package databases + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessKeyType string + +const ( + AccessKeyTypePrimary AccessKeyType = "Primary" + AccessKeyTypeSecondary AccessKeyType = "Secondary" +) + +func PossibleValuesForAccessKeyType() []string { + return []string{ + string(AccessKeyTypePrimary), + string(AccessKeyTypeSecondary), + } +} + +func (s *AccessKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessKeyType(input string) (*AccessKeyType, error) { + vals := map[string]AccessKeyType{ + "primary": AccessKeyTypePrimary, + "secondary": AccessKeyTypeSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessKeyType(input) + return &out, nil +} + +type AofFrequency string + +const ( + AofFrequencyAlways AofFrequency = "always" + AofFrequencyOnes AofFrequency = "1s" +) + +func PossibleValuesForAofFrequency() []string { + return []string{ + string(AofFrequencyAlways), + string(AofFrequencyOnes), + } +} + +func (s *AofFrequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAofFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAofFrequency(input string) (*AofFrequency, error) { + vals := map[string]AofFrequency{ + "always": AofFrequencyAlways, + "1s": AofFrequencyOnes, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AofFrequency(input) + return &out, nil +} + +type ClusteringPolicy string + +const ( + ClusteringPolicyEnterpriseCluster ClusteringPolicy = "EnterpriseCluster" + ClusteringPolicyOSSCluster ClusteringPolicy = "OSSCluster" +) + +func PossibleValuesForClusteringPolicy() []string { + return []string{ + string(ClusteringPolicyEnterpriseCluster), + string(ClusteringPolicyOSSCluster), + } +} + +func (s *ClusteringPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusteringPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClusteringPolicy(input string) (*ClusteringPolicy, error) { + vals := map[string]ClusteringPolicy{ + "enterprisecluster": ClusteringPolicyEnterpriseCluster, + "osscluster": ClusteringPolicyOSSCluster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClusteringPolicy(input) + return &out, nil +} + +type EvictionPolicy string + +const ( + EvictionPolicyAllKeysLFU EvictionPolicy = "AllKeysLFU" + EvictionPolicyAllKeysLRU EvictionPolicy = "AllKeysLRU" + EvictionPolicyAllKeysRandom EvictionPolicy = "AllKeysRandom" + EvictionPolicyNoEviction EvictionPolicy = "NoEviction" + EvictionPolicyVolatileLFU EvictionPolicy = "VolatileLFU" + EvictionPolicyVolatileLRU EvictionPolicy = "VolatileLRU" + EvictionPolicyVolatileRandom EvictionPolicy = "VolatileRandom" + EvictionPolicyVolatileTTL EvictionPolicy = "VolatileTTL" +) + +func PossibleValuesForEvictionPolicy() []string { + return []string{ + string(EvictionPolicyAllKeysLFU), + string(EvictionPolicyAllKeysLRU), + string(EvictionPolicyAllKeysRandom), + string(EvictionPolicyNoEviction), + string(EvictionPolicyVolatileLFU), + string(EvictionPolicyVolatileLRU), + string(EvictionPolicyVolatileRandom), + string(EvictionPolicyVolatileTTL), + } +} + +func (s *EvictionPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEvictionPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEvictionPolicy(input string) (*EvictionPolicy, error) { + vals := map[string]EvictionPolicy{ + "allkeyslfu": EvictionPolicyAllKeysLFU, + "allkeyslru": EvictionPolicyAllKeysLRU, + "allkeysrandom": EvictionPolicyAllKeysRandom, + "noeviction": EvictionPolicyNoEviction, + "volatilelfu": EvictionPolicyVolatileLFU, + "volatilelru": EvictionPolicyVolatileLRU, + "volatilerandom": EvictionPolicyVolatileRandom, + "volatilettl": EvictionPolicyVolatileTTL, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EvictionPolicy(input) + return &out, nil +} + +type LinkState string + +const ( + LinkStateLinkFailed LinkState = "LinkFailed" + LinkStateLinked LinkState = "Linked" + LinkStateLinking LinkState = "Linking" + LinkStateUnlinkFailed LinkState = "UnlinkFailed" + LinkStateUnlinking LinkState = "Unlinking" +) + +func PossibleValuesForLinkState() []string { + return []string{ + string(LinkStateLinkFailed), + string(LinkStateLinked), + string(LinkStateLinking), + string(LinkStateUnlinkFailed), + string(LinkStateUnlinking), + } +} + +func (s *LinkState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLinkState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLinkState(input string) (*LinkState, error) { + vals := map[string]LinkState{ + "linkfailed": LinkStateLinkFailed, + "linked": LinkStateLinked, + "linking": LinkStateLinking, + "unlinkfailed": LinkStateUnlinkFailed, + "unlinking": LinkStateUnlinking, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LinkState(input) + return &out, nil +} + +type Protocol string + +const ( + ProtocolEncrypted Protocol = "Encrypted" + ProtocolPlaintext Protocol = "Plaintext" +) + +func PossibleValuesForProtocol() []string { + return []string{ + string(ProtocolEncrypted), + string(ProtocolPlaintext), + } +} + +func (s *Protocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProtocol(input string) (*Protocol, error) { + vals := map[string]Protocol{ + "encrypted": ProtocolEncrypted, + "plaintext": ProtocolPlaintext, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Protocol(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type RdbFrequency string + +const ( + RdbFrequencyOneTwoh RdbFrequency = "12h" + RdbFrequencyOneh RdbFrequency = "1h" + RdbFrequencySixh RdbFrequency = "6h" +) + +func PossibleValuesForRdbFrequency() []string { + return []string{ + string(RdbFrequencyOneTwoh), + string(RdbFrequencyOneh), + string(RdbFrequencySixh), + } +} + +func (s *RdbFrequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRdbFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRdbFrequency(input string) (*RdbFrequency, error) { + vals := map[string]RdbFrequency{ + "12h": RdbFrequencyOneTwoh, + "1h": RdbFrequencyOneh, + "6h": RdbFrequencySixh, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RdbFrequency(input) + return &out, nil +} + +type ResourceState string + +const ( + ResourceStateCreateFailed ResourceState = "CreateFailed" + ResourceStateCreating ResourceState = "Creating" + ResourceStateDeleteFailed ResourceState = "DeleteFailed" + ResourceStateDeleting ResourceState = "Deleting" + ResourceStateDisableFailed ResourceState = "DisableFailed" + ResourceStateDisabled ResourceState = "Disabled" + ResourceStateDisabling ResourceState = "Disabling" + ResourceStateEnableFailed ResourceState = "EnableFailed" + ResourceStateEnabling ResourceState = "Enabling" + ResourceStateRunning ResourceState = "Running" + ResourceStateScaling ResourceState = "Scaling" + ResourceStateScalingFailed ResourceState = "ScalingFailed" + ResourceStateUpdateFailed ResourceState = "UpdateFailed" + ResourceStateUpdating ResourceState = "Updating" +) + +func PossibleValuesForResourceState() []string { + return []string{ + string(ResourceStateCreateFailed), + string(ResourceStateCreating), + string(ResourceStateDeleteFailed), + string(ResourceStateDeleting), + string(ResourceStateDisableFailed), + string(ResourceStateDisabled), + string(ResourceStateDisabling), + string(ResourceStateEnableFailed), + string(ResourceStateEnabling), + string(ResourceStateRunning), + string(ResourceStateScaling), + string(ResourceStateScalingFailed), + string(ResourceStateUpdateFailed), + string(ResourceStateUpdating), + } +} + +func (s *ResourceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceState(input string) (*ResourceState, error) { + vals := map[string]ResourceState{ + "createfailed": ResourceStateCreateFailed, + "creating": ResourceStateCreating, + "deletefailed": ResourceStateDeleteFailed, + "deleting": ResourceStateDeleting, + "disablefailed": ResourceStateDisableFailed, + "disabled": ResourceStateDisabled, + "disabling": ResourceStateDisabling, + "enablefailed": ResourceStateEnableFailed, + "enabling": ResourceStateEnabling, + "running": ResourceStateRunning, + "scaling": ResourceStateScaling, + "scalingfailed": ResourceStateScalingFailed, + "updatefailed": ResourceStateUpdateFailed, + "updating": ResourceStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceState(input) + return &out, nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/id_database.go b/resource-manager/redisenterprise/2024-10-01/databases/id_database.go new file mode 100644 index 00000000000..c2402902641 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/id_database.go @@ -0,0 +1,139 @@ +package databases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DatabaseId{}) +} + +var _ resourceids.ResourceId = &DatabaseId{} + +// DatabaseId is a struct representing the Resource ID for a Database +type DatabaseId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string + DatabaseName string +} + +// NewDatabaseID returns a new DatabaseId struct +func NewDatabaseID(subscriptionId string, resourceGroupName string, redisEnterpriseName string, databaseName string) DatabaseId { + return DatabaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + DatabaseName: databaseName, + } +} + +// ParseDatabaseID parses 'input' into a DatabaseId +func ParseDatabaseID(input string) (*DatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDatabaseIDInsensitively parses 'input' case-insensitively into a DatabaseId +// note: this method should only be used for API response data and not user input +func ParseDatabaseIDInsensitively(input string) (*DatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DatabaseId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + return nil +} + +// ValidateDatabaseID checks that 'input' can be parsed as a Database ID +func ValidateDatabaseID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Database ID +func (id DatabaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s/databases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName, id.DatabaseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Database ID +func (id DatabaseId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + } +} + +// String returns a human-readable description of this Database ID +func (id DatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + } + return fmt.Sprintf("Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/id_database_test.go b/resource-manager/redisenterprise/2024-10-01/databases/id_database_test.go new file mode 100644 index 00000000000..5dbc49dabaf --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/id_database_test.go @@ -0,0 +1,327 @@ +package databases + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DatabaseId{} + +func TestNewDatabaseID(t *testing.T) { + id := NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } +} + +func TestFormatDatabaseID(t *testing.T) { + actual := NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + } +} + +func TestParseDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + DatabaseName: "dAtAbAsEnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + } +} + +func TestSegmentsForDatabaseId(t *testing.T) { + segments := DatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DatabaseId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/id_redisenterprise.go b/resource-manager/redisenterprise/2024-10-01/databases/id_redisenterprise.go new file mode 100644 index 00000000000..c872e92eb24 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/id_redisenterprise.go @@ -0,0 +1,130 @@ +package databases + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RedisEnterpriseId{}) +} + +var _ resourceids.ResourceId = &RedisEnterpriseId{} + +// RedisEnterpriseId is a struct representing the Resource ID for a Redis Enterprise +type RedisEnterpriseId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string +} + +// NewRedisEnterpriseID returns a new RedisEnterpriseId struct +func NewRedisEnterpriseID(subscriptionId string, resourceGroupName string, redisEnterpriseName string) RedisEnterpriseId { + return RedisEnterpriseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + } +} + +// ParseRedisEnterpriseID parses 'input' into a RedisEnterpriseId +func ParseRedisEnterpriseID(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRedisEnterpriseIDInsensitively parses 'input' case-insensitively into a RedisEnterpriseId +// note: this method should only be used for API response data and not user input +func ParseRedisEnterpriseIDInsensitively(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RedisEnterpriseId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + return nil +} + +// ValidateRedisEnterpriseID checks that 'input' can be parsed as a Redis Enterprise ID +func ValidateRedisEnterpriseID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRedisEnterpriseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redis Enterprise ID +func (id RedisEnterpriseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redis Enterprise ID +func (id RedisEnterpriseId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + } +} + +// String returns a human-readable description of this Redis Enterprise ID +func (id RedisEnterpriseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + } + return fmt.Sprintf("Redis Enterprise (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/id_redisenterprise_test.go b/resource-manager/redisenterprise/2024-10-01/databases/id_redisenterprise_test.go new file mode 100644 index 00000000000..06c2b187531 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/id_redisenterprise_test.go @@ -0,0 +1,282 @@ +package databases + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RedisEnterpriseId{} + +func TestNewRedisEnterpriseID(t *testing.T) { + id := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } +} + +func TestFormatRedisEnterpriseID(t *testing.T) { + actual := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRedisEnterpriseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestParseRedisEnterpriseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestSegmentsForRedisEnterpriseId(t *testing.T) { + segments := RedisEnterpriseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RedisEnterpriseId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/method_create.go b/resource-manager/redisenterprise/2024-10-01/databases/method_create.go new file mode 100644 index 00000000000..ef7027e79c5 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/method_create.go @@ -0,0 +1,75 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +// Create ... +func (c DatabasesClient) Create(ctx context.Context, id DatabaseId, input Database) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c DatabasesClient) CreateThenPoll(ctx context.Context, id DatabaseId, input Database) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/method_delete.go b/resource-manager/redisenterprise/2024-10-01/databases/method_delete.go new file mode 100644 index 00000000000..dc03e526611 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/method_delete.go @@ -0,0 +1,71 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c DatabasesClient) Delete(ctx context.Context, id DatabaseId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c DatabasesClient) DeleteThenPoll(ctx context.Context, id DatabaseId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/method_export.go b/resource-manager/redisenterprise/2024-10-01/databases/method_export.go new file mode 100644 index 00000000000..a35c1aaff53 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/method_export.go @@ -0,0 +1,74 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Export ... +func (c DatabasesClient) Export(ctx context.Context, id DatabaseId, input ExportClusterParameters) (result ExportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/export", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ExportThenPoll performs Export then polls until it's completed +func (c DatabasesClient) ExportThenPoll(ctx context.Context, id DatabaseId, input ExportClusterParameters) error { + result, err := c.Export(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Export: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Export: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/method_flush.go b/resource-manager/redisenterprise/2024-10-01/databases/method_flush.go new file mode 100644 index 00000000000..aaf7666fdf0 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/method_flush.go @@ -0,0 +1,74 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FlushOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Flush ... +func (c DatabasesClient) Flush(ctx context.Context, id DatabaseId, input FlushParameters) (result FlushOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/flush", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// FlushThenPoll performs Flush then polls until it's completed +func (c DatabasesClient) FlushThenPoll(ctx context.Context, id DatabaseId, input FlushParameters) error { + result, err := c.Flush(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Flush: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Flush: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/method_forcelinktoreplicationgroup.go b/resource-manager/redisenterprise/2024-10-01/databases/method_forcelinktoreplicationgroup.go new file mode 100644 index 00000000000..020c282d01d --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/method_forcelinktoreplicationgroup.go @@ -0,0 +1,73 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceLinkToReplicationGroupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ForceLinkToReplicationGroup ... +func (c DatabasesClient) ForceLinkToReplicationGroup(ctx context.Context, id DatabaseId, input ForceLinkParameters) (result ForceLinkToReplicationGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/forceLinkToReplicationGroup", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ForceLinkToReplicationGroupThenPoll performs ForceLinkToReplicationGroup then polls until it's completed +func (c DatabasesClient) ForceLinkToReplicationGroupThenPoll(ctx context.Context, id DatabaseId, input ForceLinkParameters) error { + result, err := c.ForceLinkToReplicationGroup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ForceLinkToReplicationGroup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ForceLinkToReplicationGroup: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/method_forceunlink.go b/resource-manager/redisenterprise/2024-10-01/databases/method_forceunlink.go new file mode 100644 index 00000000000..bc8f9b988c8 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/method_forceunlink.go @@ -0,0 +1,74 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceUnlinkOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// ForceUnlink ... +func (c DatabasesClient) ForceUnlink(ctx context.Context, id DatabaseId, input ForceUnlinkParameters) (result ForceUnlinkOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/forceUnlink", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ForceUnlinkThenPoll performs ForceUnlink then polls until it's completed +func (c DatabasesClient) ForceUnlinkThenPoll(ctx context.Context, id DatabaseId, input ForceUnlinkParameters) error { + result, err := c.ForceUnlink(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ForceUnlink: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ForceUnlink: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/method_get.go b/resource-manager/redisenterprise/2024-10-01/databases/method_get.go new file mode 100644 index 00000000000..df1a873b818 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/method_get.go @@ -0,0 +1,53 @@ +package databases + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +// Get ... +func (c DatabasesClient) Get(ctx context.Context, id DatabaseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Database + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/method_import.go b/resource-manager/redisenterprise/2024-10-01/databases/method_import.go new file mode 100644 index 00000000000..39022d59c43 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/method_import.go @@ -0,0 +1,74 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Import ... +func (c DatabasesClient) Import(ctx context.Context, id DatabaseId, input ImportClusterParameters) (result ImportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/import", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ImportThenPoll performs Import then polls until it's completed +func (c DatabasesClient) ImportThenPoll(ctx context.Context, id DatabaseId, input ImportClusterParameters) error { + result, err := c.Import(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Import: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Import: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/method_listbycluster.go b/resource-manager/redisenterprise/2024-10-01/databases/method_listbycluster.go new file mode 100644 index 00000000000..c98456fed45 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/method_listbycluster.go @@ -0,0 +1,105 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByClusterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Database +} + +type ListByClusterCompleteResult struct { + LatestHttpResponse *http.Response + Items []Database +} + +type ListByClusterCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByClusterCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByCluster ... +func (c DatabasesClient) ListByCluster(ctx context.Context, id RedisEnterpriseId) (result ListByClusterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByClusterCustomPager{}, + Path: fmt.Sprintf("%s/databases", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Database `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByClusterComplete retrieves all the results into a single object +func (c DatabasesClient) ListByClusterComplete(ctx context.Context, id RedisEnterpriseId) (ListByClusterCompleteResult, error) { + return c.ListByClusterCompleteMatchingPredicate(ctx, id, DatabaseOperationPredicate{}) +} + +// ListByClusterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DatabasesClient) ListByClusterCompleteMatchingPredicate(ctx context.Context, id RedisEnterpriseId, predicate DatabaseOperationPredicate) (result ListByClusterCompleteResult, err error) { + items := make([]Database, 0) + + resp, err := c.ListByCluster(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByClusterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/method_listkeys.go b/resource-manager/redisenterprise/2024-10-01/databases/method_listkeys.go new file mode 100644 index 00000000000..147674d8dcf --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/method_listkeys.go @@ -0,0 +1,54 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AccessKeys +} + +// ListKeys ... +func (c DatabasesClient) ListKeys(ctx context.Context, id DatabaseId) (result ListKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listKeys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model AccessKeys + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/method_regeneratekey.go b/resource-manager/redisenterprise/2024-10-01/databases/method_regeneratekey.go new file mode 100644 index 00000000000..f745c705aba --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/method_regeneratekey.go @@ -0,0 +1,75 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateKeyOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AccessKeys +} + +// RegenerateKey ... +func (c DatabasesClient) RegenerateKey(ctx context.Context, id DatabaseId, input RegenerateKeyParameters) (result RegenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// RegenerateKeyThenPoll performs RegenerateKey then polls until it's completed +func (c DatabasesClient) RegenerateKeyThenPoll(ctx context.Context, id DatabaseId, input RegenerateKeyParameters) error { + result, err := c.RegenerateKey(ctx, id, input) + if err != nil { + return fmt.Errorf("performing RegenerateKey: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RegenerateKey: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/method_update.go b/resource-manager/redisenterprise/2024-10-01/databases/method_update.go new file mode 100644 index 00000000000..21a9006463c --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/method_update.go @@ -0,0 +1,75 @@ +package databases + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +// Update ... +func (c DatabasesClient) Update(ctx context.Context, id DatabaseId, input DatabaseUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c DatabasesClient) UpdateThenPoll(ctx context.Context, id DatabaseId, input DatabaseUpdate) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_accesskeys.go b/resource-manager/redisenterprise/2024-10-01/databases/model_accesskeys.go new file mode 100644 index 00000000000..d2c730f7d54 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_accesskeys.go @@ -0,0 +1,9 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessKeys struct { + PrimaryKey *string `json:"primaryKey,omitempty"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_database.go b/resource-manager/redisenterprise/2024-10-01/databases/model_database.go new file mode 100644 index 00000000000..a9880a7432b --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_database.go @@ -0,0 +1,11 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Database struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_databaseproperties.go b/resource-manager/redisenterprise/2024-10-01/databases/model_databaseproperties.go new file mode 100644 index 00000000000..85d805064ef --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_databaseproperties.go @@ -0,0 +1,16 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseProperties struct { + ClientProtocol *Protocol `json:"clientProtocol,omitempty"` + ClusteringPolicy *ClusteringPolicy `json:"clusteringPolicy,omitempty"` + EvictionPolicy *EvictionPolicy `json:"evictionPolicy,omitempty"` + GeoReplication *DatabasePropertiesGeoReplication `json:"geoReplication,omitempty"` + Modules *[]Module `json:"modules,omitempty"` + Persistence *Persistence `json:"persistence,omitempty"` + Port *int64 `json:"port,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ResourceState *ResourceState `json:"resourceState,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_databasepropertiesgeoreplication.go b/resource-manager/redisenterprise/2024-10-01/databases/model_databasepropertiesgeoreplication.go new file mode 100644 index 00000000000..1aa0445a637 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_databasepropertiesgeoreplication.go @@ -0,0 +1,9 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasePropertiesGeoReplication struct { + GroupNickname *string `json:"groupNickname,omitempty"` + LinkedDatabases *[]LinkedDatabase `json:"linkedDatabases,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_databaseupdate.go b/resource-manager/redisenterprise/2024-10-01/databases/model_databaseupdate.go new file mode 100644 index 00000000000..038f991ecef --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_databaseupdate.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseUpdate struct { + Properties *DatabaseProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_exportclusterparameters.go b/resource-manager/redisenterprise/2024-10-01/databases/model_exportclusterparameters.go new file mode 100644 index 00000000000..35c3ad5e660 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_exportclusterparameters.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportClusterParameters struct { + SasUri string `json:"sasUri"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_flushparameters.go b/resource-manager/redisenterprise/2024-10-01/databases/model_flushparameters.go new file mode 100644 index 00000000000..7ac8c6633b3 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_flushparameters.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FlushParameters struct { + Ids *[]string `json:"ids,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_forcelinkparameters.go b/resource-manager/redisenterprise/2024-10-01/databases/model_forcelinkparameters.go new file mode 100644 index 00000000000..7c8c1ecd012 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_forcelinkparameters.go @@ -0,0 +1,9 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceLinkParameters struct { + GroupNickname string `json:"groupNickname"` + LinkedDatabases []LinkedDatabase `json:"linkedDatabases"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_forceunlinkparameters.go b/resource-manager/redisenterprise/2024-10-01/databases/model_forceunlinkparameters.go new file mode 100644 index 00000000000..f3f97fbc4bf --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_forceunlinkparameters.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceUnlinkParameters struct { + Ids []string `json:"ids"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_importclusterparameters.go b/resource-manager/redisenterprise/2024-10-01/databases/model_importclusterparameters.go new file mode 100644 index 00000000000..fa3be54a50f --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_importclusterparameters.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportClusterParameters struct { + SasUris []string `json:"sasUris"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_linkeddatabase.go b/resource-manager/redisenterprise/2024-10-01/databases/model_linkeddatabase.go new file mode 100644 index 00000000000..215442f62da --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_linkeddatabase.go @@ -0,0 +1,9 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedDatabase struct { + Id *string `json:"id,omitempty"` + State *LinkState `json:"state,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_module.go b/resource-manager/redisenterprise/2024-10-01/databases/model_module.go new file mode 100644 index 00000000000..bde6a3ad4d4 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_module.go @@ -0,0 +1,10 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Module struct { + Args *string `json:"args,omitempty"` + Name string `json:"name"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_persistence.go b/resource-manager/redisenterprise/2024-10-01/databases/model_persistence.go new file mode 100644 index 00000000000..fd1e748a3dd --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_persistence.go @@ -0,0 +1,11 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Persistence struct { + AofEnabled *bool `json:"aofEnabled,omitempty"` + AofFrequency *AofFrequency `json:"aofFrequency,omitempty"` + RdbEnabled *bool `json:"rdbEnabled,omitempty"` + RdbFrequency *RdbFrequency `json:"rdbFrequency,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_regeneratekeyparameters.go b/resource-manager/redisenterprise/2024-10-01/databases/model_regeneratekeyparameters.go new file mode 100644 index 00000000000..fa84cc54ad5 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_regeneratekeyparameters.go @@ -0,0 +1,8 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateKeyParameters struct { + KeyType AccessKeyType `json:"keyType"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/predicates.go b/resource-manager/redisenterprise/2024-10-01/databases/predicates.go new file mode 100644 index 00000000000..3d55136d0fb --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/predicates.go @@ -0,0 +1,27 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseOperationPredicate) Matches(input Database) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/version.go b/resource-manager/redisenterprise/2024-10-01/databases/version.go new file mode 100644 index 00000000000..53706fab471 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/version.go @@ -0,0 +1,10 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-10-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/databases/2024-10-01" +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/README.md b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/README.md new file mode 100644 index 00000000000..26afd376079 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/README.md @@ -0,0 +1,81 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2024-10-01/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with Azure Resource Manager `redisenterprise` (API Version `2024-10-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2024-10-01/privateendpointconnections" +``` + + +### Client Initialization + +```go +client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "privateEndpointConnectionName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Get` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "privateEndpointConnectionName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.List` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Put` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "privateEndpointConnectionName") + +payload := privateendpointconnections.PrivateEndpointConnection{ + // ... +} + + +if err := client.PutThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/client.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/client.go new file mode 100644 index 00000000000..50eaf09dcce --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/client.go @@ -0,0 +1,26 @@ +package privateendpointconnections + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateEndpointConnectionsClient: %+v", err) + } + + return &PrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/constants.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/constants.go new file mode 100644 index 00000000000..c5850609650 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/constants.go @@ -0,0 +1,101 @@ +package privateendpointconnections + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_privateendpointconnection.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 00000000000..26ef2c08058 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,139 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PrivateEndpointConnectionId{}) +} + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, redisEnterpriseName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionName"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..6361371497e --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "privateEndpointConnectionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionName" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionName") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "privateEndpointConnectionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections/privateEndpointConnectionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections/privateEndpointConnectionName", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + PrivateEndpointConnectionName: "privateEndpointConnectionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/privateEndpointConnections/privateEndpointConnectionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_redisenterprise.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_redisenterprise.go new file mode 100644 index 00000000000..6449511cb2f --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_redisenterprise.go @@ -0,0 +1,130 @@ +package privateendpointconnections + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RedisEnterpriseId{}) +} + +var _ resourceids.ResourceId = &RedisEnterpriseId{} + +// RedisEnterpriseId is a struct representing the Resource ID for a Redis Enterprise +type RedisEnterpriseId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string +} + +// NewRedisEnterpriseID returns a new RedisEnterpriseId struct +func NewRedisEnterpriseID(subscriptionId string, resourceGroupName string, redisEnterpriseName string) RedisEnterpriseId { + return RedisEnterpriseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + } +} + +// ParseRedisEnterpriseID parses 'input' into a RedisEnterpriseId +func ParseRedisEnterpriseID(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRedisEnterpriseIDInsensitively parses 'input' case-insensitively into a RedisEnterpriseId +// note: this method should only be used for API response data and not user input +func ParseRedisEnterpriseIDInsensitively(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RedisEnterpriseId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + return nil +} + +// ValidateRedisEnterpriseID checks that 'input' can be parsed as a Redis Enterprise ID +func ValidateRedisEnterpriseID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRedisEnterpriseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redis Enterprise ID +func (id RedisEnterpriseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redis Enterprise ID +func (id RedisEnterpriseId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + } +} + +// String returns a human-readable description of this Redis Enterprise ID +func (id RedisEnterpriseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + } + return fmt.Sprintf("Redis Enterprise (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_redisenterprise_test.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_redisenterprise_test.go new file mode 100644 index 00000000000..d5ce5afd6e9 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/id_redisenterprise_test.go @@ -0,0 +1,282 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RedisEnterpriseId{} + +func TestNewRedisEnterpriseID(t *testing.T) { + id := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } +} + +func TestFormatRedisEnterpriseID(t *testing.T) { + actual := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRedisEnterpriseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestParseRedisEnterpriseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestSegmentsForRedisEnterpriseId(t *testing.T) { + segments := RedisEnterpriseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RedisEnterpriseId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_delete.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_delete.go new file mode 100644 index 00000000000..63c26e8f27f --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_delete.go @@ -0,0 +1,71 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c PrivateEndpointConnectionsClient) Delete(ctx context.Context, id PrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateEndpointConnectionsClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_get.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_get.go new file mode 100644 index 00000000000..351242746d4 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_get.go @@ -0,0 +1,53 @@ +package privateendpointconnections + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Get ... +func (c PrivateEndpointConnectionsClient) Get(ctx context.Context, id PrivateEndpointConnectionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnection + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_list.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_list.go new file mode 100644 index 00000000000..fbc4f5b3c1c --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_list.go @@ -0,0 +1,54 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnectionListResult +} + +// List ... +func (c PrivateEndpointConnectionsClient) List(ctx context.Context, id RedisEnterpriseId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnectionListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_put.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_put.go new file mode 100644 index 00000000000..8f6e3022d15 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/method_put.go @@ -0,0 +1,74 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PutOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Put ... +func (c PrivateEndpointConnectionsClient) Put(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result PutOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// PutThenPoll performs Put then polls until it's completed +func (c PrivateEndpointConnectionsClient) PutThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) error { + result, err := c.Put(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Put: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Put: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpoint.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpoint.go new file mode 100644 index 00000000000..1bc8cf2a97c --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpoint.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 00000000000..fde7f4db0fc --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpointconnectionlistresult.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpointconnectionlistresult.go new file mode 100644 index 00000000000..92a9ecb105a --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpointconnectionlistresult.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionListResult struct { + Value *[]PrivateEndpointConnection `json:"value,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..549d255f069 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..ec3f7a9f24c --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/version.go b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/version.go new file mode 100644 index 00000000000..dcbda23c7b3 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privateendpointconnections/version.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-10-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privateendpointconnections/2024-10-01" +} diff --git a/resource-manager/redisenterprise/2024-10-01/privatelinkresources/README.md b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/README.md new file mode 100644 index 00000000000..1db32e6e415 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2024-10-01/privatelinkresources` Documentation + +The `privatelinkresources` SDK allows for interaction with Azure Resource Manager `redisenterprise` (API Version `2024-10-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2024-10-01/privatelinkresources" +``` + + +### Client Initialization + +```go +client := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkResourcesClient.ListByCluster` + +```go +ctx := context.TODO() +id := privatelinkresources.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +read, err := client.ListByCluster(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/redisenterprise/2024-10-01/privatelinkresources/client.go b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/client.go new file mode 100644 index 00000000000..28c00b21f03 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/client.go @@ -0,0 +1,26 @@ +package privatelinkresources + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourcesClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkResourcesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "privatelinkresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkResourcesClient: %+v", err) + } + + return &PrivateLinkResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/privatelinkresources/id_redisenterprise.go b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/id_redisenterprise.go new file mode 100644 index 00000000000..b57b6c2bd42 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/id_redisenterprise.go @@ -0,0 +1,130 @@ +package privatelinkresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RedisEnterpriseId{}) +} + +var _ resourceids.ResourceId = &RedisEnterpriseId{} + +// RedisEnterpriseId is a struct representing the Resource ID for a Redis Enterprise +type RedisEnterpriseId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string +} + +// NewRedisEnterpriseID returns a new RedisEnterpriseId struct +func NewRedisEnterpriseID(subscriptionId string, resourceGroupName string, redisEnterpriseName string) RedisEnterpriseId { + return RedisEnterpriseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + } +} + +// ParseRedisEnterpriseID parses 'input' into a RedisEnterpriseId +func ParseRedisEnterpriseID(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRedisEnterpriseIDInsensitively parses 'input' case-insensitively into a RedisEnterpriseId +// note: this method should only be used for API response data and not user input +func ParseRedisEnterpriseIDInsensitively(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RedisEnterpriseId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + return nil +} + +// ValidateRedisEnterpriseID checks that 'input' can be parsed as a Redis Enterprise ID +func ValidateRedisEnterpriseID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRedisEnterpriseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redis Enterprise ID +func (id RedisEnterpriseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redis Enterprise ID +func (id RedisEnterpriseId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + } +} + +// String returns a human-readable description of this Redis Enterprise ID +func (id RedisEnterpriseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + } + return fmt.Sprintf("Redis Enterprise (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2024-10-01/privatelinkresources/id_redisenterprise_test.go b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/id_redisenterprise_test.go new file mode 100644 index 00000000000..c43caa9e0f6 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/id_redisenterprise_test.go @@ -0,0 +1,282 @@ +package privatelinkresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RedisEnterpriseId{} + +func TestNewRedisEnterpriseID(t *testing.T) { + id := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } +} + +func TestFormatRedisEnterpriseID(t *testing.T) { + actual := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRedisEnterpriseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestParseRedisEnterpriseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestSegmentsForRedisEnterpriseId(t *testing.T) { + segments := RedisEnterpriseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RedisEnterpriseId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redisenterprise/2024-10-01/privatelinkresources/method_listbycluster.go b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/method_listbycluster.go new file mode 100644 index 00000000000..ab94a7b4ec4 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/method_listbycluster.go @@ -0,0 +1,54 @@ +package privatelinkresources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByClusterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkResourceListResult +} + +// ListByCluster ... +func (c PrivateLinkResourcesClient) ListByCluster(ctx context.Context, id RedisEnterpriseId) (result ListByClusterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateLinkResourceListResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2024-10-01/privatelinkresources/model_privatelinkresource.go b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/model_privatelinkresource.go new file mode 100644 index 00000000000..69e8ae0e57a --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/model_privatelinkresource.go @@ -0,0 +1,11 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/privatelinkresources/model_privatelinkresourcelistresult.go b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/model_privatelinkresourcelistresult.go new file mode 100644 index 00000000000..fa950217c47 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/model_privatelinkresourcelistresult.go @@ -0,0 +1,8 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceListResult struct { + Value *[]PrivateLinkResource `json:"value,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/privatelinkresources/model_privatelinkresourceproperties.go b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..3c98012cdd1 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/model_privatelinkresourceproperties.go @@ -0,0 +1,10 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/privatelinkresources/version.go b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/version.go new file mode 100644 index 00000000000..dd8da2937c9 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/privatelinkresources/version.go @@ -0,0 +1,10 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-10-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/privatelinkresources/2024-10-01" +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/README.md b/resource-manager/redisenterprise/2024-10-01/redisenterprise/README.md new file mode 100644 index 00000000000..03f63dadefd --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/README.md @@ -0,0 +1,314 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2024-10-01/redisenterprise` Documentation + +The `redisenterprise` SDK allows for interaction with Azure Resource Manager `redisenterprise` (API Version `2024-10-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/redisenterprise/2024-10-01/redisenterprise" +``` + + +### Client Initialization + +```go +client := redisenterprise.NewRedisEnterpriseClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RedisEnterpriseClient.Create` + +```go +ctx := context.TODO() +id := redisenterprise.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +payload := redisenterprise.Cluster{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesCreate` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.Database{ + // ... +} + + +if err := client.DatabasesCreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesDelete` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +if err := client.DatabasesDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesExport` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.ExportClusterParameters{ + // ... +} + + +if err := client.DatabasesExportThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesFlush` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.FlushParameters{ + // ... +} + + +if err := client.DatabasesFlushThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesForceLinkToReplicationGroup` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.ForceLinkParameters{ + // ... +} + + +if err := client.DatabasesForceLinkToReplicationGroupThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesForceUnlink` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.ForceUnlinkParameters{ + // ... +} + + +if err := client.DatabasesForceUnlinkThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesGet` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +read, err := client.DatabasesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesImport` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.ImportClusterParameters{ + // ... +} + + +if err := client.DatabasesImportThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesListByCluster` + +```go +ctx := context.TODO() +id := redisenterprise.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +// alternatively `client.DatabasesListByCluster(ctx, id)` can be used to do batched pagination +items, err := client.DatabasesListByClusterComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesListKeys` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +read, err := client.DatabasesListKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesRegenerateKey` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.RegenerateKeyParameters{ + // ... +} + + +if err := client.DatabasesRegenerateKeyThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.DatabasesUpdate` + +```go +ctx := context.TODO() +id := redisenterprise.NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + +payload := redisenterprise.DatabaseUpdate{ + // ... +} + + +if err := client.DatabasesUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.Delete` + +```go +ctx := context.TODO() +id := redisenterprise.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RedisEnterpriseClient.Get` + +```go +ctx := context.TODO() +id := redisenterprise.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RedisEnterpriseClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RedisEnterpriseClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RedisEnterpriseClient.Update` + +```go +ctx := context.TODO() +id := redisenterprise.NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + +payload := redisenterprise.ClusterUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/client.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/client.go new file mode 100644 index 00000000000..08640dfb307 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/client.go @@ -0,0 +1,26 @@ +package redisenterprise + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RedisEnterpriseClient struct { + Client *resourcemanager.Client +} + +func NewRedisEnterpriseClientWithBaseURI(sdkApi sdkEnv.Api) (*RedisEnterpriseClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "redisenterprise", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RedisEnterpriseClient: %+v", err) + } + + return &RedisEnterpriseClient{ + Client: client, + }, nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/constants.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/constants.go new file mode 100644 index 00000000000..d9ac97ee81a --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/constants.go @@ -0,0 +1,701 @@ +package redisenterprise + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessKeyType string + +const ( + AccessKeyTypePrimary AccessKeyType = "Primary" + AccessKeyTypeSecondary AccessKeyType = "Secondary" +) + +func PossibleValuesForAccessKeyType() []string { + return []string{ + string(AccessKeyTypePrimary), + string(AccessKeyTypeSecondary), + } +} + +func (s *AccessKeyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAccessKeyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAccessKeyType(input string) (*AccessKeyType, error) { + vals := map[string]AccessKeyType{ + "primary": AccessKeyTypePrimary, + "secondary": AccessKeyTypeSecondary, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessKeyType(input) + return &out, nil +} + +type AofFrequency string + +const ( + AofFrequencyAlways AofFrequency = "always" + AofFrequencyOnes AofFrequency = "1s" +) + +func PossibleValuesForAofFrequency() []string { + return []string{ + string(AofFrequencyAlways), + string(AofFrequencyOnes), + } +} + +func (s *AofFrequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAofFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAofFrequency(input string) (*AofFrequency, error) { + vals := map[string]AofFrequency{ + "always": AofFrequencyAlways, + "1s": AofFrequencyOnes, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AofFrequency(input) + return &out, nil +} + +type ClusteringPolicy string + +const ( + ClusteringPolicyEnterpriseCluster ClusteringPolicy = "EnterpriseCluster" + ClusteringPolicyOSSCluster ClusteringPolicy = "OSSCluster" +) + +func PossibleValuesForClusteringPolicy() []string { + return []string{ + string(ClusteringPolicyEnterpriseCluster), + string(ClusteringPolicyOSSCluster), + } +} + +func (s *ClusteringPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseClusteringPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseClusteringPolicy(input string) (*ClusteringPolicy, error) { + vals := map[string]ClusteringPolicy{ + "enterprisecluster": ClusteringPolicyEnterpriseCluster, + "osscluster": ClusteringPolicyOSSCluster, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ClusteringPolicy(input) + return &out, nil +} + +type CmkIdentityType string + +const ( + CmkIdentityTypeSystemAssignedIdentity CmkIdentityType = "systemAssignedIdentity" + CmkIdentityTypeUserAssignedIdentity CmkIdentityType = "userAssignedIdentity" +) + +func PossibleValuesForCmkIdentityType() []string { + return []string{ + string(CmkIdentityTypeSystemAssignedIdentity), + string(CmkIdentityTypeUserAssignedIdentity), + } +} + +func (s *CmkIdentityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCmkIdentityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCmkIdentityType(input string) (*CmkIdentityType, error) { + vals := map[string]CmkIdentityType{ + "systemassignedidentity": CmkIdentityTypeSystemAssignedIdentity, + "userassignedidentity": CmkIdentityTypeUserAssignedIdentity, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CmkIdentityType(input) + return &out, nil +} + +type EvictionPolicy string + +const ( + EvictionPolicyAllKeysLFU EvictionPolicy = "AllKeysLFU" + EvictionPolicyAllKeysLRU EvictionPolicy = "AllKeysLRU" + EvictionPolicyAllKeysRandom EvictionPolicy = "AllKeysRandom" + EvictionPolicyNoEviction EvictionPolicy = "NoEviction" + EvictionPolicyVolatileLFU EvictionPolicy = "VolatileLFU" + EvictionPolicyVolatileLRU EvictionPolicy = "VolatileLRU" + EvictionPolicyVolatileRandom EvictionPolicy = "VolatileRandom" + EvictionPolicyVolatileTTL EvictionPolicy = "VolatileTTL" +) + +func PossibleValuesForEvictionPolicy() []string { + return []string{ + string(EvictionPolicyAllKeysLFU), + string(EvictionPolicyAllKeysLRU), + string(EvictionPolicyAllKeysRandom), + string(EvictionPolicyNoEviction), + string(EvictionPolicyVolatileLFU), + string(EvictionPolicyVolatileLRU), + string(EvictionPolicyVolatileRandom), + string(EvictionPolicyVolatileTTL), + } +} + +func (s *EvictionPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEvictionPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEvictionPolicy(input string) (*EvictionPolicy, error) { + vals := map[string]EvictionPolicy{ + "allkeyslfu": EvictionPolicyAllKeysLFU, + "allkeyslru": EvictionPolicyAllKeysLRU, + "allkeysrandom": EvictionPolicyAllKeysRandom, + "noeviction": EvictionPolicyNoEviction, + "volatilelfu": EvictionPolicyVolatileLFU, + "volatilelru": EvictionPolicyVolatileLRU, + "volatilerandom": EvictionPolicyVolatileRandom, + "volatilettl": EvictionPolicyVolatileTTL, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EvictionPolicy(input) + return &out, nil +} + +type LinkState string + +const ( + LinkStateLinkFailed LinkState = "LinkFailed" + LinkStateLinked LinkState = "Linked" + LinkStateLinking LinkState = "Linking" + LinkStateUnlinkFailed LinkState = "UnlinkFailed" + LinkStateUnlinking LinkState = "Unlinking" +) + +func PossibleValuesForLinkState() []string { + return []string{ + string(LinkStateLinkFailed), + string(LinkStateLinked), + string(LinkStateLinking), + string(LinkStateUnlinkFailed), + string(LinkStateUnlinking), + } +} + +func (s *LinkState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLinkState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLinkState(input string) (*LinkState, error) { + vals := map[string]LinkState{ + "linkfailed": LinkStateLinkFailed, + "linked": LinkStateLinked, + "linking": LinkStateLinking, + "unlinkfailed": LinkStateUnlinkFailed, + "unlinking": LinkStateUnlinking, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LinkState(input) + return &out, nil +} + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} + +type Protocol string + +const ( + ProtocolEncrypted Protocol = "Encrypted" + ProtocolPlaintext Protocol = "Plaintext" +) + +func PossibleValuesForProtocol() []string { + return []string{ + string(ProtocolEncrypted), + string(ProtocolPlaintext), + } +} + +func (s *Protocol) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProtocol(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProtocol(input string) (*Protocol, error) { + vals := map[string]Protocol{ + "encrypted": ProtocolEncrypted, + "plaintext": ProtocolPlaintext, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Protocol(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type RdbFrequency string + +const ( + RdbFrequencyOneTwoh RdbFrequency = "12h" + RdbFrequencyOneh RdbFrequency = "1h" + RdbFrequencySixh RdbFrequency = "6h" +) + +func PossibleValuesForRdbFrequency() []string { + return []string{ + string(RdbFrequencyOneTwoh), + string(RdbFrequencyOneh), + string(RdbFrequencySixh), + } +} + +func (s *RdbFrequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRdbFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRdbFrequency(input string) (*RdbFrequency, error) { + vals := map[string]RdbFrequency{ + "12h": RdbFrequencyOneTwoh, + "1h": RdbFrequencyOneh, + "6h": RdbFrequencySixh, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RdbFrequency(input) + return &out, nil +} + +type ResourceState string + +const ( + ResourceStateCreateFailed ResourceState = "CreateFailed" + ResourceStateCreating ResourceState = "Creating" + ResourceStateDeleteFailed ResourceState = "DeleteFailed" + ResourceStateDeleting ResourceState = "Deleting" + ResourceStateDisableFailed ResourceState = "DisableFailed" + ResourceStateDisabled ResourceState = "Disabled" + ResourceStateDisabling ResourceState = "Disabling" + ResourceStateEnableFailed ResourceState = "EnableFailed" + ResourceStateEnabling ResourceState = "Enabling" + ResourceStateRunning ResourceState = "Running" + ResourceStateScaling ResourceState = "Scaling" + ResourceStateScalingFailed ResourceState = "ScalingFailed" + ResourceStateUpdateFailed ResourceState = "UpdateFailed" + ResourceStateUpdating ResourceState = "Updating" +) + +func PossibleValuesForResourceState() []string { + return []string{ + string(ResourceStateCreateFailed), + string(ResourceStateCreating), + string(ResourceStateDeleteFailed), + string(ResourceStateDeleting), + string(ResourceStateDisableFailed), + string(ResourceStateDisabled), + string(ResourceStateDisabling), + string(ResourceStateEnableFailed), + string(ResourceStateEnabling), + string(ResourceStateRunning), + string(ResourceStateScaling), + string(ResourceStateScalingFailed), + string(ResourceStateUpdateFailed), + string(ResourceStateUpdating), + } +} + +func (s *ResourceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceState(input string) (*ResourceState, error) { + vals := map[string]ResourceState{ + "createfailed": ResourceStateCreateFailed, + "creating": ResourceStateCreating, + "deletefailed": ResourceStateDeleteFailed, + "deleting": ResourceStateDeleting, + "disablefailed": ResourceStateDisableFailed, + "disabled": ResourceStateDisabled, + "disabling": ResourceStateDisabling, + "enablefailed": ResourceStateEnableFailed, + "enabling": ResourceStateEnabling, + "running": ResourceStateRunning, + "scaling": ResourceStateScaling, + "scalingfailed": ResourceStateScalingFailed, + "updatefailed": ResourceStateUpdateFailed, + "updating": ResourceStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceState(input) + return &out, nil +} + +type SkuName string + +const ( + SkuNameEnterpriseEFive SkuName = "Enterprise_E5" + SkuNameEnterpriseEFiveZero SkuName = "Enterprise_E50" + SkuNameEnterpriseEFourHundred SkuName = "Enterprise_E400" + SkuNameEnterpriseEOne SkuName = "Enterprise_E1" + SkuNameEnterpriseEOneHundred SkuName = "Enterprise_E100" + SkuNameEnterpriseEOneZero SkuName = "Enterprise_E10" + SkuNameEnterpriseETwoHundred SkuName = "Enterprise_E200" + SkuNameEnterpriseETwoZero SkuName = "Enterprise_E20" + SkuNameEnterpriseFlashFOneFiveHundred SkuName = "EnterpriseFlash_F1500" + SkuNameEnterpriseFlashFSevenHundred SkuName = "EnterpriseFlash_F700" + SkuNameEnterpriseFlashFThreeHundred SkuName = "EnterpriseFlash_F300" +) + +func PossibleValuesForSkuName() []string { + return []string{ + string(SkuNameEnterpriseEFive), + string(SkuNameEnterpriseEFiveZero), + string(SkuNameEnterpriseEFourHundred), + string(SkuNameEnterpriseEOne), + string(SkuNameEnterpriseEOneHundred), + string(SkuNameEnterpriseEOneZero), + string(SkuNameEnterpriseETwoHundred), + string(SkuNameEnterpriseETwoZero), + string(SkuNameEnterpriseFlashFOneFiveHundred), + string(SkuNameEnterpriseFlashFSevenHundred), + string(SkuNameEnterpriseFlashFThreeHundred), + } +} + +func (s *SkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuName(input string) (*SkuName, error) { + vals := map[string]SkuName{ + "enterprise_e5": SkuNameEnterpriseEFive, + "enterprise_e50": SkuNameEnterpriseEFiveZero, + "enterprise_e400": SkuNameEnterpriseEFourHundred, + "enterprise_e1": SkuNameEnterpriseEOne, + "enterprise_e100": SkuNameEnterpriseEOneHundred, + "enterprise_e10": SkuNameEnterpriseEOneZero, + "enterprise_e200": SkuNameEnterpriseETwoHundred, + "enterprise_e20": SkuNameEnterpriseETwoZero, + "enterpriseflash_f1500": SkuNameEnterpriseFlashFOneFiveHundred, + "enterpriseflash_f700": SkuNameEnterpriseFlashFSevenHundred, + "enterpriseflash_f300": SkuNameEnterpriseFlashFThreeHundred, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuName(input) + return &out, nil +} + +type TlsVersion string + +const ( + TlsVersionOnePointOne TlsVersion = "1.1" + TlsVersionOnePointTwo TlsVersion = "1.2" + TlsVersionOnePointZero TlsVersion = "1.0" +) + +func PossibleValuesForTlsVersion() []string { + return []string{ + string(TlsVersionOnePointOne), + string(TlsVersionOnePointTwo), + string(TlsVersionOnePointZero), + } +} + +func (s *TlsVersion) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTlsVersion(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTlsVersion(input string) (*TlsVersion, error) { + vals := map[string]TlsVersion{ + "1.1": TlsVersionOnePointOne, + "1.2": TlsVersionOnePointTwo, + "1.0": TlsVersionOnePointZero, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TlsVersion(input) + return &out, nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/id_database.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/id_database.go new file mode 100644 index 00000000000..f7352ec7d89 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/id_database.go @@ -0,0 +1,139 @@ +package redisenterprise + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&DatabaseId{}) +} + +var _ resourceids.ResourceId = &DatabaseId{} + +// DatabaseId is a struct representing the Resource ID for a Database +type DatabaseId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string + DatabaseName string +} + +// NewDatabaseID returns a new DatabaseId struct +func NewDatabaseID(subscriptionId string, resourceGroupName string, redisEnterpriseName string, databaseName string) DatabaseId { + return DatabaseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + DatabaseName: databaseName, + } +} + +// ParseDatabaseID parses 'input' into a DatabaseId +func ParseDatabaseID(input string) (*DatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDatabaseIDInsensitively parses 'input' case-insensitively into a DatabaseId +// note: this method should only be used for API response data and not user input +func ParseDatabaseIDInsensitively(input string) (*DatabaseId, error) { + parser := resourceids.NewParserFromResourceIdType(&DatabaseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DatabaseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DatabaseId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + if id.DatabaseName, ok = input.Parsed["databaseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "databaseName", input) + } + + return nil +} + +// ValidateDatabaseID checks that 'input' can be parsed as a Database ID +func ValidateDatabaseID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseDatabaseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Database ID +func (id DatabaseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s/databases/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName, id.DatabaseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Database ID +func (id DatabaseId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + resourceids.StaticSegment("staticDatabases", "databases", "databases"), + resourceids.UserSpecifiedSegment("databaseName", "databaseName"), + } +} + +// String returns a human-readable description of this Database ID +func (id DatabaseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + fmt.Sprintf("Database Name: %q", id.DatabaseName), + } + return fmt.Sprintf("Database (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/id_database_test.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/id_database_test.go new file mode 100644 index 00000000000..ec9168fdb8c --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/id_database_test.go @@ -0,0 +1,327 @@ +package redisenterprise + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &DatabaseId{} + +func TestNewDatabaseID(t *testing.T) { + id := NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } + + if id.DatabaseName != "databaseName" { + t.Fatalf("Expected %q but got %q for Segment 'DatabaseName'", id.DatabaseName, "databaseName") + } +} + +func TestFormatDatabaseID(t *testing.T) { + actual := NewDatabaseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName", "databaseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDatabaseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + } +} + +func TestParseDatabaseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DatabaseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + DatabaseName: "databaseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/databases/databaseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE", + Expected: &DatabaseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + DatabaseName: "dAtAbAsEnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/dAtAbAsEs/dAtAbAsEnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDatabaseIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + if actual.DatabaseName != v.Expected.DatabaseName { + t.Fatalf("Expected %q but got %q for DatabaseName", v.Expected.DatabaseName, actual.DatabaseName) + } + + } +} + +func TestSegmentsForDatabaseId(t *testing.T) { + segments := DatabaseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DatabaseId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/id_redisenterprise.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/id_redisenterprise.go new file mode 100644 index 00000000000..de1d9d9bef2 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/id_redisenterprise.go @@ -0,0 +1,130 @@ +package redisenterprise + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RedisEnterpriseId{}) +} + +var _ resourceids.ResourceId = &RedisEnterpriseId{} + +// RedisEnterpriseId is a struct representing the Resource ID for a Redis Enterprise +type RedisEnterpriseId struct { + SubscriptionId string + ResourceGroupName string + RedisEnterpriseName string +} + +// NewRedisEnterpriseID returns a new RedisEnterpriseId struct +func NewRedisEnterpriseID(subscriptionId string, resourceGroupName string, redisEnterpriseName string) RedisEnterpriseId { + return RedisEnterpriseId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + RedisEnterpriseName: redisEnterpriseName, + } +} + +// ParseRedisEnterpriseID parses 'input' into a RedisEnterpriseId +func ParseRedisEnterpriseID(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRedisEnterpriseIDInsensitively parses 'input' case-insensitively into a RedisEnterpriseId +// note: this method should only be used for API response data and not user input +func ParseRedisEnterpriseIDInsensitively(input string) (*RedisEnterpriseId, error) { + parser := resourceids.NewParserFromResourceIdType(&RedisEnterpriseId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RedisEnterpriseId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RedisEnterpriseId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.RedisEnterpriseName, ok = input.Parsed["redisEnterpriseName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "redisEnterpriseName", input) + } + + return nil +} + +// ValidateRedisEnterpriseID checks that 'input' can be parsed as a Redis Enterprise ID +func ValidateRedisEnterpriseID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRedisEnterpriseID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Redis Enterprise ID +func (id RedisEnterpriseId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Cache/redisEnterprise/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.RedisEnterpriseName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Redis Enterprise ID +func (id RedisEnterpriseId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCache", "Microsoft.Cache", "Microsoft.Cache"), + resourceids.StaticSegment("staticRedisEnterprise", "redisEnterprise", "redisEnterprise"), + resourceids.UserSpecifiedSegment("redisEnterpriseName", "redisEnterpriseName"), + } +} + +// String returns a human-readable description of this Redis Enterprise ID +func (id RedisEnterpriseId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Redis Enterprise Name: %q", id.RedisEnterpriseName), + } + return fmt.Sprintf("Redis Enterprise (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/id_redisenterprise_test.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/id_redisenterprise_test.go new file mode 100644 index 00000000000..8676cc8523e --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/id_redisenterprise_test.go @@ -0,0 +1,282 @@ +package redisenterprise + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RedisEnterpriseId{} + +func TestNewRedisEnterpriseID(t *testing.T) { + id := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.RedisEnterpriseName != "redisEnterpriseName" { + t.Fatalf("Expected %q but got %q for Segment 'RedisEnterpriseName'", id.RedisEnterpriseName, "redisEnterpriseName") + } +} + +func TestFormatRedisEnterpriseID(t *testing.T) { + actual := NewRedisEnterpriseID("12345678-1234-9876-4563-123456789012", "example-resource-group", "redisEnterpriseName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRedisEnterpriseID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestParseRedisEnterpriseIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RedisEnterpriseId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + RedisEnterpriseName: "redisEnterpriseName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Cache/redisEnterprise/redisEnterpriseName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe", + Expected: &RedisEnterpriseId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + RedisEnterpriseName: "rEdIsEnTeRpRiSeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cAcHe/rEdIsEnTeRpRiSe/rEdIsEnTeRpRiSeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRedisEnterpriseIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.RedisEnterpriseName != v.Expected.RedisEnterpriseName { + t.Fatalf("Expected %q but got %q for RedisEnterpriseName", v.Expected.RedisEnterpriseName, actual.RedisEnterpriseName) + } + + } +} + +func TestSegmentsForRedisEnterpriseId(t *testing.T) { + segments := RedisEnterpriseId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RedisEnterpriseId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_create.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_create.go new file mode 100644 index 00000000000..bc1b883cbbb --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_create.go @@ -0,0 +1,75 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Cluster +} + +// Create ... +func (c RedisEnterpriseClient) Create(ctx context.Context, id RedisEnterpriseId, input Cluster) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c RedisEnterpriseClient) CreateThenPoll(ctx context.Context, id RedisEnterpriseId, input Cluster) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasescreate.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasescreate.go new file mode 100644 index 00000000000..76933e8f063 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasescreate.go @@ -0,0 +1,75 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasesCreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +// DatabasesCreate ... +func (c RedisEnterpriseClient) DatabasesCreate(ctx context.Context, id DatabaseId, input Database) (result DatabasesCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DatabasesCreateThenPoll performs DatabasesCreate then polls until it's completed +func (c RedisEnterpriseClient) DatabasesCreateThenPoll(ctx context.Context, id DatabaseId, input Database) error { + result, err := c.DatabasesCreate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesCreate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesCreate: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesdelete.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesdelete.go new file mode 100644 index 00000000000..a7961442781 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesdelete.go @@ -0,0 +1,71 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasesDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabasesDelete ... +func (c RedisEnterpriseClient) DatabasesDelete(ctx context.Context, id DatabaseId) (result DatabasesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DatabasesDeleteThenPoll performs DatabasesDelete then polls until it's completed +func (c RedisEnterpriseClient) DatabasesDeleteThenPoll(ctx context.Context, id DatabaseId) error { + result, err := c.DatabasesDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing DatabasesDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesexport.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesexport.go new file mode 100644 index 00000000000..8ce4d87e186 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesexport.go @@ -0,0 +1,74 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasesExportOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabasesExport ... +func (c RedisEnterpriseClient) DatabasesExport(ctx context.Context, id DatabaseId, input ExportClusterParameters) (result DatabasesExportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/export", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DatabasesExportThenPoll performs DatabasesExport then polls until it's completed +func (c RedisEnterpriseClient) DatabasesExportThenPoll(ctx context.Context, id DatabaseId, input ExportClusterParameters) error { + result, err := c.DatabasesExport(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesExport: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesExport: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesflush.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesflush.go new file mode 100644 index 00000000000..1a2453ebee2 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesflush.go @@ -0,0 +1,74 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasesFlushOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabasesFlush ... +func (c RedisEnterpriseClient) DatabasesFlush(ctx context.Context, id DatabaseId, input FlushParameters) (result DatabasesFlushOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/flush", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DatabasesFlushThenPoll performs DatabasesFlush then polls until it's completed +func (c RedisEnterpriseClient) DatabasesFlushThenPoll(ctx context.Context, id DatabaseId, input FlushParameters) error { + result, err := c.DatabasesFlush(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesFlush: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesFlush: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesforcelinktoreplicationgroup.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesforcelinktoreplicationgroup.go new file mode 100644 index 00000000000..2a6994912d6 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesforcelinktoreplicationgroup.go @@ -0,0 +1,73 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasesForceLinkToReplicationGroupOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabasesForceLinkToReplicationGroup ... +func (c RedisEnterpriseClient) DatabasesForceLinkToReplicationGroup(ctx context.Context, id DatabaseId, input ForceLinkParameters) (result DatabasesForceLinkToReplicationGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/forceLinkToReplicationGroup", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DatabasesForceLinkToReplicationGroupThenPoll performs DatabasesForceLinkToReplicationGroup then polls until it's completed +func (c RedisEnterpriseClient) DatabasesForceLinkToReplicationGroupThenPoll(ctx context.Context, id DatabaseId, input ForceLinkParameters) error { + result, err := c.DatabasesForceLinkToReplicationGroup(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesForceLinkToReplicationGroup: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesForceLinkToReplicationGroup: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesforceunlink.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesforceunlink.go new file mode 100644 index 00000000000..1fc0801e823 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesforceunlink.go @@ -0,0 +1,74 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasesForceUnlinkOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabasesForceUnlink ... +func (c RedisEnterpriseClient) DatabasesForceUnlink(ctx context.Context, id DatabaseId, input ForceUnlinkParameters) (result DatabasesForceUnlinkOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/forceUnlink", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DatabasesForceUnlinkThenPoll performs DatabasesForceUnlink then polls until it's completed +func (c RedisEnterpriseClient) DatabasesForceUnlinkThenPoll(ctx context.Context, id DatabaseId, input ForceUnlinkParameters) error { + result, err := c.DatabasesForceUnlink(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesForceUnlink: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesForceUnlink: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesget.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesget.go new file mode 100644 index 00000000000..f774a726917 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesget.go @@ -0,0 +1,53 @@ +package redisenterprise + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +// DatabasesGet ... +func (c RedisEnterpriseClient) DatabasesGet(ctx context.Context, id DatabaseId) (result DatabasesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Database + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesimport.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesimport.go new file mode 100644 index 00000000000..08fff384eb6 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesimport.go @@ -0,0 +1,74 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasesImportOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DatabasesImport ... +func (c RedisEnterpriseClient) DatabasesImport(ctx context.Context, id DatabaseId, input ImportClusterParameters) (result DatabasesImportOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/import", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DatabasesImportThenPoll performs DatabasesImport then polls until it's completed +func (c RedisEnterpriseClient) DatabasesImportThenPoll(ctx context.Context, id DatabaseId, input ImportClusterParameters) error { + result, err := c.DatabasesImport(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesImport: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesImport: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databaseslistbycluster.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databaseslistbycluster.go new file mode 100644 index 00000000000..b8af4ecf22a --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databaseslistbycluster.go @@ -0,0 +1,105 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasesListByClusterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Database +} + +type DatabasesListByClusterCompleteResult struct { + LatestHttpResponse *http.Response + Items []Database +} + +type DatabasesListByClusterCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *DatabasesListByClusterCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// DatabasesListByCluster ... +func (c RedisEnterpriseClient) DatabasesListByCluster(ctx context.Context, id RedisEnterpriseId) (result DatabasesListByClusterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &DatabasesListByClusterCustomPager{}, + Path: fmt.Sprintf("%s/databases", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Database `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// DatabasesListByClusterComplete retrieves all the results into a single object +func (c RedisEnterpriseClient) DatabasesListByClusterComplete(ctx context.Context, id RedisEnterpriseId) (DatabasesListByClusterCompleteResult, error) { + return c.DatabasesListByClusterCompleteMatchingPredicate(ctx, id, DatabaseOperationPredicate{}) +} + +// DatabasesListByClusterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisEnterpriseClient) DatabasesListByClusterCompleteMatchingPredicate(ctx context.Context, id RedisEnterpriseId, predicate DatabaseOperationPredicate) (result DatabasesListByClusterCompleteResult, err error) { + items := make([]Database, 0) + + resp, err := c.DatabasesListByCluster(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = DatabasesListByClusterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databaseslistkeys.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databaseslistkeys.go new file mode 100644 index 00000000000..0232e662380 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databaseslistkeys.go @@ -0,0 +1,54 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasesListKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AccessKeys +} + +// DatabasesListKeys ... +func (c RedisEnterpriseClient) DatabasesListKeys(ctx context.Context, id DatabaseId) (result DatabasesListKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listKeys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model AccessKeys + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesregeneratekey.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesregeneratekey.go new file mode 100644 index 00000000000..62dc26cf6ea --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesregeneratekey.go @@ -0,0 +1,75 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasesRegenerateKeyOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *AccessKeys +} + +// DatabasesRegenerateKey ... +func (c RedisEnterpriseClient) DatabasesRegenerateKey(ctx context.Context, id DatabaseId, input RegenerateKeyParameters) (result DatabasesRegenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DatabasesRegenerateKeyThenPoll performs DatabasesRegenerateKey then polls until it's completed +func (c RedisEnterpriseClient) DatabasesRegenerateKeyThenPoll(ctx context.Context, id DatabaseId, input RegenerateKeyParameters) error { + result, err := c.DatabasesRegenerateKey(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesRegenerateKey: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesRegenerateKey: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesupdate.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesupdate.go new file mode 100644 index 00000000000..2b0e7934d93 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_databasesupdate.go @@ -0,0 +1,75 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasesUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Database +} + +// DatabasesUpdate ... +func (c RedisEnterpriseClient) DatabasesUpdate(ctx context.Context, id DatabaseId, input DatabaseUpdate) (result DatabasesUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DatabasesUpdateThenPoll performs DatabasesUpdate then polls until it's completed +func (c RedisEnterpriseClient) DatabasesUpdateThenPoll(ctx context.Context, id DatabaseId, input DatabaseUpdate) error { + result, err := c.DatabasesUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing DatabasesUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DatabasesUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_delete.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_delete.go new file mode 100644 index 00000000000..d15634da2c0 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_delete.go @@ -0,0 +1,71 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c RedisEnterpriseClient) Delete(ctx context.Context, id RedisEnterpriseId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c RedisEnterpriseClient) DeleteThenPoll(ctx context.Context, id RedisEnterpriseId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_get.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_get.go new file mode 100644 index 00000000000..c729b30e660 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_get.go @@ -0,0 +1,53 @@ +package redisenterprise + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Cluster +} + +// Get ... +func (c RedisEnterpriseClient) Get(ctx context.Context, id RedisEnterpriseId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Cluster + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_list.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_list.go new file mode 100644 index 00000000000..b3062bf1802 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_list.go @@ -0,0 +1,106 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Cluster +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Cluster +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c RedisEnterpriseClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Cache/redisEnterprise", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Cluster `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c RedisEnterpriseClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ClusterOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisEnterpriseClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ClusterOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Cluster, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_listbyresourcegroup.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_listbyresourcegroup.go new file mode 100644 index 00000000000..181676b5089 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Cluster +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Cluster +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c RedisEnterpriseClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Cache/redisEnterprise", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Cluster `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c RedisEnterpriseClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ClusterOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RedisEnterpriseClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ClusterOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Cluster, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_update.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_update.go new file mode 100644 index 00000000000..e23cde29632 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/method_update.go @@ -0,0 +1,75 @@ +package redisenterprise + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Cluster +} + +// Update ... +func (c RedisEnterpriseClient) Update(ctx context.Context, id RedisEnterpriseId, input ClusterUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c RedisEnterpriseClient) UpdateThenPoll(ctx context.Context, id RedisEnterpriseId, input ClusterUpdate) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_accesskeys.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_accesskeys.go new file mode 100644 index 00000000000..79566de711f --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_accesskeys.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessKeys struct { + PrimaryKey *string `json:"primaryKey,omitempty"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_cluster.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_cluster.go new file mode 100644 index 00000000000..26b12398e06 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_cluster.go @@ -0,0 +1,21 @@ +package redisenterprise + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Cluster struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ClusterProperties `json:"properties,omitempty"` + Sku Sku `json:"sku"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterproperties.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterproperties.go new file mode 100644 index 00000000000..b31d8d3a387 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterproperties.go @@ -0,0 +1,14 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterProperties struct { + Encryption *ClusterPropertiesEncryption `json:"encryption,omitempty"` + HostName *string `json:"hostName,omitempty"` + MinimumTlsVersion *TlsVersion `json:"minimumTlsVersion,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + RedisVersion *string `json:"redisVersion,omitempty"` + ResourceState *ResourceState `json:"resourceState,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterpropertiesencryption.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterpropertiesencryption.go new file mode 100644 index 00000000000..253b894977f --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterpropertiesencryption.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterPropertiesEncryption struct { + CustomerManagedKeyEncryption *ClusterPropertiesEncryptionCustomerManagedKeyEncryption `json:"customerManagedKeyEncryption,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryption.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryption.go new file mode 100644 index 00000000000..8c3ddebdaca --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryption.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterPropertiesEncryptionCustomerManagedKeyEncryption struct { + KeyEncryptionKeyIdentity *ClusterPropertiesEncryptionCustomerManagedKeyEncryptionKeyEncryptionKeyIdentity `json:"keyEncryptionKeyIdentity,omitempty"` + KeyEncryptionKeyURL *string `json:"keyEncryptionKeyUrl,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryptionkeyencryptionkeyidentity.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryptionkeyencryptionkeyidentity.go new file mode 100644 index 00000000000..e99632be68c --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterpropertiesencryptioncustomermanagedkeyencryptionkeyencryptionkeyidentity.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterPropertiesEncryptionCustomerManagedKeyEncryptionKeyEncryptionKeyIdentity struct { + IdentityType *CmkIdentityType `json:"identityType,omitempty"` + UserAssignedIdentityResourceId *string `json:"userAssignedIdentityResourceId,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterupdate.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterupdate.go new file mode 100644 index 00000000000..b5489a543df --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_clusterupdate.go @@ -0,0 +1,15 @@ +package redisenterprise + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterUpdate struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *ClusterProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_database.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_database.go new file mode 100644 index 00000000000..dd20d0b355a --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_database.go @@ -0,0 +1,11 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Database struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatabaseProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_databaseproperties.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_databaseproperties.go new file mode 100644 index 00000000000..c8ca12b1385 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_databaseproperties.go @@ -0,0 +1,16 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseProperties struct { + ClientProtocol *Protocol `json:"clientProtocol,omitempty"` + ClusteringPolicy *ClusteringPolicy `json:"clusteringPolicy,omitempty"` + EvictionPolicy *EvictionPolicy `json:"evictionPolicy,omitempty"` + GeoReplication *DatabasePropertiesGeoReplication `json:"geoReplication,omitempty"` + Modules *[]Module `json:"modules,omitempty"` + Persistence *Persistence `json:"persistence,omitempty"` + Port *int64 `json:"port,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + ResourceState *ResourceState `json:"resourceState,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_databasepropertiesgeoreplication.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_databasepropertiesgeoreplication.go new file mode 100644 index 00000000000..3244185bf85 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_databasepropertiesgeoreplication.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabasePropertiesGeoReplication struct { + GroupNickname *string `json:"groupNickname,omitempty"` + LinkedDatabases *[]LinkedDatabase `json:"linkedDatabases,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_databaseupdate.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_databaseupdate.go new file mode 100644 index 00000000000..aff0488e608 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_databaseupdate.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatabaseUpdate struct { + Properties *DatabaseProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_exportclusterparameters.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_exportclusterparameters.go new file mode 100644 index 00000000000..d6ba54aa230 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_exportclusterparameters.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ExportClusterParameters struct { + SasUri string `json:"sasUri"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_flushparameters.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_flushparameters.go new file mode 100644 index 00000000000..9d3358ea741 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_flushparameters.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FlushParameters struct { + Ids *[]string `json:"ids,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forcelinkparameters.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forcelinkparameters.go new file mode 100644 index 00000000000..32ca00618d3 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forcelinkparameters.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceLinkParameters struct { + GroupNickname string `json:"groupNickname"` + LinkedDatabases []LinkedDatabase `json:"linkedDatabases"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forceunlinkparameters.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forceunlinkparameters.go new file mode 100644 index 00000000000..7bf82a13709 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forceunlinkparameters.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceUnlinkParameters struct { + Ids []string `json:"ids"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_importclusterparameters.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_importclusterparameters.go new file mode 100644 index 00000000000..11e13cd4dc4 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_importclusterparameters.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImportClusterParameters struct { + SasUris []string `json:"sasUris"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_linkeddatabase.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_linkeddatabase.go new file mode 100644 index 00000000000..02abc0422ce --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_linkeddatabase.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedDatabase struct { + Id *string `json:"id,omitempty"` + State *LinkState `json:"state,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_module.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_module.go new file mode 100644 index 00000000000..99bd8473a0f --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_module.go @@ -0,0 +1,10 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Module struct { + Args *string `json:"args,omitempty"` + Name string `json:"name"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_persistence.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_persistence.go new file mode 100644 index 00000000000..3b7b30f2fb9 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_persistence.go @@ -0,0 +1,11 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Persistence struct { + AofEnabled *bool `json:"aofEnabled,omitempty"` + AofFrequency *AofFrequency `json:"aofFrequency,omitempty"` + RdbEnabled *bool `json:"rdbEnabled,omitempty"` + RdbFrequency *RdbFrequency `json:"rdbFrequency,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privateendpoint.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privateendpoint.go new file mode 100644 index 00000000000..e15699fe1d1 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privateendpoint.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privateendpointconnection.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privateendpointconnection.go new file mode 100644 index 00000000000..5da2f77534d --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privateendpointconnection.go @@ -0,0 +1,11 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privateendpointconnectionproperties.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..9ebfbe2d3c2 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privateendpointconnectionproperties.go @@ -0,0 +1,10 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privatelinkserviceconnectionstate.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..abb658aee84 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_regeneratekeyparameters.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_regeneratekeyparameters.go new file mode 100644 index 00000000000..2d44026dd91 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_regeneratekeyparameters.go @@ -0,0 +1,8 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateKeyParameters struct { + KeyType AccessKeyType `json:"keyType"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_sku.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_sku.go new file mode 100644 index 00000000000..740c3615e0c --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_sku.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Capacity *int64 `json:"capacity,omitempty"` + Name SkuName `json:"name"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/predicates.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/predicates.go new file mode 100644 index 00000000000..d240cbf7181 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/predicates.go @@ -0,0 +1,55 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ClusterOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ClusterOperationPredicate) Matches(input Cluster) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type DatabaseOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatabaseOperationPredicate) Matches(input Database) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/version.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/version.go new file mode 100644 index 00000000000..dce3600f716 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/version.go @@ -0,0 +1,10 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-10-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/redisenterprise/2024-10-01" +} diff --git a/resource-manager/standbypool/2024-03-01/client.go b/resource-manager/standbypool/2024-03-01/client.go new file mode 100644 index 00000000000..38db7687e32 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/client.go @@ -0,0 +1,64 @@ +package v2024_03_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews" + "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbycontainergrouppools" + "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews" + "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools" + "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachines" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + StandbyContainerGroupPoolRuntimeViews *standbycontainergrouppoolruntimeviews.StandbyContainerGroupPoolRuntimeViewsClient + StandbyContainerGroupPools *standbycontainergrouppools.StandbyContainerGroupPoolsClient + StandbyVirtualMachinePoolRuntimeViews *standbyvirtualmachinepoolruntimeviews.StandbyVirtualMachinePoolRuntimeViewsClient + StandbyVirtualMachinePools *standbyvirtualmachinepools.StandbyVirtualMachinePoolsClient + StandbyVirtualMachines *standbyvirtualmachines.StandbyVirtualMachinesClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + standbyContainerGroupPoolRuntimeViewsClient, err := standbycontainergrouppoolruntimeviews.NewStandbyContainerGroupPoolRuntimeViewsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building StandbyContainerGroupPoolRuntimeViews client: %+v", err) + } + configureFunc(standbyContainerGroupPoolRuntimeViewsClient.Client) + + standbyContainerGroupPoolsClient, err := standbycontainergrouppools.NewStandbyContainerGroupPoolsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building StandbyContainerGroupPools client: %+v", err) + } + configureFunc(standbyContainerGroupPoolsClient.Client) + + standbyVirtualMachinePoolRuntimeViewsClient, err := standbyvirtualmachinepoolruntimeviews.NewStandbyVirtualMachinePoolRuntimeViewsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building StandbyVirtualMachinePoolRuntimeViews client: %+v", err) + } + configureFunc(standbyVirtualMachinePoolRuntimeViewsClient.Client) + + standbyVirtualMachinePoolsClient, err := standbyvirtualmachinepools.NewStandbyVirtualMachinePoolsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building StandbyVirtualMachinePools client: %+v", err) + } + configureFunc(standbyVirtualMachinePoolsClient.Client) + + standbyVirtualMachinesClient, err := standbyvirtualmachines.NewStandbyVirtualMachinesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building StandbyVirtualMachines client: %+v", err) + } + configureFunc(standbyVirtualMachinesClient.Client) + + return &Client{ + StandbyContainerGroupPoolRuntimeViews: standbyContainerGroupPoolRuntimeViewsClient, + StandbyContainerGroupPools: standbyContainerGroupPoolsClient, + StandbyVirtualMachinePoolRuntimeViews: standbyVirtualMachinePoolRuntimeViewsClient, + StandbyVirtualMachinePools: standbyVirtualMachinePoolsClient, + StandbyVirtualMachines: standbyVirtualMachinesClient, + }, nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/README.md b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/README.md new file mode 100644 index 00000000000..90dcb2bf5c5 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews` Documentation + +The `standbycontainergrouppoolruntimeviews` SDK allows for interaction with Azure Resource Manager `standbypool` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews" +``` + + +### Client Initialization + +```go +client := standbycontainergrouppoolruntimeviews.NewStandbyContainerGroupPoolRuntimeViewsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `StandbyContainerGroupPoolRuntimeViewsClient.Get` + +```go +ctx := context.TODO() +id := standbycontainergrouppoolruntimeviews.NewRuntimeViewID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyContainerGroupPoolName", "runtimeViewName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `StandbyContainerGroupPoolRuntimeViewsClient.ListByStandbyPool` + +```go +ctx := context.TODO() +id := standbycontainergrouppoolruntimeviews.NewStandbyContainerGroupPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyContainerGroupPoolName") + +// alternatively `client.ListByStandbyPool(ctx, id)` can be used to do batched pagination +items, err := client.ListByStandbyPoolComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/client.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/client.go new file mode 100644 index 00000000000..05b366cc702 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/client.go @@ -0,0 +1,26 @@ +package standbycontainergrouppoolruntimeviews + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyContainerGroupPoolRuntimeViewsClient struct { + Client *resourcemanager.Client +} + +func NewStandbyContainerGroupPoolRuntimeViewsClientWithBaseURI(sdkApi sdkEnv.Api) (*StandbyContainerGroupPoolRuntimeViewsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "standbycontainergrouppoolruntimeviews", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating StandbyContainerGroupPoolRuntimeViewsClient: %+v", err) + } + + return &StandbyContainerGroupPoolRuntimeViewsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/constants.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/constants.go new file mode 100644 index 00000000000..be6bf71e622 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/constants.go @@ -0,0 +1,57 @@ +package standbycontainergrouppoolruntimeviews + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_runtimeview.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_runtimeview.go new file mode 100644 index 00000000000..e71976f66f9 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_runtimeview.go @@ -0,0 +1,139 @@ +package standbycontainergrouppoolruntimeviews + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&RuntimeViewId{}) +} + +var _ resourceids.ResourceId = &RuntimeViewId{} + +// RuntimeViewId is a struct representing the Resource ID for a Runtime View +type RuntimeViewId struct { + SubscriptionId string + ResourceGroupName string + StandbyContainerGroupPoolName string + RuntimeViewName string +} + +// NewRuntimeViewID returns a new RuntimeViewId struct +func NewRuntimeViewID(subscriptionId string, resourceGroupName string, standbyContainerGroupPoolName string, runtimeViewName string) RuntimeViewId { + return RuntimeViewId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + StandbyContainerGroupPoolName: standbyContainerGroupPoolName, + RuntimeViewName: runtimeViewName, + } +} + +// ParseRuntimeViewID parses 'input' into a RuntimeViewId +func ParseRuntimeViewID(input string) (*RuntimeViewId, error) { + parser := resourceids.NewParserFromResourceIdType(&RuntimeViewId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RuntimeViewId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRuntimeViewIDInsensitively parses 'input' case-insensitively into a RuntimeViewId +// note: this method should only be used for API response data and not user input +func ParseRuntimeViewIDInsensitively(input string) (*RuntimeViewId, error) { + parser := resourceids.NewParserFromResourceIdType(&RuntimeViewId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RuntimeViewId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RuntimeViewId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.StandbyContainerGroupPoolName, ok = input.Parsed["standbyContainerGroupPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "standbyContainerGroupPoolName", input) + } + + if id.RuntimeViewName, ok = input.Parsed["runtimeViewName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "runtimeViewName", input) + } + + return nil +} + +// ValidateRuntimeViewID checks that 'input' can be parsed as a Runtime View ID +func ValidateRuntimeViewID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseRuntimeViewID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Runtime View ID +func (id RuntimeViewId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.StandbyPool/standbyContainerGroupPools/%s/runtimeViews/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.StandbyContainerGroupPoolName, id.RuntimeViewName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Runtime View ID +func (id RuntimeViewId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftStandbyPool", "Microsoft.StandbyPool", "Microsoft.StandbyPool"), + resourceids.StaticSegment("staticStandbyContainerGroupPools", "standbyContainerGroupPools", "standbyContainerGroupPools"), + resourceids.UserSpecifiedSegment("standbyContainerGroupPoolName", "standbyContainerGroupPoolName"), + resourceids.StaticSegment("staticRuntimeViews", "runtimeViews", "runtimeViews"), + resourceids.UserSpecifiedSegment("runtimeViewName", "runtimeViewName"), + } +} + +// String returns a human-readable description of this Runtime View ID +func (id RuntimeViewId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Standby Container Group Pool Name: %q", id.StandbyContainerGroupPoolName), + fmt.Sprintf("Runtime View Name: %q", id.RuntimeViewName), + } + return fmt.Sprintf("Runtime View (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_runtimeview_test.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_runtimeview_test.go new file mode 100644 index 00000000000..31adab7f166 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_runtimeview_test.go @@ -0,0 +1,327 @@ +package standbycontainergrouppoolruntimeviews + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &RuntimeViewId{} + +func TestNewRuntimeViewID(t *testing.T) { + id := NewRuntimeViewID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyContainerGroupPoolName", "runtimeViewName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.StandbyContainerGroupPoolName != "standbyContainerGroupPoolName" { + t.Fatalf("Expected %q but got %q for Segment 'StandbyContainerGroupPoolName'", id.StandbyContainerGroupPoolName, "standbyContainerGroupPoolName") + } + + if id.RuntimeViewName != "runtimeViewName" { + t.Fatalf("Expected %q but got %q for Segment 'RuntimeViewName'", id.RuntimeViewName, "runtimeViewName") + } +} + +func TestFormatRuntimeViewID(t *testing.T) { + actual := NewRuntimeViewID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyContainerGroupPoolName", "runtimeViewName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName/runtimeViews/runtimeViewName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRuntimeViewID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RuntimeViewId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName/runtimeViews", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName/runtimeViews/runtimeViewName", + Expected: &RuntimeViewId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyContainerGroupPoolName: "standbyContainerGroupPoolName", + RuntimeViewName: "runtimeViewName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName/runtimeViews/runtimeViewName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRuntimeViewID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyContainerGroupPoolName != v.Expected.StandbyContainerGroupPoolName { + t.Fatalf("Expected %q but got %q for StandbyContainerGroupPoolName", v.Expected.StandbyContainerGroupPoolName, actual.StandbyContainerGroupPoolName) + } + + if actual.RuntimeViewName != v.Expected.RuntimeViewName { + t.Fatalf("Expected %q but got %q for RuntimeViewName", v.Expected.RuntimeViewName, actual.RuntimeViewName) + } + + } +} + +func TestParseRuntimeViewIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RuntimeViewId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByCoNtAiNeRgRoUpPoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByCoNtAiNeRgRoUpPoOlS/sTaNdByCoNtAiNeRgRoUpPoOlNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName/runtimeViews", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByCoNtAiNeRgRoUpPoOlS/sTaNdByCoNtAiNeRgRoUpPoOlNaMe/rUnTiMeViEwS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName/runtimeViews/runtimeViewName", + Expected: &RuntimeViewId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyContainerGroupPoolName: "standbyContainerGroupPoolName", + RuntimeViewName: "runtimeViewName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName/runtimeViews/runtimeViewName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByCoNtAiNeRgRoUpPoOlS/sTaNdByCoNtAiNeRgRoUpPoOlNaMe/rUnTiMeViEwS/rUnTiMeViEwNaMe", + Expected: &RuntimeViewId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + StandbyContainerGroupPoolName: "sTaNdByCoNtAiNeRgRoUpPoOlNaMe", + RuntimeViewName: "rUnTiMeViEwNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByCoNtAiNeRgRoUpPoOlS/sTaNdByCoNtAiNeRgRoUpPoOlNaMe/rUnTiMeViEwS/rUnTiMeViEwNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRuntimeViewIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyContainerGroupPoolName != v.Expected.StandbyContainerGroupPoolName { + t.Fatalf("Expected %q but got %q for StandbyContainerGroupPoolName", v.Expected.StandbyContainerGroupPoolName, actual.StandbyContainerGroupPoolName) + } + + if actual.RuntimeViewName != v.Expected.RuntimeViewName { + t.Fatalf("Expected %q but got %q for RuntimeViewName", v.Expected.RuntimeViewName, actual.RuntimeViewName) + } + + } +} + +func TestSegmentsForRuntimeViewId(t *testing.T) { + segments := RuntimeViewId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RuntimeViewId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_standbycontainergrouppool.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_standbycontainergrouppool.go new file mode 100644 index 00000000000..9003fcfc894 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_standbycontainergrouppool.go @@ -0,0 +1,130 @@ +package standbycontainergrouppoolruntimeviews + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&StandbyContainerGroupPoolId{}) +} + +var _ resourceids.ResourceId = &StandbyContainerGroupPoolId{} + +// StandbyContainerGroupPoolId is a struct representing the Resource ID for a Standby Container Group Pool +type StandbyContainerGroupPoolId struct { + SubscriptionId string + ResourceGroupName string + StandbyContainerGroupPoolName string +} + +// NewStandbyContainerGroupPoolID returns a new StandbyContainerGroupPoolId struct +func NewStandbyContainerGroupPoolID(subscriptionId string, resourceGroupName string, standbyContainerGroupPoolName string) StandbyContainerGroupPoolId { + return StandbyContainerGroupPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + StandbyContainerGroupPoolName: standbyContainerGroupPoolName, + } +} + +// ParseStandbyContainerGroupPoolID parses 'input' into a StandbyContainerGroupPoolId +func ParseStandbyContainerGroupPoolID(input string) (*StandbyContainerGroupPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyContainerGroupPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyContainerGroupPoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseStandbyContainerGroupPoolIDInsensitively parses 'input' case-insensitively into a StandbyContainerGroupPoolId +// note: this method should only be used for API response data and not user input +func ParseStandbyContainerGroupPoolIDInsensitively(input string) (*StandbyContainerGroupPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyContainerGroupPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyContainerGroupPoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *StandbyContainerGroupPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.StandbyContainerGroupPoolName, ok = input.Parsed["standbyContainerGroupPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "standbyContainerGroupPoolName", input) + } + + return nil +} + +// ValidateStandbyContainerGroupPoolID checks that 'input' can be parsed as a Standby Container Group Pool ID +func ValidateStandbyContainerGroupPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseStandbyContainerGroupPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Standby Container Group Pool ID +func (id StandbyContainerGroupPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.StandbyPool/standbyContainerGroupPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.StandbyContainerGroupPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Standby Container Group Pool ID +func (id StandbyContainerGroupPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftStandbyPool", "Microsoft.StandbyPool", "Microsoft.StandbyPool"), + resourceids.StaticSegment("staticStandbyContainerGroupPools", "standbyContainerGroupPools", "standbyContainerGroupPools"), + resourceids.UserSpecifiedSegment("standbyContainerGroupPoolName", "standbyContainerGroupPoolName"), + } +} + +// String returns a human-readable description of this Standby Container Group Pool ID +func (id StandbyContainerGroupPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Standby Container Group Pool Name: %q", id.StandbyContainerGroupPoolName), + } + return fmt.Sprintf("Standby Container Group Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_standbycontainergrouppool_test.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_standbycontainergrouppool_test.go new file mode 100644 index 00000000000..13cdfc8e48d --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/id_standbycontainergrouppool_test.go @@ -0,0 +1,282 @@ +package standbycontainergrouppoolruntimeviews + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &StandbyContainerGroupPoolId{} + +func TestNewStandbyContainerGroupPoolID(t *testing.T) { + id := NewStandbyContainerGroupPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyContainerGroupPoolName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.StandbyContainerGroupPoolName != "standbyContainerGroupPoolName" { + t.Fatalf("Expected %q but got %q for Segment 'StandbyContainerGroupPoolName'", id.StandbyContainerGroupPoolName, "standbyContainerGroupPoolName") + } +} + +func TestFormatStandbyContainerGroupPoolID(t *testing.T) { + actual := NewStandbyContainerGroupPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyContainerGroupPoolName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseStandbyContainerGroupPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyContainerGroupPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName", + Expected: &StandbyContainerGroupPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyContainerGroupPoolName: "standbyContainerGroupPoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyContainerGroupPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyContainerGroupPoolName != v.Expected.StandbyContainerGroupPoolName { + t.Fatalf("Expected %q but got %q for StandbyContainerGroupPoolName", v.Expected.StandbyContainerGroupPoolName, actual.StandbyContainerGroupPoolName) + } + + } +} + +func TestParseStandbyContainerGroupPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyContainerGroupPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByCoNtAiNeRgRoUpPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName", + Expected: &StandbyContainerGroupPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyContainerGroupPoolName: "standbyContainerGroupPoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByCoNtAiNeRgRoUpPoOlS/sTaNdByCoNtAiNeRgRoUpPoOlNaMe", + Expected: &StandbyContainerGroupPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + StandbyContainerGroupPoolName: "sTaNdByCoNtAiNeRgRoUpPoOlNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByCoNtAiNeRgRoUpPoOlS/sTaNdByCoNtAiNeRgRoUpPoOlNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyContainerGroupPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyContainerGroupPoolName != v.Expected.StandbyContainerGroupPoolName { + t.Fatalf("Expected %q but got %q for StandbyContainerGroupPoolName", v.Expected.StandbyContainerGroupPoolName, actual.StandbyContainerGroupPoolName) + } + + } +} + +func TestSegmentsForStandbyContainerGroupPoolId(t *testing.T) { + segments := StandbyContainerGroupPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("StandbyContainerGroupPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/method_get.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/method_get.go new file mode 100644 index 00000000000..fe1bbb0becd --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/method_get.go @@ -0,0 +1,53 @@ +package standbycontainergrouppoolruntimeviews + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StandbyContainerGroupPoolRuntimeViewResource +} + +// Get ... +func (c StandbyContainerGroupPoolRuntimeViewsClient) Get(ctx context.Context, id RuntimeViewId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model StandbyContainerGroupPoolRuntimeViewResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/method_listbystandbypool.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/method_listbystandbypool.go new file mode 100644 index 00000000000..84612737fbc --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/method_listbystandbypool.go @@ -0,0 +1,105 @@ +package standbycontainergrouppoolruntimeviews + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByStandbyPoolOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StandbyContainerGroupPoolRuntimeViewResource +} + +type ListByStandbyPoolCompleteResult struct { + LatestHttpResponse *http.Response + Items []StandbyContainerGroupPoolRuntimeViewResource +} + +type ListByStandbyPoolCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByStandbyPoolCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByStandbyPool ... +func (c StandbyContainerGroupPoolRuntimeViewsClient) ListByStandbyPool(ctx context.Context, id StandbyContainerGroupPoolId) (result ListByStandbyPoolOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByStandbyPoolCustomPager{}, + Path: fmt.Sprintf("%s/runtimeViews", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]StandbyContainerGroupPoolRuntimeViewResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByStandbyPoolComplete retrieves all the results into a single object +func (c StandbyContainerGroupPoolRuntimeViewsClient) ListByStandbyPoolComplete(ctx context.Context, id StandbyContainerGroupPoolId) (ListByStandbyPoolCompleteResult, error) { + return c.ListByStandbyPoolCompleteMatchingPredicate(ctx, id, StandbyContainerGroupPoolRuntimeViewResourceOperationPredicate{}) +} + +// ListByStandbyPoolCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StandbyContainerGroupPoolRuntimeViewsClient) ListByStandbyPoolCompleteMatchingPredicate(ctx context.Context, id StandbyContainerGroupPoolId, predicate StandbyContainerGroupPoolRuntimeViewResourceOperationPredicate) (result ListByStandbyPoolCompleteResult, err error) { + items := make([]StandbyContainerGroupPoolRuntimeViewResource, 0) + + resp, err := c.ListByStandbyPool(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByStandbyPoolCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_containergroupinstancecountsummary.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_containergroupinstancecountsummary.go new file mode 100644 index 00000000000..1a1899568df --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_containergroupinstancecountsummary.go @@ -0,0 +1,8 @@ +package standbycontainergrouppoolruntimeviews + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerGroupInstanceCountSummary struct { + InstanceCountsByState []PoolResourceStateCount `json:"instanceCountsByState"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_poolresourcestatecount.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_poolresourcestatecount.go new file mode 100644 index 00000000000..3b7d626c004 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_poolresourcestatecount.go @@ -0,0 +1,9 @@ +package standbycontainergrouppoolruntimeviews + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PoolResourceStateCount struct { + Count int64 `json:"count"` + State string `json:"state"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_standbycontainergrouppoolruntimeviewresource.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_standbycontainergrouppoolruntimeviewresource.go new file mode 100644 index 00000000000..cc129016a83 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_standbycontainergrouppoolruntimeviewresource.go @@ -0,0 +1,16 @@ +package standbycontainergrouppoolruntimeviews + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyContainerGroupPoolRuntimeViewResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *StandbyContainerGroupPoolRuntimeViewResourceProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_standbycontainergrouppoolruntimeviewresourceproperties.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_standbycontainergrouppoolruntimeviewresourceproperties.go new file mode 100644 index 00000000000..9d4f15fe833 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/model_standbycontainergrouppoolruntimeviewresourceproperties.go @@ -0,0 +1,9 @@ +package standbycontainergrouppoolruntimeviews + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyContainerGroupPoolRuntimeViewResourceProperties struct { + InstanceCountSummary []ContainerGroupInstanceCountSummary `json:"instanceCountSummary"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/predicates.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/predicates.go new file mode 100644 index 00000000000..8e0ee57c62e --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/predicates.go @@ -0,0 +1,27 @@ +package standbycontainergrouppoolruntimeviews + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyContainerGroupPoolRuntimeViewResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p StandbyContainerGroupPoolRuntimeViewResourceOperationPredicate) Matches(input StandbyContainerGroupPoolRuntimeViewResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/version.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/version.go new file mode 100644 index 00000000000..10c24e36de8 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppoolruntimeviews/version.go @@ -0,0 +1,10 @@ +package standbycontainergrouppoolruntimeviews + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/standbycontainergrouppoolruntimeviews/2024-03-01" +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/README.md b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/README.md new file mode 100644 index 00000000000..c23cc9af807 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/README.md @@ -0,0 +1,121 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbycontainergrouppools` Documentation + +The `standbycontainergrouppools` SDK allows for interaction with Azure Resource Manager `standbypool` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbycontainergrouppools" +``` + + +### Client Initialization + +```go +client := standbycontainergrouppools.NewStandbyContainerGroupPoolsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `StandbyContainerGroupPoolsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := standbycontainergrouppools.NewStandbyContainerGroupPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyContainerGroupPoolName") + +payload := standbycontainergrouppools.StandbyContainerGroupPoolResource{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `StandbyContainerGroupPoolsClient.Delete` + +```go +ctx := context.TODO() +id := standbycontainergrouppools.NewStandbyContainerGroupPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyContainerGroupPoolName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `StandbyContainerGroupPoolsClient.Get` + +```go +ctx := context.TODO() +id := standbycontainergrouppools.NewStandbyContainerGroupPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyContainerGroupPoolName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `StandbyContainerGroupPoolsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `StandbyContainerGroupPoolsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `StandbyContainerGroupPoolsClient.Update` + +```go +ctx := context.TODO() +id := standbycontainergrouppools.NewStandbyContainerGroupPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyContainerGroupPoolName") + +payload := standbycontainergrouppools.StandbyContainerGroupPoolResourceUpdate{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/client.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/client.go new file mode 100644 index 00000000000..0674629580e --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/client.go @@ -0,0 +1,26 @@ +package standbycontainergrouppools + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyContainerGroupPoolsClient struct { + Client *resourcemanager.Client +} + +func NewStandbyContainerGroupPoolsClientWithBaseURI(sdkApi sdkEnv.Api) (*StandbyContainerGroupPoolsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "standbycontainergrouppools", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating StandbyContainerGroupPoolsClient: %+v", err) + } + + return &StandbyContainerGroupPoolsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/constants.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/constants.go new file mode 100644 index 00000000000..7e3b7a12e1b --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/constants.go @@ -0,0 +1,95 @@ +package standbycontainergrouppools + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type RefillPolicy string + +const ( + RefillPolicyAlways RefillPolicy = "always" +) + +func PossibleValuesForRefillPolicy() []string { + return []string{ + string(RefillPolicyAlways), + } +} + +func (s *RefillPolicy) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRefillPolicy(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRefillPolicy(input string) (*RefillPolicy, error) { + vals := map[string]RefillPolicy{ + "always": RefillPolicyAlways, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RefillPolicy(input) + return &out, nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/id_standbycontainergrouppool.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/id_standbycontainergrouppool.go new file mode 100644 index 00000000000..cd7d833ffc8 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/id_standbycontainergrouppool.go @@ -0,0 +1,130 @@ +package standbycontainergrouppools + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&StandbyContainerGroupPoolId{}) +} + +var _ resourceids.ResourceId = &StandbyContainerGroupPoolId{} + +// StandbyContainerGroupPoolId is a struct representing the Resource ID for a Standby Container Group Pool +type StandbyContainerGroupPoolId struct { + SubscriptionId string + ResourceGroupName string + StandbyContainerGroupPoolName string +} + +// NewStandbyContainerGroupPoolID returns a new StandbyContainerGroupPoolId struct +func NewStandbyContainerGroupPoolID(subscriptionId string, resourceGroupName string, standbyContainerGroupPoolName string) StandbyContainerGroupPoolId { + return StandbyContainerGroupPoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + StandbyContainerGroupPoolName: standbyContainerGroupPoolName, + } +} + +// ParseStandbyContainerGroupPoolID parses 'input' into a StandbyContainerGroupPoolId +func ParseStandbyContainerGroupPoolID(input string) (*StandbyContainerGroupPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyContainerGroupPoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyContainerGroupPoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseStandbyContainerGroupPoolIDInsensitively parses 'input' case-insensitively into a StandbyContainerGroupPoolId +// note: this method should only be used for API response data and not user input +func ParseStandbyContainerGroupPoolIDInsensitively(input string) (*StandbyContainerGroupPoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyContainerGroupPoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyContainerGroupPoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *StandbyContainerGroupPoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.StandbyContainerGroupPoolName, ok = input.Parsed["standbyContainerGroupPoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "standbyContainerGroupPoolName", input) + } + + return nil +} + +// ValidateStandbyContainerGroupPoolID checks that 'input' can be parsed as a Standby Container Group Pool ID +func ValidateStandbyContainerGroupPoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseStandbyContainerGroupPoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Standby Container Group Pool ID +func (id StandbyContainerGroupPoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.StandbyPool/standbyContainerGroupPools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.StandbyContainerGroupPoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Standby Container Group Pool ID +func (id StandbyContainerGroupPoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftStandbyPool", "Microsoft.StandbyPool", "Microsoft.StandbyPool"), + resourceids.StaticSegment("staticStandbyContainerGroupPools", "standbyContainerGroupPools", "standbyContainerGroupPools"), + resourceids.UserSpecifiedSegment("standbyContainerGroupPoolName", "standbyContainerGroupPoolName"), + } +} + +// String returns a human-readable description of this Standby Container Group Pool ID +func (id StandbyContainerGroupPoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Standby Container Group Pool Name: %q", id.StandbyContainerGroupPoolName), + } + return fmt.Sprintf("Standby Container Group Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/id_standbycontainergrouppool_test.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/id_standbycontainergrouppool_test.go new file mode 100644 index 00000000000..1c1695109b7 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/id_standbycontainergrouppool_test.go @@ -0,0 +1,282 @@ +package standbycontainergrouppools + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &StandbyContainerGroupPoolId{} + +func TestNewStandbyContainerGroupPoolID(t *testing.T) { + id := NewStandbyContainerGroupPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyContainerGroupPoolName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.StandbyContainerGroupPoolName != "standbyContainerGroupPoolName" { + t.Fatalf("Expected %q but got %q for Segment 'StandbyContainerGroupPoolName'", id.StandbyContainerGroupPoolName, "standbyContainerGroupPoolName") + } +} + +func TestFormatStandbyContainerGroupPoolID(t *testing.T) { + actual := NewStandbyContainerGroupPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyContainerGroupPoolName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseStandbyContainerGroupPoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyContainerGroupPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName", + Expected: &StandbyContainerGroupPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyContainerGroupPoolName: "standbyContainerGroupPoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyContainerGroupPoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyContainerGroupPoolName != v.Expected.StandbyContainerGroupPoolName { + t.Fatalf("Expected %q but got %q for StandbyContainerGroupPoolName", v.Expected.StandbyContainerGroupPoolName, actual.StandbyContainerGroupPoolName) + } + + } +} + +func TestParseStandbyContainerGroupPoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyContainerGroupPoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByCoNtAiNeRgRoUpPoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName", + Expected: &StandbyContainerGroupPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyContainerGroupPoolName: "standbyContainerGroupPoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyContainerGroupPools/standbyContainerGroupPoolName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByCoNtAiNeRgRoUpPoOlS/sTaNdByCoNtAiNeRgRoUpPoOlNaMe", + Expected: &StandbyContainerGroupPoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + StandbyContainerGroupPoolName: "sTaNdByCoNtAiNeRgRoUpPoOlNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByCoNtAiNeRgRoUpPoOlS/sTaNdByCoNtAiNeRgRoUpPoOlNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyContainerGroupPoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyContainerGroupPoolName != v.Expected.StandbyContainerGroupPoolName { + t.Fatalf("Expected %q but got %q for StandbyContainerGroupPoolName", v.Expected.StandbyContainerGroupPoolName, actual.StandbyContainerGroupPoolName) + } + + } +} + +func TestSegmentsForStandbyContainerGroupPoolId(t *testing.T) { + segments := StandbyContainerGroupPoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("StandbyContainerGroupPoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_createorupdate.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_createorupdate.go new file mode 100644 index 00000000000..c3d1e96f40a --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_createorupdate.go @@ -0,0 +1,75 @@ +package standbycontainergrouppools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *StandbyContainerGroupPoolResource +} + +// CreateOrUpdate ... +func (c StandbyContainerGroupPoolsClient) CreateOrUpdate(ctx context.Context, id StandbyContainerGroupPoolId, input StandbyContainerGroupPoolResource) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c StandbyContainerGroupPoolsClient) CreateOrUpdateThenPoll(ctx context.Context, id StandbyContainerGroupPoolId, input StandbyContainerGroupPoolResource) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_delete.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_delete.go new file mode 100644 index 00000000000..3549685c956 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_delete.go @@ -0,0 +1,70 @@ +package standbycontainergrouppools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c StandbyContainerGroupPoolsClient) Delete(ctx context.Context, id StandbyContainerGroupPoolId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c StandbyContainerGroupPoolsClient) DeleteThenPoll(ctx context.Context, id StandbyContainerGroupPoolId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_get.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_get.go new file mode 100644 index 00000000000..6e0bf66e4db --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_get.go @@ -0,0 +1,53 @@ +package standbycontainergrouppools + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StandbyContainerGroupPoolResource +} + +// Get ... +func (c StandbyContainerGroupPoolsClient) Get(ctx context.Context, id StandbyContainerGroupPoolId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model StandbyContainerGroupPoolResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_listbyresourcegroup.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_listbyresourcegroup.go new file mode 100644 index 00000000000..72e7005c06d --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package standbycontainergrouppools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StandbyContainerGroupPoolResource +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []StandbyContainerGroupPoolResource +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c StandbyContainerGroupPoolsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.StandbyPool/standbyContainerGroupPools", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]StandbyContainerGroupPoolResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c StandbyContainerGroupPoolsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, StandbyContainerGroupPoolResourceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StandbyContainerGroupPoolsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate StandbyContainerGroupPoolResourceOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]StandbyContainerGroupPoolResource, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_listbysubscription.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_listbysubscription.go new file mode 100644 index 00000000000..e9e5d92419e --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_listbysubscription.go @@ -0,0 +1,106 @@ +package standbycontainergrouppools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StandbyContainerGroupPoolResource +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []StandbyContainerGroupPoolResource +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c StandbyContainerGroupPoolsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.StandbyPool/standbyContainerGroupPools", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]StandbyContainerGroupPoolResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySubscriptionComplete retrieves all the results into a single object +func (c StandbyContainerGroupPoolsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, StandbyContainerGroupPoolResourceOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StandbyContainerGroupPoolsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate StandbyContainerGroupPoolResourceOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]StandbyContainerGroupPoolResource, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_update.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_update.go new file mode 100644 index 00000000000..e440146bc33 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/method_update.go @@ -0,0 +1,57 @@ +package standbycontainergrouppools + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StandbyContainerGroupPoolResource +} + +// Update ... +func (c StandbyContainerGroupPoolsClient) Update(ctx context.Context, id StandbyContainerGroupPoolId, input StandbyContainerGroupPoolResourceUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model StandbyContainerGroupPoolResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_containergroupprofile.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_containergroupprofile.go new file mode 100644 index 00000000000..03933f8dae5 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_containergroupprofile.go @@ -0,0 +1,9 @@ +package standbycontainergrouppools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerGroupProfile struct { + Id string `json:"id"` + Revision *int64 `json:"revision,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_containergroupproperties.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_containergroupproperties.go new file mode 100644 index 00000000000..1abe6ae2a42 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_containergroupproperties.go @@ -0,0 +1,9 @@ +package standbycontainergrouppools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ContainerGroupProperties struct { + ContainerGroupProfile ContainerGroupProfile `json:"containerGroupProfile"` + SubnetIds *[]Subnet `json:"subnetIds,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolelasticityprofile.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolelasticityprofile.go new file mode 100644 index 00000000000..eb8a167738d --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolelasticityprofile.go @@ -0,0 +1,9 @@ +package standbycontainergrouppools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyContainerGroupPoolElasticityProfile struct { + MaxReadyCapacity int64 `json:"maxReadyCapacity"` + RefillPolicy *RefillPolicy `json:"refillPolicy,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresource.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresource.go new file mode 100644 index 00000000000..823f1b55647 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresource.go @@ -0,0 +1,18 @@ +package standbycontainergrouppools + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyContainerGroupPoolResource struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *StandbyContainerGroupPoolResourceProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresourceproperties.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresourceproperties.go new file mode 100644 index 00000000000..4a1d255b72d --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresourceproperties.go @@ -0,0 +1,10 @@ +package standbycontainergrouppools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyContainerGroupPoolResourceProperties struct { + ContainerGroupProperties ContainerGroupProperties `json:"containerGroupProperties"` + ElasticityProfile StandbyContainerGroupPoolElasticityProfile `json:"elasticityProfile"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresourceupdate.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresourceupdate.go new file mode 100644 index 00000000000..58928b2b07a --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresourceupdate.go @@ -0,0 +1,9 @@ +package standbycontainergrouppools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyContainerGroupPoolResourceUpdate struct { + Properties *StandbyContainerGroupPoolResourceUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresourceupdateproperties.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresourceupdateproperties.go new file mode 100644 index 00000000000..6ed4190e145 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_standbycontainergrouppoolresourceupdateproperties.go @@ -0,0 +1,9 @@ +package standbycontainergrouppools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyContainerGroupPoolResourceUpdateProperties struct { + ContainerGroupProperties *ContainerGroupProperties `json:"containerGroupProperties,omitempty"` + ElasticityProfile *StandbyContainerGroupPoolElasticityProfile `json:"elasticityProfile,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_subnet.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_subnet.go new file mode 100644 index 00000000000..bdf6d353cf7 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/model_subnet.go @@ -0,0 +1,8 @@ +package standbycontainergrouppools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Subnet struct { + Id string `json:"id"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/predicates.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/predicates.go new file mode 100644 index 00000000000..f083c997467 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/predicates.go @@ -0,0 +1,32 @@ +package standbycontainergrouppools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyContainerGroupPoolResourceOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p StandbyContainerGroupPoolResourceOperationPredicate) Matches(input StandbyContainerGroupPoolResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/version.go b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/version.go new file mode 100644 index 00000000000..2cc97f2ae08 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbycontainergrouppools/version.go @@ -0,0 +1,10 @@ +package standbycontainergrouppools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/standbycontainergrouppools/2024-03-01" +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/README.md b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/README.md new file mode 100644 index 00000000000..30f2bf81c91 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews` Documentation + +The `standbyvirtualmachinepoolruntimeviews` SDK allows for interaction with Azure Resource Manager `standbypool` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews" +``` + + +### Client Initialization + +```go +client := standbyvirtualmachinepoolruntimeviews.NewStandbyVirtualMachinePoolRuntimeViewsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `StandbyVirtualMachinePoolRuntimeViewsClient.Get` + +```go +ctx := context.TODO() +id := standbyvirtualmachinepoolruntimeviews.NewStandbyVirtualMachinePoolRuntimeViewID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName", "runtimeViewName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `StandbyVirtualMachinePoolRuntimeViewsClient.ListByStandbyPool` + +```go +ctx := context.TODO() +id := standbyvirtualmachinepoolruntimeviews.NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName") + +// alternatively `client.ListByStandbyPool(ctx, id)` can be used to do batched pagination +items, err := client.ListByStandbyPoolComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/client.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/client.go new file mode 100644 index 00000000000..21932432464 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/client.go @@ -0,0 +1,26 @@ +package standbyvirtualmachinepoolruntimeviews + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolRuntimeViewsClient struct { + Client *resourcemanager.Client +} + +func NewStandbyVirtualMachinePoolRuntimeViewsClientWithBaseURI(sdkApi sdkEnv.Api) (*StandbyVirtualMachinePoolRuntimeViewsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "standbyvirtualmachinepoolruntimeviews", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating StandbyVirtualMachinePoolRuntimeViewsClient: %+v", err) + } + + return &StandbyVirtualMachinePoolRuntimeViewsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/constants.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/constants.go new file mode 100644 index 00000000000..88d8f62e671 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/constants.go @@ -0,0 +1,57 @@ +package standbyvirtualmachinepoolruntimeviews + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepool.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepool.go new file mode 100644 index 00000000000..edd114dccba --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepool.go @@ -0,0 +1,130 @@ +package standbyvirtualmachinepoolruntimeviews + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&StandbyVirtualMachinePoolId{}) +} + +var _ resourceids.ResourceId = &StandbyVirtualMachinePoolId{} + +// StandbyVirtualMachinePoolId is a struct representing the Resource ID for a Standby Virtual Machine Pool +type StandbyVirtualMachinePoolId struct { + SubscriptionId string + ResourceGroupName string + StandbyVirtualMachinePoolName string +} + +// NewStandbyVirtualMachinePoolID returns a new StandbyVirtualMachinePoolId struct +func NewStandbyVirtualMachinePoolID(subscriptionId string, resourceGroupName string, standbyVirtualMachinePoolName string) StandbyVirtualMachinePoolId { + return StandbyVirtualMachinePoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + StandbyVirtualMachinePoolName: standbyVirtualMachinePoolName, + } +} + +// ParseStandbyVirtualMachinePoolID parses 'input' into a StandbyVirtualMachinePoolId +func ParseStandbyVirtualMachinePoolID(input string) (*StandbyVirtualMachinePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyVirtualMachinePoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyVirtualMachinePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseStandbyVirtualMachinePoolIDInsensitively parses 'input' case-insensitively into a StandbyVirtualMachinePoolId +// note: this method should only be used for API response data and not user input +func ParseStandbyVirtualMachinePoolIDInsensitively(input string) (*StandbyVirtualMachinePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyVirtualMachinePoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyVirtualMachinePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *StandbyVirtualMachinePoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.StandbyVirtualMachinePoolName, ok = input.Parsed["standbyVirtualMachinePoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "standbyVirtualMachinePoolName", input) + } + + return nil +} + +// ValidateStandbyVirtualMachinePoolID checks that 'input' can be parsed as a Standby Virtual Machine Pool ID +func ValidateStandbyVirtualMachinePoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseStandbyVirtualMachinePoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Standby Virtual Machine Pool ID +func (id StandbyVirtualMachinePoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.StandbyVirtualMachinePoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Standby Virtual Machine Pool ID +func (id StandbyVirtualMachinePoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftStandbyPool", "Microsoft.StandbyPool", "Microsoft.StandbyPool"), + resourceids.StaticSegment("staticStandbyVirtualMachinePools", "standbyVirtualMachinePools", "standbyVirtualMachinePools"), + resourceids.UserSpecifiedSegment("standbyVirtualMachinePoolName", "standbyVirtualMachinePoolName"), + } +} + +// String returns a human-readable description of this Standby Virtual Machine Pool ID +func (id StandbyVirtualMachinePoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Standby Virtual Machine Pool Name: %q", id.StandbyVirtualMachinePoolName), + } + return fmt.Sprintf("Standby Virtual Machine Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepool_test.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepool_test.go new file mode 100644 index 00000000000..5a7eef993c3 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepool_test.go @@ -0,0 +1,282 @@ +package standbyvirtualmachinepoolruntimeviews + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &StandbyVirtualMachinePoolId{} + +func TestNewStandbyVirtualMachinePoolID(t *testing.T) { + id := NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.StandbyVirtualMachinePoolName != "standbyVirtualMachinePoolName" { + t.Fatalf("Expected %q but got %q for Segment 'StandbyVirtualMachinePoolName'", id.StandbyVirtualMachinePoolName, "standbyVirtualMachinePoolName") + } +} + +func TestFormatStandbyVirtualMachinePoolID(t *testing.T) { + actual := NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseStandbyVirtualMachinePoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyVirtualMachinePoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName", + Expected: &StandbyVirtualMachinePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyVirtualMachinePoolName: "standbyVirtualMachinePoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyVirtualMachinePoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyVirtualMachinePoolName != v.Expected.StandbyVirtualMachinePoolName { + t.Fatalf("Expected %q but got %q for StandbyVirtualMachinePoolName", v.Expected.StandbyVirtualMachinePoolName, actual.StandbyVirtualMachinePoolName) + } + + } +} + +func TestParseStandbyVirtualMachinePoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyVirtualMachinePoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName", + Expected: &StandbyVirtualMachinePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyVirtualMachinePoolName: "standbyVirtualMachinePoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe", + Expected: &StandbyVirtualMachinePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + StandbyVirtualMachinePoolName: "sTaNdByViRtUaLmAcHiNePoOlNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyVirtualMachinePoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyVirtualMachinePoolName != v.Expected.StandbyVirtualMachinePoolName { + t.Fatalf("Expected %q but got %q for StandbyVirtualMachinePoolName", v.Expected.StandbyVirtualMachinePoolName, actual.StandbyVirtualMachinePoolName) + } + + } +} + +func TestSegmentsForStandbyVirtualMachinePoolId(t *testing.T) { + segments := StandbyVirtualMachinePoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("StandbyVirtualMachinePoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepoolruntimeview.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepoolruntimeview.go new file mode 100644 index 00000000000..589029778e3 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepoolruntimeview.go @@ -0,0 +1,139 @@ +package standbyvirtualmachinepoolruntimeviews + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&StandbyVirtualMachinePoolRuntimeViewId{}) +} + +var _ resourceids.ResourceId = &StandbyVirtualMachinePoolRuntimeViewId{} + +// StandbyVirtualMachinePoolRuntimeViewId is a struct representing the Resource ID for a Standby Virtual Machine Pool Runtime View +type StandbyVirtualMachinePoolRuntimeViewId struct { + SubscriptionId string + ResourceGroupName string + StandbyVirtualMachinePoolName string + RuntimeViewName string +} + +// NewStandbyVirtualMachinePoolRuntimeViewID returns a new StandbyVirtualMachinePoolRuntimeViewId struct +func NewStandbyVirtualMachinePoolRuntimeViewID(subscriptionId string, resourceGroupName string, standbyVirtualMachinePoolName string, runtimeViewName string) StandbyVirtualMachinePoolRuntimeViewId { + return StandbyVirtualMachinePoolRuntimeViewId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + StandbyVirtualMachinePoolName: standbyVirtualMachinePoolName, + RuntimeViewName: runtimeViewName, + } +} + +// ParseStandbyVirtualMachinePoolRuntimeViewID parses 'input' into a StandbyVirtualMachinePoolRuntimeViewId +func ParseStandbyVirtualMachinePoolRuntimeViewID(input string) (*StandbyVirtualMachinePoolRuntimeViewId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyVirtualMachinePoolRuntimeViewId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyVirtualMachinePoolRuntimeViewId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseStandbyVirtualMachinePoolRuntimeViewIDInsensitively parses 'input' case-insensitively into a StandbyVirtualMachinePoolRuntimeViewId +// note: this method should only be used for API response data and not user input +func ParseStandbyVirtualMachinePoolRuntimeViewIDInsensitively(input string) (*StandbyVirtualMachinePoolRuntimeViewId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyVirtualMachinePoolRuntimeViewId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyVirtualMachinePoolRuntimeViewId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *StandbyVirtualMachinePoolRuntimeViewId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.StandbyVirtualMachinePoolName, ok = input.Parsed["standbyVirtualMachinePoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "standbyVirtualMachinePoolName", input) + } + + if id.RuntimeViewName, ok = input.Parsed["runtimeViewName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "runtimeViewName", input) + } + + return nil +} + +// ValidateStandbyVirtualMachinePoolRuntimeViewID checks that 'input' can be parsed as a Standby Virtual Machine Pool Runtime View ID +func ValidateStandbyVirtualMachinePoolRuntimeViewID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseStandbyVirtualMachinePoolRuntimeViewID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Standby Virtual Machine Pool Runtime View ID +func (id StandbyVirtualMachinePoolRuntimeViewId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/%s/runtimeViews/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.StandbyVirtualMachinePoolName, id.RuntimeViewName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Standby Virtual Machine Pool Runtime View ID +func (id StandbyVirtualMachinePoolRuntimeViewId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftStandbyPool", "Microsoft.StandbyPool", "Microsoft.StandbyPool"), + resourceids.StaticSegment("staticStandbyVirtualMachinePools", "standbyVirtualMachinePools", "standbyVirtualMachinePools"), + resourceids.UserSpecifiedSegment("standbyVirtualMachinePoolName", "standbyVirtualMachinePoolName"), + resourceids.StaticSegment("staticRuntimeViews", "runtimeViews", "runtimeViews"), + resourceids.UserSpecifiedSegment("runtimeViewName", "runtimeViewName"), + } +} + +// String returns a human-readable description of this Standby Virtual Machine Pool Runtime View ID +func (id StandbyVirtualMachinePoolRuntimeViewId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Standby Virtual Machine Pool Name: %q", id.StandbyVirtualMachinePoolName), + fmt.Sprintf("Runtime View Name: %q", id.RuntimeViewName), + } + return fmt.Sprintf("Standby Virtual Machine Pool Runtime View (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepoolruntimeview_test.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepoolruntimeview_test.go new file mode 100644 index 00000000000..bd0f36a6b2f --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/id_standbyvirtualmachinepoolruntimeview_test.go @@ -0,0 +1,327 @@ +package standbyvirtualmachinepoolruntimeviews + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &StandbyVirtualMachinePoolRuntimeViewId{} + +func TestNewStandbyVirtualMachinePoolRuntimeViewID(t *testing.T) { + id := NewStandbyVirtualMachinePoolRuntimeViewID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName", "runtimeViewName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.StandbyVirtualMachinePoolName != "standbyVirtualMachinePoolName" { + t.Fatalf("Expected %q but got %q for Segment 'StandbyVirtualMachinePoolName'", id.StandbyVirtualMachinePoolName, "standbyVirtualMachinePoolName") + } + + if id.RuntimeViewName != "runtimeViewName" { + t.Fatalf("Expected %q but got %q for Segment 'RuntimeViewName'", id.RuntimeViewName, "runtimeViewName") + } +} + +func TestFormatStandbyVirtualMachinePoolRuntimeViewID(t *testing.T) { + actual := NewStandbyVirtualMachinePoolRuntimeViewID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName", "runtimeViewName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/runtimeViews/runtimeViewName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseStandbyVirtualMachinePoolRuntimeViewID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyVirtualMachinePoolRuntimeViewId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/runtimeViews", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/runtimeViews/runtimeViewName", + Expected: &StandbyVirtualMachinePoolRuntimeViewId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyVirtualMachinePoolName: "standbyVirtualMachinePoolName", + RuntimeViewName: "runtimeViewName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/runtimeViews/runtimeViewName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyVirtualMachinePoolRuntimeViewID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyVirtualMachinePoolName != v.Expected.StandbyVirtualMachinePoolName { + t.Fatalf("Expected %q but got %q for StandbyVirtualMachinePoolName", v.Expected.StandbyVirtualMachinePoolName, actual.StandbyVirtualMachinePoolName) + } + + if actual.RuntimeViewName != v.Expected.RuntimeViewName { + t.Fatalf("Expected %q but got %q for RuntimeViewName", v.Expected.RuntimeViewName, actual.RuntimeViewName) + } + + } +} + +func TestParseStandbyVirtualMachinePoolRuntimeViewIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyVirtualMachinePoolRuntimeViewId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/runtimeViews", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe/rUnTiMeViEwS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/runtimeViews/runtimeViewName", + Expected: &StandbyVirtualMachinePoolRuntimeViewId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyVirtualMachinePoolName: "standbyVirtualMachinePoolName", + RuntimeViewName: "runtimeViewName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/runtimeViews/runtimeViewName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe/rUnTiMeViEwS/rUnTiMeViEwNaMe", + Expected: &StandbyVirtualMachinePoolRuntimeViewId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + StandbyVirtualMachinePoolName: "sTaNdByViRtUaLmAcHiNePoOlNaMe", + RuntimeViewName: "rUnTiMeViEwNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe/rUnTiMeViEwS/rUnTiMeViEwNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyVirtualMachinePoolRuntimeViewIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyVirtualMachinePoolName != v.Expected.StandbyVirtualMachinePoolName { + t.Fatalf("Expected %q but got %q for StandbyVirtualMachinePoolName", v.Expected.StandbyVirtualMachinePoolName, actual.StandbyVirtualMachinePoolName) + } + + if actual.RuntimeViewName != v.Expected.RuntimeViewName { + t.Fatalf("Expected %q but got %q for RuntimeViewName", v.Expected.RuntimeViewName, actual.RuntimeViewName) + } + + } +} + +func TestSegmentsForStandbyVirtualMachinePoolRuntimeViewId(t *testing.T) { + segments := StandbyVirtualMachinePoolRuntimeViewId{}.Segments() + if len(segments) == 0 { + t.Fatalf("StandbyVirtualMachinePoolRuntimeViewId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/method_get.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/method_get.go new file mode 100644 index 00000000000..32ddf1067ba --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/method_get.go @@ -0,0 +1,53 @@ +package standbyvirtualmachinepoolruntimeviews + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StandbyVirtualMachinePoolRuntimeViewResource +} + +// Get ... +func (c StandbyVirtualMachinePoolRuntimeViewsClient) Get(ctx context.Context, id StandbyVirtualMachinePoolRuntimeViewId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model StandbyVirtualMachinePoolRuntimeViewResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/method_listbystandbypool.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/method_listbystandbypool.go new file mode 100644 index 00000000000..2c208af9494 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/method_listbystandbypool.go @@ -0,0 +1,105 @@ +package standbyvirtualmachinepoolruntimeviews + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByStandbyPoolOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StandbyVirtualMachinePoolRuntimeViewResource +} + +type ListByStandbyPoolCompleteResult struct { + LatestHttpResponse *http.Response + Items []StandbyVirtualMachinePoolRuntimeViewResource +} + +type ListByStandbyPoolCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByStandbyPoolCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByStandbyPool ... +func (c StandbyVirtualMachinePoolRuntimeViewsClient) ListByStandbyPool(ctx context.Context, id StandbyVirtualMachinePoolId) (result ListByStandbyPoolOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByStandbyPoolCustomPager{}, + Path: fmt.Sprintf("%s/runtimeViews", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]StandbyVirtualMachinePoolRuntimeViewResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByStandbyPoolComplete retrieves all the results into a single object +func (c StandbyVirtualMachinePoolRuntimeViewsClient) ListByStandbyPoolComplete(ctx context.Context, id StandbyVirtualMachinePoolId) (ListByStandbyPoolCompleteResult, error) { + return c.ListByStandbyPoolCompleteMatchingPredicate(ctx, id, StandbyVirtualMachinePoolRuntimeViewResourceOperationPredicate{}) +} + +// ListByStandbyPoolCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StandbyVirtualMachinePoolRuntimeViewsClient) ListByStandbyPoolCompleteMatchingPredicate(ctx context.Context, id StandbyVirtualMachinePoolId, predicate StandbyVirtualMachinePoolRuntimeViewResourceOperationPredicate) (result ListByStandbyPoolCompleteResult, err error) { + items := make([]StandbyVirtualMachinePoolRuntimeViewResource, 0) + + resp, err := c.ListByStandbyPool(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByStandbyPoolCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_poolresourcestatecount.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_poolresourcestatecount.go new file mode 100644 index 00000000000..fbd4dc9f3d8 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_poolresourcestatecount.go @@ -0,0 +1,9 @@ +package standbyvirtualmachinepoolruntimeviews + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PoolResourceStateCount struct { + Count int64 `json:"count"` + State string `json:"state"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_standbyvirtualmachinepoolruntimeviewresource.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_standbyvirtualmachinepoolruntimeviewresource.go new file mode 100644 index 00000000000..3f39def8584 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_standbyvirtualmachinepoolruntimeviewresource.go @@ -0,0 +1,16 @@ +package standbyvirtualmachinepoolruntimeviews + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolRuntimeViewResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *StandbyVirtualMachinePoolRuntimeViewResourceProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_standbyvirtualmachinepoolruntimeviewresourceproperties.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_standbyvirtualmachinepoolruntimeviewresourceproperties.go new file mode 100644 index 00000000000..19cb6c0f6e1 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_standbyvirtualmachinepoolruntimeviewresourceproperties.go @@ -0,0 +1,9 @@ +package standbyvirtualmachinepoolruntimeviews + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolRuntimeViewResourceProperties struct { + InstanceCountSummary []VirtualMachineInstanceCountSummary `json:"instanceCountSummary"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_virtualmachineinstancecountsummary.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_virtualmachineinstancecountsummary.go new file mode 100644 index 00000000000..d0772decddf --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/model_virtualmachineinstancecountsummary.go @@ -0,0 +1,9 @@ +package standbyvirtualmachinepoolruntimeviews + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualMachineInstanceCountSummary struct { + InstanceCountsByState []PoolResourceStateCount `json:"instanceCountsByState"` + Zone *int64 `json:"zone,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/predicates.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/predicates.go new file mode 100644 index 00000000000..8e1645affaf --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/predicates.go @@ -0,0 +1,27 @@ +package standbyvirtualmachinepoolruntimeviews + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolRuntimeViewResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p StandbyVirtualMachinePoolRuntimeViewResourceOperationPredicate) Matches(input StandbyVirtualMachinePoolRuntimeViewResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/version.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/version.go new file mode 100644 index 00000000000..41b45dd581d --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepoolruntimeviews/version.go @@ -0,0 +1,10 @@ +package standbyvirtualmachinepoolruntimeviews + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/standbyvirtualmachinepoolruntimeviews/2024-03-01" +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/README.md b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/README.md new file mode 100644 index 00000000000..3a64e7d4e09 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/README.md @@ -0,0 +1,121 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools` Documentation + +The `standbyvirtualmachinepools` SDK allows for interaction with Azure Resource Manager `standbypool` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools" +``` + + +### Client Initialization + +```go +client := standbyvirtualmachinepools.NewStandbyVirtualMachinePoolsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `StandbyVirtualMachinePoolsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := standbyvirtualmachinepools.NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName") + +payload := standbyvirtualmachinepools.StandbyVirtualMachinePoolResource{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `StandbyVirtualMachinePoolsClient.Delete` + +```go +ctx := context.TODO() +id := standbyvirtualmachinepools.NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `StandbyVirtualMachinePoolsClient.Get` + +```go +ctx := context.TODO() +id := standbyvirtualmachinepools.NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `StandbyVirtualMachinePoolsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `StandbyVirtualMachinePoolsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `StandbyVirtualMachinePoolsClient.Update` + +```go +ctx := context.TODO() +id := standbyvirtualmachinepools.NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName") + +payload := standbyvirtualmachinepools.StandbyVirtualMachinePoolResourceUpdate{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/client.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/client.go new file mode 100644 index 00000000000..5cc450073f3 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/client.go @@ -0,0 +1,26 @@ +package standbyvirtualmachinepools + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolsClient struct { + Client *resourcemanager.Client +} + +func NewStandbyVirtualMachinePoolsClientWithBaseURI(sdkApi sdkEnv.Api) (*StandbyVirtualMachinePoolsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "standbyvirtualmachinepools", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating StandbyVirtualMachinePoolsClient: %+v", err) + } + + return &StandbyVirtualMachinePoolsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/constants.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/constants.go new file mode 100644 index 00000000000..e3010f1886c --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/constants.go @@ -0,0 +1,98 @@ +package standbyvirtualmachinepools + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type VirtualMachineState string + +const ( + VirtualMachineStateDeallocated VirtualMachineState = "Deallocated" + VirtualMachineStateRunning VirtualMachineState = "Running" +) + +func PossibleValuesForVirtualMachineState() []string { + return []string{ + string(VirtualMachineStateDeallocated), + string(VirtualMachineStateRunning), + } +} + +func (s *VirtualMachineState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVirtualMachineState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVirtualMachineState(input string) (*VirtualMachineState, error) { + vals := map[string]VirtualMachineState{ + "deallocated": VirtualMachineStateDeallocated, + "running": VirtualMachineStateRunning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VirtualMachineState(input) + return &out, nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/id_standbyvirtualmachinepool.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/id_standbyvirtualmachinepool.go new file mode 100644 index 00000000000..21ce39183a9 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/id_standbyvirtualmachinepool.go @@ -0,0 +1,130 @@ +package standbyvirtualmachinepools + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&StandbyVirtualMachinePoolId{}) +} + +var _ resourceids.ResourceId = &StandbyVirtualMachinePoolId{} + +// StandbyVirtualMachinePoolId is a struct representing the Resource ID for a Standby Virtual Machine Pool +type StandbyVirtualMachinePoolId struct { + SubscriptionId string + ResourceGroupName string + StandbyVirtualMachinePoolName string +} + +// NewStandbyVirtualMachinePoolID returns a new StandbyVirtualMachinePoolId struct +func NewStandbyVirtualMachinePoolID(subscriptionId string, resourceGroupName string, standbyVirtualMachinePoolName string) StandbyVirtualMachinePoolId { + return StandbyVirtualMachinePoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + StandbyVirtualMachinePoolName: standbyVirtualMachinePoolName, + } +} + +// ParseStandbyVirtualMachinePoolID parses 'input' into a StandbyVirtualMachinePoolId +func ParseStandbyVirtualMachinePoolID(input string) (*StandbyVirtualMachinePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyVirtualMachinePoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyVirtualMachinePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseStandbyVirtualMachinePoolIDInsensitively parses 'input' case-insensitively into a StandbyVirtualMachinePoolId +// note: this method should only be used for API response data and not user input +func ParseStandbyVirtualMachinePoolIDInsensitively(input string) (*StandbyVirtualMachinePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyVirtualMachinePoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyVirtualMachinePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *StandbyVirtualMachinePoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.StandbyVirtualMachinePoolName, ok = input.Parsed["standbyVirtualMachinePoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "standbyVirtualMachinePoolName", input) + } + + return nil +} + +// ValidateStandbyVirtualMachinePoolID checks that 'input' can be parsed as a Standby Virtual Machine Pool ID +func ValidateStandbyVirtualMachinePoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseStandbyVirtualMachinePoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Standby Virtual Machine Pool ID +func (id StandbyVirtualMachinePoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.StandbyVirtualMachinePoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Standby Virtual Machine Pool ID +func (id StandbyVirtualMachinePoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftStandbyPool", "Microsoft.StandbyPool", "Microsoft.StandbyPool"), + resourceids.StaticSegment("staticStandbyVirtualMachinePools", "standbyVirtualMachinePools", "standbyVirtualMachinePools"), + resourceids.UserSpecifiedSegment("standbyVirtualMachinePoolName", "standbyVirtualMachinePoolName"), + } +} + +// String returns a human-readable description of this Standby Virtual Machine Pool ID +func (id StandbyVirtualMachinePoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Standby Virtual Machine Pool Name: %q", id.StandbyVirtualMachinePoolName), + } + return fmt.Sprintf("Standby Virtual Machine Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/id_standbyvirtualmachinepool_test.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/id_standbyvirtualmachinepool_test.go new file mode 100644 index 00000000000..1c56a7516be --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/id_standbyvirtualmachinepool_test.go @@ -0,0 +1,282 @@ +package standbyvirtualmachinepools + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &StandbyVirtualMachinePoolId{} + +func TestNewStandbyVirtualMachinePoolID(t *testing.T) { + id := NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.StandbyVirtualMachinePoolName != "standbyVirtualMachinePoolName" { + t.Fatalf("Expected %q but got %q for Segment 'StandbyVirtualMachinePoolName'", id.StandbyVirtualMachinePoolName, "standbyVirtualMachinePoolName") + } +} + +func TestFormatStandbyVirtualMachinePoolID(t *testing.T) { + actual := NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseStandbyVirtualMachinePoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyVirtualMachinePoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName", + Expected: &StandbyVirtualMachinePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyVirtualMachinePoolName: "standbyVirtualMachinePoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyVirtualMachinePoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyVirtualMachinePoolName != v.Expected.StandbyVirtualMachinePoolName { + t.Fatalf("Expected %q but got %q for StandbyVirtualMachinePoolName", v.Expected.StandbyVirtualMachinePoolName, actual.StandbyVirtualMachinePoolName) + } + + } +} + +func TestParseStandbyVirtualMachinePoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyVirtualMachinePoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName", + Expected: &StandbyVirtualMachinePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyVirtualMachinePoolName: "standbyVirtualMachinePoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe", + Expected: &StandbyVirtualMachinePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + StandbyVirtualMachinePoolName: "sTaNdByViRtUaLmAcHiNePoOlNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyVirtualMachinePoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyVirtualMachinePoolName != v.Expected.StandbyVirtualMachinePoolName { + t.Fatalf("Expected %q but got %q for StandbyVirtualMachinePoolName", v.Expected.StandbyVirtualMachinePoolName, actual.StandbyVirtualMachinePoolName) + } + + } +} + +func TestSegmentsForStandbyVirtualMachinePoolId(t *testing.T) { + segments := StandbyVirtualMachinePoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("StandbyVirtualMachinePoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_createorupdate.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_createorupdate.go new file mode 100644 index 00000000000..95f8487d7f9 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_createorupdate.go @@ -0,0 +1,75 @@ +package standbyvirtualmachinepools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *StandbyVirtualMachinePoolResource +} + +// CreateOrUpdate ... +func (c StandbyVirtualMachinePoolsClient) CreateOrUpdate(ctx context.Context, id StandbyVirtualMachinePoolId, input StandbyVirtualMachinePoolResource) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c StandbyVirtualMachinePoolsClient) CreateOrUpdateThenPoll(ctx context.Context, id StandbyVirtualMachinePoolId, input StandbyVirtualMachinePoolResource) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_delete.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_delete.go new file mode 100644 index 00000000000..2166eb6c1d1 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_delete.go @@ -0,0 +1,70 @@ +package standbyvirtualmachinepools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c StandbyVirtualMachinePoolsClient) Delete(ctx context.Context, id StandbyVirtualMachinePoolId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c StandbyVirtualMachinePoolsClient) DeleteThenPoll(ctx context.Context, id StandbyVirtualMachinePoolId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_get.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_get.go new file mode 100644 index 00000000000..f0c6e16ef01 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_get.go @@ -0,0 +1,53 @@ +package standbyvirtualmachinepools + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StandbyVirtualMachinePoolResource +} + +// Get ... +func (c StandbyVirtualMachinePoolsClient) Get(ctx context.Context, id StandbyVirtualMachinePoolId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model StandbyVirtualMachinePoolResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbyresourcegroup.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbyresourcegroup.go new file mode 100644 index 00000000000..18ac9c91c83 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package standbyvirtualmachinepools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StandbyVirtualMachinePoolResource +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []StandbyVirtualMachinePoolResource +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c StandbyVirtualMachinePoolsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]StandbyVirtualMachinePoolResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c StandbyVirtualMachinePoolsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, StandbyVirtualMachinePoolResourceOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StandbyVirtualMachinePoolsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate StandbyVirtualMachinePoolResourceOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]StandbyVirtualMachinePoolResource, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbysubscription.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbysubscription.go new file mode 100644 index 00000000000..18859d5e0e2 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_listbysubscription.go @@ -0,0 +1,106 @@ +package standbyvirtualmachinepools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StandbyVirtualMachinePoolResource +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []StandbyVirtualMachinePoolResource +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c StandbyVirtualMachinePoolsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]StandbyVirtualMachinePoolResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySubscriptionComplete retrieves all the results into a single object +func (c StandbyVirtualMachinePoolsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, StandbyVirtualMachinePoolResourceOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StandbyVirtualMachinePoolsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate StandbyVirtualMachinePoolResourceOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]StandbyVirtualMachinePoolResource, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_update.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_update.go new file mode 100644 index 00000000000..b4d470798de --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/method_update.go @@ -0,0 +1,57 @@ +package standbyvirtualmachinepools + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StandbyVirtualMachinePoolResource +} + +// Update ... +func (c StandbyVirtualMachinePoolsClient) Update(ctx context.Context, id StandbyVirtualMachinePoolId, input StandbyVirtualMachinePoolResourceUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model StandbyVirtualMachinePoolResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolelasticityprofile.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolelasticityprofile.go new file mode 100644 index 00000000000..9214ec79b5f --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolelasticityprofile.go @@ -0,0 +1,9 @@ +package standbyvirtualmachinepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolElasticityProfile struct { + MaxReadyCapacity int64 `json:"maxReadyCapacity"` + MinReadyCapacity *int64 `json:"minReadyCapacity,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresource.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresource.go new file mode 100644 index 00000000000..f7126f48397 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresource.go @@ -0,0 +1,18 @@ +package standbyvirtualmachinepools + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolResource struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *StandbyVirtualMachinePoolResourceProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceproperties.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceproperties.go new file mode 100644 index 00000000000..4ae4ea48f7e --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceproperties.go @@ -0,0 +1,11 @@ +package standbyvirtualmachinepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolResourceProperties struct { + AttachedVirtualMachineScaleSetId *string `json:"attachedVirtualMachineScaleSetId,omitempty"` + ElasticityProfile *StandbyVirtualMachinePoolElasticityProfile `json:"elasticityProfile,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + VirtualMachineState VirtualMachineState `json:"virtualMachineState"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdate.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdate.go new file mode 100644 index 00000000000..dc5d7c116c9 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdate.go @@ -0,0 +1,9 @@ +package standbyvirtualmachinepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolResourceUpdate struct { + Properties *StandbyVirtualMachinePoolResourceUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdateproperties.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdateproperties.go new file mode 100644 index 00000000000..1f535491838 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/model_standbyvirtualmachinepoolresourceupdateproperties.go @@ -0,0 +1,10 @@ +package standbyvirtualmachinepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolResourceUpdateProperties struct { + AttachedVirtualMachineScaleSetId *string `json:"attachedVirtualMachineScaleSetId,omitempty"` + ElasticityProfile *StandbyVirtualMachinePoolElasticityProfile `json:"elasticityProfile,omitempty"` + VirtualMachineState *VirtualMachineState `json:"virtualMachineState,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/predicates.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/predicates.go new file mode 100644 index 00000000000..3ada540e573 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/predicates.go @@ -0,0 +1,32 @@ +package standbyvirtualmachinepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinePoolResourceOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p StandbyVirtualMachinePoolResourceOperationPredicate) Matches(input StandbyVirtualMachinePoolResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/version.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/version.go new file mode 100644 index 00000000000..9079509eac0 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachinepools/version.go @@ -0,0 +1,10 @@ +package standbyvirtualmachinepools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/standbyvirtualmachinepools/2024-03-01" +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/README.md b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/README.md new file mode 100644 index 00000000000..eafc6716312 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachines` Documentation + +The `standbyvirtualmachines` SDK allows for interaction with Azure Resource Manager `standbypool` (API Version `2024-03-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/standbypool/2024-03-01/standbyvirtualmachines" +``` + + +### Client Initialization + +```go +client := standbyvirtualmachines.NewStandbyVirtualMachinesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `StandbyVirtualMachinesClient.Get` + +```go +ctx := context.TODO() +id := standbyvirtualmachines.NewStandbyVirtualMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName", "standbyVirtualMachineName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `StandbyVirtualMachinesClient.ListByStandbyVirtualMachinePoolResource` + +```go +ctx := context.TODO() +id := standbyvirtualmachines.NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName") + +// alternatively `client.ListByStandbyVirtualMachinePoolResource(ctx, id)` can be used to do batched pagination +items, err := client.ListByStandbyVirtualMachinePoolResourceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/client.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/client.go new file mode 100644 index 00000000000..967c173b53e --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/client.go @@ -0,0 +1,26 @@ +package standbyvirtualmachines + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachinesClient struct { + Client *resourcemanager.Client +} + +func NewStandbyVirtualMachinesClientWithBaseURI(sdkApi sdkEnv.Api) (*StandbyVirtualMachinesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "standbyvirtualmachines", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating StandbyVirtualMachinesClient: %+v", err) + } + + return &StandbyVirtualMachinesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/constants.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/constants.go new file mode 100644 index 00000000000..6f95f23b354 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/constants.go @@ -0,0 +1,57 @@ +package standbyvirtualmachines + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateSucceeded), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "succeeded": ProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachine.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachine.go new file mode 100644 index 00000000000..0efe13707ad --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachine.go @@ -0,0 +1,139 @@ +package standbyvirtualmachines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&StandbyVirtualMachineId{}) +} + +var _ resourceids.ResourceId = &StandbyVirtualMachineId{} + +// StandbyVirtualMachineId is a struct representing the Resource ID for a Standby Virtual Machine +type StandbyVirtualMachineId struct { + SubscriptionId string + ResourceGroupName string + StandbyVirtualMachinePoolName string + StandbyVirtualMachineName string +} + +// NewStandbyVirtualMachineID returns a new StandbyVirtualMachineId struct +func NewStandbyVirtualMachineID(subscriptionId string, resourceGroupName string, standbyVirtualMachinePoolName string, standbyVirtualMachineName string) StandbyVirtualMachineId { + return StandbyVirtualMachineId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + StandbyVirtualMachinePoolName: standbyVirtualMachinePoolName, + StandbyVirtualMachineName: standbyVirtualMachineName, + } +} + +// ParseStandbyVirtualMachineID parses 'input' into a StandbyVirtualMachineId +func ParseStandbyVirtualMachineID(input string) (*StandbyVirtualMachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyVirtualMachineId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyVirtualMachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseStandbyVirtualMachineIDInsensitively parses 'input' case-insensitively into a StandbyVirtualMachineId +// note: this method should only be used for API response data and not user input +func ParseStandbyVirtualMachineIDInsensitively(input string) (*StandbyVirtualMachineId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyVirtualMachineId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyVirtualMachineId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *StandbyVirtualMachineId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.StandbyVirtualMachinePoolName, ok = input.Parsed["standbyVirtualMachinePoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "standbyVirtualMachinePoolName", input) + } + + if id.StandbyVirtualMachineName, ok = input.Parsed["standbyVirtualMachineName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "standbyVirtualMachineName", input) + } + + return nil +} + +// ValidateStandbyVirtualMachineID checks that 'input' can be parsed as a Standby Virtual Machine ID +func ValidateStandbyVirtualMachineID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseStandbyVirtualMachineID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Standby Virtual Machine ID +func (id StandbyVirtualMachineId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/%s/standbyVirtualMachines/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.StandbyVirtualMachinePoolName, id.StandbyVirtualMachineName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Standby Virtual Machine ID +func (id StandbyVirtualMachineId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftStandbyPool", "Microsoft.StandbyPool", "Microsoft.StandbyPool"), + resourceids.StaticSegment("staticStandbyVirtualMachinePools", "standbyVirtualMachinePools", "standbyVirtualMachinePools"), + resourceids.UserSpecifiedSegment("standbyVirtualMachinePoolName", "standbyVirtualMachinePoolName"), + resourceids.StaticSegment("staticStandbyVirtualMachines", "standbyVirtualMachines", "standbyVirtualMachines"), + resourceids.UserSpecifiedSegment("standbyVirtualMachineName", "standbyVirtualMachineName"), + } +} + +// String returns a human-readable description of this Standby Virtual Machine ID +func (id StandbyVirtualMachineId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Standby Virtual Machine Pool Name: %q", id.StandbyVirtualMachinePoolName), + fmt.Sprintf("Standby Virtual Machine Name: %q", id.StandbyVirtualMachineName), + } + return fmt.Sprintf("Standby Virtual Machine (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachine_test.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachine_test.go new file mode 100644 index 00000000000..8f0a3df7e70 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachine_test.go @@ -0,0 +1,327 @@ +package standbyvirtualmachines + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &StandbyVirtualMachineId{} + +func TestNewStandbyVirtualMachineID(t *testing.T) { + id := NewStandbyVirtualMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName", "standbyVirtualMachineName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.StandbyVirtualMachinePoolName != "standbyVirtualMachinePoolName" { + t.Fatalf("Expected %q but got %q for Segment 'StandbyVirtualMachinePoolName'", id.StandbyVirtualMachinePoolName, "standbyVirtualMachinePoolName") + } + + if id.StandbyVirtualMachineName != "standbyVirtualMachineName" { + t.Fatalf("Expected %q but got %q for Segment 'StandbyVirtualMachineName'", id.StandbyVirtualMachineName, "standbyVirtualMachineName") + } +} + +func TestFormatStandbyVirtualMachineID(t *testing.T) { + actual := NewStandbyVirtualMachineID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName", "standbyVirtualMachineName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/standbyVirtualMachines/standbyVirtualMachineName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseStandbyVirtualMachineID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyVirtualMachineId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/standbyVirtualMachines", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/standbyVirtualMachines/standbyVirtualMachineName", + Expected: &StandbyVirtualMachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyVirtualMachinePoolName: "standbyVirtualMachinePoolName", + StandbyVirtualMachineName: "standbyVirtualMachineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/standbyVirtualMachines/standbyVirtualMachineName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyVirtualMachineID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyVirtualMachinePoolName != v.Expected.StandbyVirtualMachinePoolName { + t.Fatalf("Expected %q but got %q for StandbyVirtualMachinePoolName", v.Expected.StandbyVirtualMachinePoolName, actual.StandbyVirtualMachinePoolName) + } + + if actual.StandbyVirtualMachineName != v.Expected.StandbyVirtualMachineName { + t.Fatalf("Expected %q but got %q for StandbyVirtualMachineName", v.Expected.StandbyVirtualMachineName, actual.StandbyVirtualMachineName) + } + + } +} + +func TestParseStandbyVirtualMachineIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyVirtualMachineId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/standbyVirtualMachines", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe/sTaNdByViRtUaLmAcHiNeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/standbyVirtualMachines/standbyVirtualMachineName", + Expected: &StandbyVirtualMachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyVirtualMachinePoolName: "standbyVirtualMachinePoolName", + StandbyVirtualMachineName: "standbyVirtualMachineName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/standbyVirtualMachines/standbyVirtualMachineName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe/sTaNdByViRtUaLmAcHiNeS/sTaNdByViRtUaLmAcHiNeNaMe", + Expected: &StandbyVirtualMachineId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + StandbyVirtualMachinePoolName: "sTaNdByViRtUaLmAcHiNePoOlNaMe", + StandbyVirtualMachineName: "sTaNdByViRtUaLmAcHiNeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe/sTaNdByViRtUaLmAcHiNeS/sTaNdByViRtUaLmAcHiNeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyVirtualMachineIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyVirtualMachinePoolName != v.Expected.StandbyVirtualMachinePoolName { + t.Fatalf("Expected %q but got %q for StandbyVirtualMachinePoolName", v.Expected.StandbyVirtualMachinePoolName, actual.StandbyVirtualMachinePoolName) + } + + if actual.StandbyVirtualMachineName != v.Expected.StandbyVirtualMachineName { + t.Fatalf("Expected %q but got %q for StandbyVirtualMachineName", v.Expected.StandbyVirtualMachineName, actual.StandbyVirtualMachineName) + } + + } +} + +func TestSegmentsForStandbyVirtualMachineId(t *testing.T) { + segments := StandbyVirtualMachineId{}.Segments() + if len(segments) == 0 { + t.Fatalf("StandbyVirtualMachineId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachinepool.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachinepool.go new file mode 100644 index 00000000000..c10ec28e374 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachinepool.go @@ -0,0 +1,130 @@ +package standbyvirtualmachines + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&StandbyVirtualMachinePoolId{}) +} + +var _ resourceids.ResourceId = &StandbyVirtualMachinePoolId{} + +// StandbyVirtualMachinePoolId is a struct representing the Resource ID for a Standby Virtual Machine Pool +type StandbyVirtualMachinePoolId struct { + SubscriptionId string + ResourceGroupName string + StandbyVirtualMachinePoolName string +} + +// NewStandbyVirtualMachinePoolID returns a new StandbyVirtualMachinePoolId struct +func NewStandbyVirtualMachinePoolID(subscriptionId string, resourceGroupName string, standbyVirtualMachinePoolName string) StandbyVirtualMachinePoolId { + return StandbyVirtualMachinePoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + StandbyVirtualMachinePoolName: standbyVirtualMachinePoolName, + } +} + +// ParseStandbyVirtualMachinePoolID parses 'input' into a StandbyVirtualMachinePoolId +func ParseStandbyVirtualMachinePoolID(input string) (*StandbyVirtualMachinePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyVirtualMachinePoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyVirtualMachinePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseStandbyVirtualMachinePoolIDInsensitively parses 'input' case-insensitively into a StandbyVirtualMachinePoolId +// note: this method should only be used for API response data and not user input +func ParseStandbyVirtualMachinePoolIDInsensitively(input string) (*StandbyVirtualMachinePoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&StandbyVirtualMachinePoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := StandbyVirtualMachinePoolId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *StandbyVirtualMachinePoolId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.StandbyVirtualMachinePoolName, ok = input.Parsed["standbyVirtualMachinePoolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "standbyVirtualMachinePoolName", input) + } + + return nil +} + +// ValidateStandbyVirtualMachinePoolID checks that 'input' can be parsed as a Standby Virtual Machine Pool ID +func ValidateStandbyVirtualMachinePoolID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseStandbyVirtualMachinePoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Standby Virtual Machine Pool ID +func (id StandbyVirtualMachinePoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.StandbyVirtualMachinePoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Standby Virtual Machine Pool ID +func (id StandbyVirtualMachinePoolId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftStandbyPool", "Microsoft.StandbyPool", "Microsoft.StandbyPool"), + resourceids.StaticSegment("staticStandbyVirtualMachinePools", "standbyVirtualMachinePools", "standbyVirtualMachinePools"), + resourceids.UserSpecifiedSegment("standbyVirtualMachinePoolName", "standbyVirtualMachinePoolName"), + } +} + +// String returns a human-readable description of this Standby Virtual Machine Pool ID +func (id StandbyVirtualMachinePoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Standby Virtual Machine Pool Name: %q", id.StandbyVirtualMachinePoolName), + } + return fmt.Sprintf("Standby Virtual Machine Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachinepool_test.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachinepool_test.go new file mode 100644 index 00000000000..96a20bcb405 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/id_standbyvirtualmachinepool_test.go @@ -0,0 +1,282 @@ +package standbyvirtualmachines + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &StandbyVirtualMachinePoolId{} + +func TestNewStandbyVirtualMachinePoolID(t *testing.T) { + id := NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.StandbyVirtualMachinePoolName != "standbyVirtualMachinePoolName" { + t.Fatalf("Expected %q but got %q for Segment 'StandbyVirtualMachinePoolName'", id.StandbyVirtualMachinePoolName, "standbyVirtualMachinePoolName") + } +} + +func TestFormatStandbyVirtualMachinePoolID(t *testing.T) { + actual := NewStandbyVirtualMachinePoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "standbyVirtualMachinePoolName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseStandbyVirtualMachinePoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyVirtualMachinePoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName", + Expected: &StandbyVirtualMachinePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyVirtualMachinePoolName: "standbyVirtualMachinePoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyVirtualMachinePoolID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyVirtualMachinePoolName != v.Expected.StandbyVirtualMachinePoolName { + t.Fatalf("Expected %q but got %q for StandbyVirtualMachinePoolName", v.Expected.StandbyVirtualMachinePoolName, actual.StandbyVirtualMachinePoolName) + } + + } +} + +func TestParseStandbyVirtualMachinePoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *StandbyVirtualMachinePoolId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName", + Expected: &StandbyVirtualMachinePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + StandbyVirtualMachinePoolName: "standbyVirtualMachinePoolName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.StandbyPool/standbyVirtualMachinePools/standbyVirtualMachinePoolName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe", + Expected: &StandbyVirtualMachinePoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + StandbyVirtualMachinePoolName: "sTaNdByViRtUaLmAcHiNePoOlNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sTaNdByPoOl/sTaNdByViRtUaLmAcHiNePoOlS/sTaNdByViRtUaLmAcHiNePoOlNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseStandbyVirtualMachinePoolIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.StandbyVirtualMachinePoolName != v.Expected.StandbyVirtualMachinePoolName { + t.Fatalf("Expected %q but got %q for StandbyVirtualMachinePoolName", v.Expected.StandbyVirtualMachinePoolName, actual.StandbyVirtualMachinePoolName) + } + + } +} + +func TestSegmentsForStandbyVirtualMachinePoolId(t *testing.T) { + segments := StandbyVirtualMachinePoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("StandbyVirtualMachinePoolId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/method_get.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/method_get.go new file mode 100644 index 00000000000..8a63a04d3a9 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/method_get.go @@ -0,0 +1,53 @@ +package standbyvirtualmachines + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *StandbyVirtualMachineResource +} + +// Get ... +func (c StandbyVirtualMachinesClient) Get(ctx context.Context, id StandbyVirtualMachineId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model StandbyVirtualMachineResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/method_listbystandbyvirtualmachinepoolresource.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/method_listbystandbyvirtualmachinepoolresource.go new file mode 100644 index 00000000000..d2b762a36fe --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/method_listbystandbyvirtualmachinepoolresource.go @@ -0,0 +1,105 @@ +package standbyvirtualmachines + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByStandbyVirtualMachinePoolResourceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]StandbyVirtualMachineResource +} + +type ListByStandbyVirtualMachinePoolResourceCompleteResult struct { + LatestHttpResponse *http.Response + Items []StandbyVirtualMachineResource +} + +type ListByStandbyVirtualMachinePoolResourceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByStandbyVirtualMachinePoolResourceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByStandbyVirtualMachinePoolResource ... +func (c StandbyVirtualMachinesClient) ListByStandbyVirtualMachinePoolResource(ctx context.Context, id StandbyVirtualMachinePoolId) (result ListByStandbyVirtualMachinePoolResourceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByStandbyVirtualMachinePoolResourceCustomPager{}, + Path: fmt.Sprintf("%s/standbyVirtualMachines", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]StandbyVirtualMachineResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByStandbyVirtualMachinePoolResourceComplete retrieves all the results into a single object +func (c StandbyVirtualMachinesClient) ListByStandbyVirtualMachinePoolResourceComplete(ctx context.Context, id StandbyVirtualMachinePoolId) (ListByStandbyVirtualMachinePoolResourceCompleteResult, error) { + return c.ListByStandbyVirtualMachinePoolResourceCompleteMatchingPredicate(ctx, id, StandbyVirtualMachineResourceOperationPredicate{}) +} + +// ListByStandbyVirtualMachinePoolResourceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c StandbyVirtualMachinesClient) ListByStandbyVirtualMachinePoolResourceCompleteMatchingPredicate(ctx context.Context, id StandbyVirtualMachinePoolId, predicate StandbyVirtualMachineResourceOperationPredicate) (result ListByStandbyVirtualMachinePoolResourceCompleteResult, err error) { + items := make([]StandbyVirtualMachineResource, 0) + + resp, err := c.ListByStandbyVirtualMachinePoolResource(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByStandbyVirtualMachinePoolResourceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/model_standbyvirtualmachineresource.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/model_standbyvirtualmachineresource.go new file mode 100644 index 00000000000..e7d0e76d0ff --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/model_standbyvirtualmachineresource.go @@ -0,0 +1,16 @@ +package standbyvirtualmachines + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachineResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *StandbyVirtualMachineResourceProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/model_standbyvirtualmachineresourceproperties.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/model_standbyvirtualmachineresourceproperties.go new file mode 100644 index 00000000000..48492a9e5b6 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/model_standbyvirtualmachineresourceproperties.go @@ -0,0 +1,9 @@ +package standbyvirtualmachines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachineResourceProperties struct { + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + VirtualMachineResourceId string `json:"virtualMachineResourceId"` +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/predicates.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/predicates.go new file mode 100644 index 00000000000..c067a7dc6c3 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/predicates.go @@ -0,0 +1,27 @@ +package standbyvirtualmachines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StandbyVirtualMachineResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p StandbyVirtualMachineResourceOperationPredicate) Matches(input StandbyVirtualMachineResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/version.go b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/version.go new file mode 100644 index 00000000000..337281f0f33 --- /dev/null +++ b/resource-manager/standbypool/2024-03-01/standbyvirtualmachines/version.go @@ -0,0 +1,10 @@ +package standbyvirtualmachines + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-03-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/standbyvirtualmachines/2024-03-01" +}