From fd1fe76f52d1acac3f5b8f0389cfc22ae039a9bb Mon Sep 17 00:00:00 2001 From: hc-github-team-tf-azure <> Date: Tue, 2 Apr 2024 06:30:12 +0000 Subject: [PATCH] Updating based on 4235b69a --- .../attachednetworkconnections/README.md | 54 +++ .../attachednetworkconnections/client.go | 26 ++ .../attachednetworkconnections/constants.go | 187 ++++++++ .../id_devcenter.go | 125 ++++++ .../id_devcenter_test.go | 282 ++++++++++++ .../attachednetworkconnections/id_project.go | 125 ++++++ .../id_project_test.go | 282 ++++++++++++ .../method_attachednetworkslistbydevcenter.go | 119 +++++ .../method_attachednetworkslistbyproject.go | 119 +++++ .../model_attachednetworkconnection.go | 16 + ...del_attachednetworkconnectionproperties.go | 12 + .../attachednetworkconnections/predicates.go | 27 ++ .../attachednetworkconnections/version.go | 12 + .../devcenter/2024-02-01/catalogs/README.md | 139 ++++++ .../devcenter/2024-02-01/catalogs/client.go | 26 ++ .../2024-02-01/catalogs/constants.go | 260 +++++++++++ .../2024-02-01/catalogs/id_devcenter.go | 125 ++++++ .../2024-02-01/catalogs/id_devcenter_test.go | 282 ++++++++++++ .../catalogs/id_devcentercatalog.go | 134 ++++++ .../catalogs/id_devcentercatalog_test.go | 327 ++++++++++++++ .../2024-02-01/catalogs/method_connect.go | 69 +++ .../catalogs/method_createorupdate.go | 75 ++++ .../2024-02-01/catalogs/method_delete.go | 70 +++ .../2024-02-01/catalogs/method_get.go | 54 +++ .../catalogs/method_getsyncerrordetails.go | 55 +++ .../catalogs/method_listbydevcenter.go | 119 +++++ .../2024-02-01/catalogs/method_sync.go | 69 +++ .../2024-02-01/catalogs/method_update.go | 75 ++++ .../2024-02-01/catalogs/model_catalog.go | 16 + .../catalogs/model_catalogconflicterror.go | 9 + .../catalogs/model_catalogerrordetails.go | 9 + .../catalogs/model_catalogproperties.go | 47 ++ .../catalogs/model_catalogsyncerror.go | 9 + .../catalogs/model_catalogupdate.go | 8 + .../catalogs/model_catalogupdateproperties.go | 11 + .../2024-02-01/catalogs/model_gitcatalog.go | 11 + .../catalogs/model_syncerrordetails.go | 10 + .../2024-02-01/catalogs/model_syncstats.go | 14 + .../2024-02-01/catalogs/predicates.go | 27 ++ .../devcenter/2024-02-01/catalogs/version.go | 12 + .../checknameavailability/README.md | 42 ++ .../checknameavailability/client.go | 26 ++ .../checknameavailability/constants.go | 51 +++ .../checknameavailability/method_execute.go | 60 +++ .../model_checknameavailabilityrequest.go | 9 + .../model_checknameavailabilityresponse.go | 10 + .../checknameavailability/version.go | 12 + .../checkscopednameavailability/README.md | 42 ++ .../checkscopednameavailability/client.go | 26 ++ .../checkscopednameavailability/constants.go | 51 +++ .../method_execute.go | 60 +++ .../model_checknameavailabilityresponse.go | 10 + ...odel_checkscopednameavailabilityrequest.go | 10 + .../checkscopednameavailability/version.go | 12 + .../devcenter/2024-02-01/client.go | 190 ++++++++ .../2024-02-01/devboxdefinitions/README.md | 132 ++++++ .../2024-02-01/devboxdefinitions/client.go | 26 ++ .../2024-02-01/devboxdefinitions/constants.go | 278 ++++++++++++ .../devboxdefinitions/id_devboxdefinition.go | 134 ++++++ .../id_devboxdefinition_test.go | 327 ++++++++++++++ .../devboxdefinitions/id_devcenter.go | 125 ++++++ .../devboxdefinitions/id_devcenter_test.go | 282 ++++++++++++ .../id_devcenterdevboxdefinition.go | 134 ++++++ .../id_devcenterdevboxdefinition_test.go | 327 ++++++++++++++ .../devboxdefinitions/id_project.go | 125 ++++++ .../devboxdefinitions/id_project_test.go | 282 ++++++++++++ .../method_createorupdate.go | 75 ++++ .../devboxdefinitions/method_delete.go | 70 +++ .../devboxdefinitions/method_get.go | 54 +++ .../devboxdefinitions/method_getbyproject.go | 54 +++ .../method_listbydevcenter.go | 91 ++++ .../devboxdefinitions/method_listbyproject.go | 91 ++++ .../devboxdefinitions/method_update.go | 75 ++++ .../model_devboxdefinition.go | 18 + .../model_devboxdefinitionproperties.go | 16 + .../model_devboxdefinitionupdate.go | 10 + .../model_devboxdefinitionupdateproperties.go | 11 + .../devboxdefinitions/model_imagereference.go | 9 + .../model_imagevalidationerrordetails.go | 9 + .../2024-02-01/devboxdefinitions/model_sku.go | 12 + .../devboxdefinitions/predicates.go | 32 ++ .../2024-02-01/devboxdefinitions/version.go | 12 + .../devcenter/2024-02-01/devcenters/README.md | 117 +++++ .../devcenter/2024-02-01/devcenters/client.go | 26 ++ .../2024-02-01/devcenters/constants.go | 178 ++++++++ .../2024-02-01/devcenters/id_devcenter.go | 125 ++++++ .../devcenters/id_devcenter_test.go | 282 ++++++++++++ .../devcenters/method_createorupdate.go | 75 ++++ .../2024-02-01/devcenters/method_delete.go | 70 +++ .../2024-02-01/devcenters/method_get.go | 54 +++ .../devcenters/method_listbyresourcegroup.go | 120 +++++ .../devcenters/method_listbysubscription.go | 120 +++++ .../2024-02-01/devcenters/method_update.go | 75 ++++ .../model_customermanagedkeyencryption.go | 9 + ...edkeyencryptionkeyencryptionkeyidentity.go | 10 + .../2024-02-01/devcenters/model_devcenter.go | 20 + .../model_devcenterprojectcatalogsettings.go | 8 + .../devcenters/model_devcenterproperties.go | 12 + .../devcenters/model_devcenterupdate.go | 15 + .../model_devcenterupdateproperties.go | 10 + .../2024-02-01/devcenters/model_encryption.go | 8 + .../2024-02-01/devcenters/predicates.go | 32 ++ .../2024-02-01/devcenters/version.go | 12 + .../environmentdefinitions/README.md | 118 +++++ .../environmentdefinitions/client.go | 26 ++ .../environmentdefinitions/constants.go | 110 +++++ .../environmentdefinitions/id_catalog.go | 134 ++++++ .../environmentdefinitions/id_catalog_test.go | 327 ++++++++++++++ .../id_catalogenvironmentdefinition.go | 143 ++++++ .../id_catalogenvironmentdefinition_test.go | 372 ++++++++++++++++ .../id_devcentercatalog.go | 134 ++++++ .../id_devcentercatalog_test.go | 327 ++++++++++++++ .../id_environmentdefinition.go | 143 ++++++ .../id_environmentdefinition_test.go | 372 ++++++++++++++++ .../method_environmentdefinitionsget.go | 54 +++ ...vironmentdefinitionsgetbyprojectcatalog.go | 54 +++ ...d_environmentdefinitionsgeterrordetails.go | 55 +++ ...hod_environmentdefinitionslistbycatalog.go | 119 +++++ ...ironmentdefinitionslistbyprojectcatalog.go | 91 ++++ ...ogenvironmentdefinitionsgeterrordetails.go | 55 +++ .../model_catalogerrordetails.go | 9 + ...l_catalogresourcevalidationerrordetails.go | 8 + .../model_environmentdefinition.go | 16 + .../model_environmentdefinitionparameter.go | 13 + .../model_environmentdefinitionproperties.go | 11 + .../environmentdefinitions/predicates.go | 27 ++ .../environmentdefinitions/version.go | 12 + .../2024-02-01/environmenttypes/README.md | 235 ++++++++++ .../2024-02-01/environmenttypes/client.go | 26 ++ .../2024-02-01/environmenttypes/constants.go | 134 ++++++ .../id_allowedenvironmenttype.go | 134 ++++++ .../id_allowedenvironmenttype_test.go | 327 ++++++++++++++ .../environmenttypes/id_devcenter.go | 125 ++++++ .../environmenttypes/id_devcenter_test.go | 282 ++++++++++++ .../id_devcenterenvironmenttype.go | 134 ++++++ .../id_devcenterenvironmenttype_test.go | 327 ++++++++++++++ .../environmenttypes/id_environmenttype.go | 134 ++++++ .../id_environmenttype_test.go | 327 ++++++++++++++ .../2024-02-01/environmenttypes/id_project.go | 125 ++++++ .../environmenttypes/id_project_test.go | 282 ++++++++++++ .../method_environmenttypescreateorupdate.go | 59 +++ .../method_environmenttypesdelete.go | 47 ++ .../method_environmenttypesget.go | 54 +++ .../method_environmenttypeslistbydevcenter.go | 119 +++++ .../method_environmenttypesupdate.go | 58 +++ ...ethod_projectallowedenvironmenttypesget.go | 54 +++ ...thod_projectallowedenvironmenttypeslist.go | 119 +++++ ...d_projectenvironmenttypescreateorupdate.go | 59 +++ .../method_projectenvironmenttypesdelete.go | 47 ++ .../method_projectenvironmenttypesget.go | 54 +++ .../method_projectenvironmenttypeslist.go | 119 +++++ .../method_projectenvironmenttypesupdate.go | 58 +++ .../model_allowedenvironmenttype.go | 16 + .../model_allowedenvironmenttypeproperties.go | 9 + .../environmenttypes/model_environmentrole.go | 9 + .../environmenttypes/model_environmenttype.go | 17 + .../model_environmenttypeproperties.go | 9 + .../model_environmenttypeupdate.go | 9 + .../model_environmenttypeupdateproperties.go | 8 + .../model_projectenvironmenttype.go | 20 + .../model_projectenvironmenttypeproperties.go | 14 + .../model_projectenvironmenttypeupdate.go | 14 + ..._projectenvironmenttypeupdateproperties.go | 12 + ...peupdatepropertiescreatorroleassignment.go | 8 + .../model_userroleassignment.go | 8 + .../2024-02-01/environmenttypes/predicates.go | 78 ++++ .../2024-02-01/environmenttypes/version.go | 12 + .../devcenter/2024-02-01/galleries/README.md | 82 ++++ .../devcenter/2024-02-01/galleries/client.go | 26 ++ .../2024-02-01/galleries/constants.go | 93 ++++ .../2024-02-01/galleries/id_devcenter.go | 125 ++++++ .../2024-02-01/galleries/id_devcenter_test.go | 282 ++++++++++++ .../2024-02-01/galleries/id_gallery.go | 134 ++++++ .../2024-02-01/galleries/id_gallery_test.go | 327 ++++++++++++++ .../galleries/method_createorupdate.go | 75 ++++ .../2024-02-01/galleries/method_delete.go | 70 +++ .../2024-02-01/galleries/method_get.go | 54 +++ .../galleries/method_listbydevcenter.go | 119 +++++ .../2024-02-01/galleries/model_gallery.go | 16 + .../galleries/model_galleryproperties.go | 9 + .../2024-02-01/galleries/predicates.go | 27 ++ .../devcenter/2024-02-01/galleries/version.go | 12 + .../devcenter/2024-02-01/images/README.md | 70 +++ .../devcenter/2024-02-01/images/client.go | 26 ++ .../devcenter/2024-02-01/images/constants.go | 134 ++++++ .../2024-02-01/images/id_devcenter.go | 125 ++++++ .../2024-02-01/images/id_devcenter_test.go | 282 ++++++++++++ .../devcenter/2024-02-01/images/id_gallery.go | 134 ++++++ .../2024-02-01/images/id_gallery_test.go | 327 ++++++++++++++ .../devcenter/2024-02-01/images/id_image.go | 143 ++++++ .../2024-02-01/images/id_image_test.go | 372 ++++++++++++++++ .../devcenter/2024-02-01/images/method_get.go | 54 +++ .../images/method_listbydevcenter.go | 119 +++++ .../2024-02-01/images/method_listbygallery.go | 119 +++++ .../2024-02-01/images/model_image.go | 16 + .../images/model_imageproperties.go | 14 + .../model_recommendedmachineconfiguration.go | 9 + .../2024-02-01/images/model_resourcerange.go | 9 + .../devcenter/2024-02-01/images/predicates.go | 27 ++ .../devcenter/2024-02-01/images/version.go | 12 + .../2024-02-01/imageversions/README.md | 53 +++ .../2024-02-01/imageversions/client.go | 26 ++ .../2024-02-01/imageversions/constants.go | 93 ++++ .../2024-02-01/imageversions/id_image.go | 143 ++++++ .../2024-02-01/imageversions/id_image_test.go | 372 ++++++++++++++++ .../2024-02-01/imageversions/id_version.go | 152 +++++++ .../imageversions/id_version_test.go | 417 ++++++++++++++++++ .../2024-02-01/imageversions/method_get.go | 54 +++ .../imageversions/method_listbyimage.go | 91 ++++ .../imageversions/model_imageversion.go | 16 + .../model_imageversionproperties.go | 30 ++ .../2024-02-01/imageversions/predicates.go | 27 ++ .../2024-02-01/imageversions/version.go | 12 + .../2024-02-01/networkconnection/README.md | 49 ++ .../2024-02-01/networkconnection/client.go | 26 ++ .../networkconnection/id_networkconnection.go | 125 ++++++ .../id_networkconnection_test.go | 282 ++++++++++++ ...istoutboundnetworkdependenciesendpoints.go | 91 ++++ .../method_runhealthchecks.go | 69 +++ .../model_endpointdependency.go | 10 + .../networkconnection/model_endpointdetail.go | 8 + .../model_outboundenvironmentendpoint.go | 9 + .../networkconnection/predicates.go | 17 + .../2024-02-01/networkconnection/version.go | 12 + .../2024-02-01/networkconnections/README.md | 150 +++++++ .../2024-02-01/networkconnections/client.go | 26 ++ .../networkconnections/constants.go | 187 ++++++++ .../id_networkconnection.go | 125 ++++++ .../id_networkconnection_test.go | 282 ++++++++++++ .../method_createorupdate.go | 75 ++++ .../networkconnections/method_delete.go | 70 +++ .../networkconnections/method_get.go | 54 +++ .../method_gethealthdetails.go | 55 +++ .../method_listbyresourcegroup.go | 92 ++++ .../method_listbysubscription.go | 92 ++++ .../method_listhealthdetails.go | 91 ++++ .../networkconnections/method_update.go | 75 ++++ .../networkconnections/model_healthcheck.go | 44 ++ .../model_healthcheckstatusdetails.go | 16 + ...odel_healthcheckstatusdetailsproperties.go | 40 ++ .../model_networkconnection.go | 18 + .../model_networkconnectionupdate.go | 10 + ...model_networkconnectionupdateproperties.go | 12 + .../model_networkproperties.go | 16 + .../networkconnections/predicates.go | 55 +++ .../2024-02-01/networkconnections/version.go | 12 + .../devcenter/2024-02-01/pools/README.md | 111 +++++ .../devcenter/2024-02-01/pools/client.go | 26 ++ .../devcenter/2024-02-01/pools/constants.go | 345 +++++++++++++++ .../devcenter/2024-02-01/pools/id_pool.go | 134 ++++++ .../2024-02-01/pools/id_pool_test.go | 327 ++++++++++++++ .../devcenter/2024-02-01/pools/id_project.go | 125 ++++++ .../2024-02-01/pools/id_project_test.go | 282 ++++++++++++ .../2024-02-01/pools/method_createorupdate.go | 75 ++++ .../2024-02-01/pools/method_delete.go | 70 +++ .../devcenter/2024-02-01/pools/method_get.go | 54 +++ .../2024-02-01/pools/method_listbyproject.go | 91 ++++ .../pools/method_runhealthchecks.go | 69 +++ .../2024-02-01/pools/method_update.go | 75 ++++ .../pools/model_healthstatusdetail.go | 9 + .../devcenter/2024-02-01/pools/model_pool.go | 18 + .../2024-02-01/pools/model_poolproperties.go | 20 + .../2024-02-01/pools/model_poolupdate.go | 10 + .../pools/model_poolupdateproperties.go | 16 + .../model_stopondisconnectconfiguration.go | 9 + .../devcenter/2024-02-01/pools/predicates.go | 32 ++ .../devcenter/2024-02-01/pools/version.go | 12 + .../2024-02-01/projectcatalogs/README.md | 139 ++++++ .../2024-02-01/projectcatalogs/client.go | 26 ++ .../2024-02-01/projectcatalogs/constants.go | 260 +++++++++++ .../2024-02-01/projectcatalogs/id_catalog.go | 134 ++++++ .../projectcatalogs/id_catalog_test.go | 327 ++++++++++++++ .../2024-02-01/projectcatalogs/id_project.go | 125 ++++++ .../projectcatalogs/id_project_test.go | 282 ++++++++++++ .../projectcatalogs/method_connect.go | 69 +++ .../projectcatalogs/method_createorupdate.go | 75 ++++ .../projectcatalogs/method_delete.go | 70 +++ .../2024-02-01/projectcatalogs/method_get.go | 54 +++ .../method_getsyncerrordetails.go | 55 +++ .../2024-02-01/projectcatalogs/method_list.go | 119 +++++ .../projectcatalogs/method_patch.go | 75 ++++ .../2024-02-01/projectcatalogs/method_sync.go | 69 +++ .../projectcatalogs/model_catalog.go | 16 + .../model_catalogconflicterror.go | 9 + .../model_catalogerrordetails.go | 9 + .../model_catalogproperties.go | 47 ++ .../projectcatalogs/model_catalogsyncerror.go | 9 + .../projectcatalogs/model_catalogupdate.go | 8 + .../model_catalogupdateproperties.go | 11 + .../projectcatalogs/model_gitcatalog.go | 11 + .../projectcatalogs/model_syncerrordetails.go | 10 + .../projectcatalogs/model_syncstats.go | 14 + .../2024-02-01/projectcatalogs/predicates.go | 27 ++ .../2024-02-01/projectcatalogs/version.go | 12 + .../devcenter/2024-02-01/projects/README.md | 117 +++++ .../devcenter/2024-02-01/projects/client.go | 26 ++ .../2024-02-01/projects/constants.go | 131 ++++++ .../2024-02-01/projects/id_project.go | 125 ++++++ .../2024-02-01/projects/id_project_test.go | 282 ++++++++++++ .../projects/method_createorupdate.go | 75 ++++ .../2024-02-01/projects/method_delete.go | 70 +++ .../2024-02-01/projects/method_get.go | 54 +++ .../projects/method_listbyresourcegroup.go | 120 +++++ .../projects/method_listbysubscription.go | 120 +++++ .../2024-02-01/projects/method_update.go | 75 ++++ .../2024-02-01/projects/model_project.go | 20 + .../projects/model_projectcatalogsettings.go | 8 + .../projects/model_projectproperties.go | 14 + .../projects/model_projectupdate.go | 15 + .../projects/model_projectupdateproperties.go | 12 + .../2024-02-01/projects/predicates.go | 32 ++ .../devcenter/2024-02-01/projects/version.go | 12 + .../devcenter/2024-02-01/schedules/README.md | 99 +++++ .../devcenter/2024-02-01/schedules/client.go | 26 ++ .../2024-02-01/schedules/constants.go | 210 +++++++++ .../devcenter/2024-02-01/schedules/id_pool.go | 134 ++++++ .../2024-02-01/schedules/id_pool_test.go | 327 ++++++++++++++ .../2024-02-01/schedules/id_schedule.go | 143 ++++++ .../2024-02-01/schedules/id_schedule_test.go | 372 ++++++++++++++++ .../schedules/method_createorupdate.go | 75 ++++ .../2024-02-01/schedules/method_delete.go | 70 +++ .../2024-02-01/schedules/method_get.go | 54 +++ .../2024-02-01/schedules/method_listbypool.go | 91 ++++ .../2024-02-01/schedules/method_update.go | 75 ++++ .../2024-02-01/schedules/model_schedule.go | 16 + .../schedules/model_scheduleproperties.go | 15 + .../schedules/model_scheduleupdate.go | 8 + .../model_scheduleupdateproperties.go | 14 + .../2024-02-01/schedules/predicates.go | 27 ++ .../devcenter/2024-02-01/schedules/version.go | 12 + .../devcenter/2024-02-01/skus/README.md | 38 ++ .../devcenter/2024-02-01/skus/client.go | 26 ++ .../devcenter/2024-02-01/skus/constants.go | 57 +++ .../skus/method_listbysubscription.go | 92 ++++ .../2024-02-01/skus/model_capability.go | 9 + .../2024-02-01/skus/model_devcentersku.go | 15 + .../devcenter/2024-02-01/skus/predicates.go | 37 ++ .../devcenter/2024-02-01/skus/version.go | 12 + .../devcenter/2024-02-01/usages/README.md | 37 ++ .../devcenter/2024-02-01/usages/client.go | 26 ++ .../devcenter/2024-02-01/usages/constants.go | 48 ++ .../2024-02-01/usages/id_location.go | 116 +++++ .../2024-02-01/usages/id_location_test.go | 237 ++++++++++ .../usages/method_listbylocation.go | 91 ++++ .../2024-02-01/usages/model_usage.go | 12 + .../2024-02-01/usages/model_usagename.go | 9 + .../devcenter/2024-02-01/usages/predicates.go | 27 ++ .../devcenter/2024-02-01/usages/version.go | 12 + 348 files changed, 29833 insertions(+) create mode 100644 resource-manager/devcenter/2024-02-01/attachednetworkconnections/README.md create mode 100644 resource-manager/devcenter/2024-02-01/attachednetworkconnections/client.go create mode 100644 resource-manager/devcenter/2024-02-01/attachednetworkconnections/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_devcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_devcenter_test.go create mode 100644 resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_project.go create mode 100644 resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_project_test.go create mode 100644 resource-manager/devcenter/2024-02-01/attachednetworkconnections/method_attachednetworkslistbydevcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/attachednetworkconnections/method_attachednetworkslistbyproject.go create mode 100644 resource-manager/devcenter/2024-02-01/attachednetworkconnections/model_attachednetworkconnection.go create mode 100644 resource-manager/devcenter/2024-02-01/attachednetworkconnections/model_attachednetworkconnectionproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/attachednetworkconnections/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/attachednetworkconnections/version.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/README.md create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/client.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/id_devcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/id_devcenter_test.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/id_devcentercatalog.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/id_devcentercatalog_test.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/method_connect.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/method_createorupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/method_delete.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/method_get.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/method_getsyncerrordetails.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/method_listbydevcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/method_sync.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/method_update.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/model_catalog.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/model_catalogconflicterror.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/model_catalogerrordetails.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/model_catalogproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/model_catalogsyncerror.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/model_catalogupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/model_catalogupdateproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/model_gitcatalog.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/model_syncerrordetails.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/model_syncstats.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/catalogs/version.go create mode 100644 resource-manager/devcenter/2024-02-01/checknameavailability/README.md create mode 100644 resource-manager/devcenter/2024-02-01/checknameavailability/client.go create mode 100644 resource-manager/devcenter/2024-02-01/checknameavailability/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/checknameavailability/method_execute.go create mode 100644 resource-manager/devcenter/2024-02-01/checknameavailability/model_checknameavailabilityrequest.go create mode 100644 resource-manager/devcenter/2024-02-01/checknameavailability/model_checknameavailabilityresponse.go create mode 100644 resource-manager/devcenter/2024-02-01/checknameavailability/version.go create mode 100644 resource-manager/devcenter/2024-02-01/checkscopednameavailability/README.md create mode 100644 resource-manager/devcenter/2024-02-01/checkscopednameavailability/client.go create mode 100644 resource-manager/devcenter/2024-02-01/checkscopednameavailability/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/checkscopednameavailability/method_execute.go create mode 100644 resource-manager/devcenter/2024-02-01/checkscopednameavailability/model_checknameavailabilityresponse.go create mode 100644 resource-manager/devcenter/2024-02-01/checkscopednameavailability/model_checkscopednameavailabilityrequest.go create mode 100644 resource-manager/devcenter/2024-02-01/checkscopednameavailability/version.go create mode 100644 resource-manager/devcenter/2024-02-01/client.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/README.md create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/client.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devboxdefinition.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devboxdefinition_test.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenter_test.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenterdevboxdefinition.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenterdevboxdefinition_test.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/id_project.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/id_project_test.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/method_createorupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/method_delete.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/method_get.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/method_getbyproject.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/method_listbydevcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/method_listbyproject.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/method_update.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinition.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinitionproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinitionupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinitionupdateproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/model_imagereference.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/model_imagevalidationerrordetails.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/model_sku.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/devboxdefinitions/version.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/README.md create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/client.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/id_devcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/id_devcenter_test.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/method_createorupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/method_delete.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/method_get.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/method_listbyresourcegroup.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/method_listbysubscription.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/method_update.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/model_customermanagedkeyencryption.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/model_customermanagedkeyencryptionkeyencryptionkeyidentity.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/model_devcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/model_devcenterprojectcatalogsettings.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/model_devcenterproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/model_devcenterupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/model_devcenterupdateproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/model_encryption.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/devcenters/version.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/README.md create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/client.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalog.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalog_test.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalogenvironmentdefinition.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalogenvironmentdefinition_test.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/id_devcentercatalog.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/id_devcentercatalog_test.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/id_environmentdefinition.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/id_environmentdefinition_test.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionsget.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionsgetbyprojectcatalog.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionsgeterrordetails.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionslistbycatalog.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionslistbyprojectcatalog.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/method_projectcatalogenvironmentdefinitionsgeterrordetails.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/model_catalogerrordetails.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/model_catalogresourcevalidationerrordetails.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/model_environmentdefinition.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/model_environmentdefinitionparameter.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/model_environmentdefinitionproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/environmentdefinitions/version.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/README.md create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/client.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/id_allowedenvironmenttype.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/id_allowedenvironmenttype_test.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenter_test.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenterenvironmenttype.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenterenvironmenttype_test.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/id_environmenttype.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/id_environmenttype_test.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/id_project.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/id_project_test.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypescreateorupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypesdelete.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypesget.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypeslistbydevcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypesupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/method_projectallowedenvironmenttypesget.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/method_projectallowedenvironmenttypeslist.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypescreateorupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypesdelete.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypesget.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypeslist.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypesupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/model_allowedenvironmenttype.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/model_allowedenvironmenttypeproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/model_environmentrole.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttype.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttypeproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttypeupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttypeupdateproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttype.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeupdateproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeupdatepropertiescreatorroleassignment.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/model_userroleassignment.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/environmenttypes/version.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/README.md create mode 100644 resource-manager/devcenter/2024-02-01/galleries/client.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/id_devcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/id_devcenter_test.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/id_gallery.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/id_gallery_test.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/method_createorupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/method_delete.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/method_get.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/method_listbydevcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/model_gallery.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/model_galleryproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/galleries/version.go create mode 100644 resource-manager/devcenter/2024-02-01/images/README.md create mode 100644 resource-manager/devcenter/2024-02-01/images/client.go create mode 100644 resource-manager/devcenter/2024-02-01/images/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/images/id_devcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/images/id_devcenter_test.go create mode 100644 resource-manager/devcenter/2024-02-01/images/id_gallery.go create mode 100644 resource-manager/devcenter/2024-02-01/images/id_gallery_test.go create mode 100644 resource-manager/devcenter/2024-02-01/images/id_image.go create mode 100644 resource-manager/devcenter/2024-02-01/images/id_image_test.go create mode 100644 resource-manager/devcenter/2024-02-01/images/method_get.go create mode 100644 resource-manager/devcenter/2024-02-01/images/method_listbydevcenter.go create mode 100644 resource-manager/devcenter/2024-02-01/images/method_listbygallery.go create mode 100644 resource-manager/devcenter/2024-02-01/images/model_image.go create mode 100644 resource-manager/devcenter/2024-02-01/images/model_imageproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/images/model_recommendedmachineconfiguration.go create mode 100644 resource-manager/devcenter/2024-02-01/images/model_resourcerange.go create mode 100644 resource-manager/devcenter/2024-02-01/images/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/images/version.go create mode 100644 resource-manager/devcenter/2024-02-01/imageversions/README.md create mode 100644 resource-manager/devcenter/2024-02-01/imageversions/client.go create mode 100644 resource-manager/devcenter/2024-02-01/imageversions/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/imageversions/id_image.go create mode 100644 resource-manager/devcenter/2024-02-01/imageversions/id_image_test.go create mode 100644 resource-manager/devcenter/2024-02-01/imageversions/id_version.go create mode 100644 resource-manager/devcenter/2024-02-01/imageversions/id_version_test.go create mode 100644 resource-manager/devcenter/2024-02-01/imageversions/method_get.go create mode 100644 resource-manager/devcenter/2024-02-01/imageversions/method_listbyimage.go create mode 100644 resource-manager/devcenter/2024-02-01/imageversions/model_imageversion.go create mode 100644 resource-manager/devcenter/2024-02-01/imageversions/model_imageversionproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/imageversions/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/imageversions/version.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnection/README.md create mode 100644 resource-manager/devcenter/2024-02-01/networkconnection/client.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnection/id_networkconnection.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnection/id_networkconnection_test.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnection/method_listoutboundnetworkdependenciesendpoints.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnection/method_runhealthchecks.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnection/model_endpointdependency.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnection/model_endpointdetail.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnection/model_outboundenvironmentendpoint.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnection/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnection/version.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/README.md create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/client.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/id_networkconnection.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/id_networkconnection_test.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/method_createorupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/method_delete.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/method_get.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/method_gethealthdetails.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/method_listbyresourcegroup.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/method_listbysubscription.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/method_listhealthdetails.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/method_update.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/model_healthcheck.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/model_healthcheckstatusdetails.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/model_healthcheckstatusdetailsproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/model_networkconnection.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/model_networkconnectionupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/model_networkconnectionupdateproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/model_networkproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/networkconnections/version.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/README.md create mode 100644 resource-manager/devcenter/2024-02-01/pools/client.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/id_pool.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/id_pool_test.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/id_project.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/id_project_test.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/method_createorupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/method_delete.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/method_get.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/method_listbyproject.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/method_runhealthchecks.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/method_update.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/model_healthstatusdetail.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/model_pool.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/model_poolproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/model_poolupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/model_poolupdateproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/model_stopondisconnectconfiguration.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/pools/version.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/README.md create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/client.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/id_catalog.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/id_catalog_test.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/id_project.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/id_project_test.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/method_connect.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/method_createorupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/method_delete.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/method_get.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/method_getsyncerrordetails.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/method_list.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/method_patch.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/method_sync.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalog.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogconflicterror.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogerrordetails.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogsyncerror.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogupdateproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/model_gitcatalog.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/model_syncerrordetails.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/model_syncstats.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/projectcatalogs/version.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/README.md create mode 100644 resource-manager/devcenter/2024-02-01/projects/client.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/id_project.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/id_project_test.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/method_createorupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/method_delete.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/method_get.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/method_listbyresourcegroup.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/method_listbysubscription.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/method_update.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/model_project.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/model_projectcatalogsettings.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/model_projectproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/model_projectupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/model_projectupdateproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/projects/version.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/README.md create mode 100644 resource-manager/devcenter/2024-02-01/schedules/client.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/id_pool.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/id_pool_test.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/id_schedule.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/id_schedule_test.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/method_createorupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/method_delete.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/method_get.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/method_listbypool.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/method_update.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/model_schedule.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/model_scheduleproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/model_scheduleupdate.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/model_scheduleupdateproperties.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/schedules/version.go create mode 100644 resource-manager/devcenter/2024-02-01/skus/README.md create mode 100644 resource-manager/devcenter/2024-02-01/skus/client.go create mode 100644 resource-manager/devcenter/2024-02-01/skus/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/skus/method_listbysubscription.go create mode 100644 resource-manager/devcenter/2024-02-01/skus/model_capability.go create mode 100644 resource-manager/devcenter/2024-02-01/skus/model_devcentersku.go create mode 100644 resource-manager/devcenter/2024-02-01/skus/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/skus/version.go create mode 100644 resource-manager/devcenter/2024-02-01/usages/README.md create mode 100644 resource-manager/devcenter/2024-02-01/usages/client.go create mode 100644 resource-manager/devcenter/2024-02-01/usages/constants.go create mode 100644 resource-manager/devcenter/2024-02-01/usages/id_location.go create mode 100644 resource-manager/devcenter/2024-02-01/usages/id_location_test.go create mode 100644 resource-manager/devcenter/2024-02-01/usages/method_listbylocation.go create mode 100644 resource-manager/devcenter/2024-02-01/usages/model_usage.go create mode 100644 resource-manager/devcenter/2024-02-01/usages/model_usagename.go create mode 100644 resource-manager/devcenter/2024-02-01/usages/predicates.go create mode 100644 resource-manager/devcenter/2024-02-01/usages/version.go diff --git a/resource-manager/devcenter/2024-02-01/attachednetworkconnections/README.md b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/README.md new file mode 100644 index 00000000000..74f64be764c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/attachednetworkconnections` Documentation + +The `attachednetworkconnections` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/attachednetworkconnections" +``` + + +### Client Initialization + +```go +client := attachednetworkconnections.NewAttachedNetworkConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AttachedNetworkConnectionsClient.AttachedNetworksListByDevCenter` + +```go +ctx := context.TODO() +id := attachednetworkconnections.NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + +// alternatively `client.AttachedNetworksListByDevCenter(ctx, id, attachednetworkconnections.DefaultAttachedNetworksListByDevCenterOperationOptions())` can be used to do batched pagination +items, err := client.AttachedNetworksListByDevCenterComplete(ctx, id, attachednetworkconnections.DefaultAttachedNetworksListByDevCenterOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `AttachedNetworkConnectionsClient.AttachedNetworksListByProject` + +```go +ctx := context.TODO() +id := attachednetworkconnections.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + +// alternatively `client.AttachedNetworksListByProject(ctx, id, attachednetworkconnections.DefaultAttachedNetworksListByProjectOperationOptions())` can be used to do batched pagination +items, err := client.AttachedNetworksListByProjectComplete(ctx, id, attachednetworkconnections.DefaultAttachedNetworksListByProjectOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/devcenter/2024-02-01/attachednetworkconnections/client.go b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/client.go new file mode 100644 index 00000000000..c047bb519e2 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/client.go @@ -0,0 +1,26 @@ +package attachednetworkconnections + +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 AttachedNetworkConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewAttachedNetworkConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*AttachedNetworkConnectionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "attachednetworkconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AttachedNetworkConnectionsClient: %+v", err) + } + + return &AttachedNetworkConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/attachednetworkconnections/constants.go b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/constants.go new file mode 100644 index 00000000000..187bed9c3dd --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/constants.go @@ -0,0 +1,187 @@ +package attachednetworkconnections + +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 DomainJoinType string + +const ( + DomainJoinTypeAzureADJoin DomainJoinType = "AzureADJoin" + DomainJoinTypeHybridAzureADJoin DomainJoinType = "HybridAzureADJoin" +) + +func PossibleValuesForDomainJoinType() []string { + return []string{ + string(DomainJoinTypeAzureADJoin), + string(DomainJoinTypeHybridAzureADJoin), + } +} + +func (s *DomainJoinType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDomainJoinType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDomainJoinType(input string) (*DomainJoinType, error) { + vals := map[string]DomainJoinType{ + "azureadjoin": DomainJoinTypeAzureADJoin, + "hybridazureadjoin": DomainJoinTypeHybridAzureADJoin, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DomainJoinType(input) + return &out, nil +} + +type HealthCheckStatus string + +const ( + HealthCheckStatusFailed HealthCheckStatus = "Failed" + HealthCheckStatusPassed HealthCheckStatus = "Passed" + HealthCheckStatusPending HealthCheckStatus = "Pending" + HealthCheckStatusRunning HealthCheckStatus = "Running" + HealthCheckStatusUnknown HealthCheckStatus = "Unknown" + HealthCheckStatusWarning HealthCheckStatus = "Warning" +) + +func PossibleValuesForHealthCheckStatus() []string { + return []string{ + string(HealthCheckStatusFailed), + string(HealthCheckStatusPassed), + string(HealthCheckStatusPending), + string(HealthCheckStatusRunning), + string(HealthCheckStatusUnknown), + string(HealthCheckStatusWarning), + } +} + +func (s *HealthCheckStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHealthCheckStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHealthCheckStatus(input string) (*HealthCheckStatus, error) { + vals := map[string]HealthCheckStatus{ + "failed": HealthCheckStatusFailed, + "passed": HealthCheckStatusPassed, + "pending": HealthCheckStatusPending, + "running": HealthCheckStatusRunning, + "unknown": HealthCheckStatusUnknown, + "warning": HealthCheckStatusWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthCheckStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMovingResources ProvisioningState = "MovingResources" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateRolloutInProgress ProvisioningState = "RolloutInProgress" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateStorageProvisioningFailed ProvisioningState = "StorageProvisioningFailed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateTransientFailure ProvisioningState = "TransientFailure" + ProvisioningStateUpdated ProvisioningState = "Updated" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMovingResources), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateRolloutInProgress), + string(ProvisioningStateRunning), + string(ProvisioningStateStorageProvisioningFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateTransientFailure), + string(ProvisioningStateUpdated), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "movingresources": ProvisioningStateMovingResources, + "notspecified": ProvisioningStateNotSpecified, + "rolloutinprogress": ProvisioningStateRolloutInProgress, + "running": ProvisioningStateRunning, + "storageprovisioningfailed": ProvisioningStateStorageProvisioningFailed, + "succeeded": ProvisioningStateSucceeded, + "transientfailure": ProvisioningStateTransientFailure, + "updated": ProvisioningStateUpdated, + "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/devcenter/2024-02-01/attachednetworkconnections/id_devcenter.go b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_devcenter.go new file mode 100644 index 00000000000..17697431bef --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_devcenter.go @@ -0,0 +1,125 @@ +package attachednetworkconnections + +import ( + "fmt" + "strings" + + "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 = &DevCenterId{} + +// DevCenterId is a struct representing the Resource ID for a Dev Center +type DevCenterId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string +} + +// NewDevCenterID returns a new DevCenterId struct +func NewDevCenterID(subscriptionId string, resourceGroupName string, devCenterName string) DevCenterId { + return DevCenterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + } +} + +// ParseDevCenterID parses 'input' into a DevCenterId +func ParseDevCenterID(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDevCenterIDInsensitively parses 'input' case-insensitively into a DevCenterId +// note: this method should only be used for API response data and not user input +func ParseDevCenterIDInsensitively(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DevCenterId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + return nil +} + +// ValidateDevCenterID checks that 'input' can be parsed as a Dev Center ID +func ValidateDevCenterID(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 := ParseDevCenterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dev Center ID +func (id DevCenterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dev Center ID +func (id DevCenterId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + } +} + +// String returns a human-readable description of this Dev Center ID +func (id DevCenterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + } + return fmt.Sprintf("Dev Center (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_devcenter_test.go b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_devcenter_test.go new file mode 100644 index 00000000000..bdae77220af --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_devcenter_test.go @@ -0,0 +1,282 @@ +package attachednetworkconnections + +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 = &DevCenterId{} + +func TestNewDevCenterID(t *testing.T) { + id := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } +} + +func TestFormatDevCenterID(t *testing.T) { + actual := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDevCenterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestParseDevCenterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestSegmentsForDevCenterId(t *testing.T) { + segments := DevCenterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DevCenterId 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/devcenter/2024-02-01/attachednetworkconnections/id_project.go b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_project.go new file mode 100644 index 00000000000..3ef33e0bc0a --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_project.go @@ -0,0 +1,125 @@ +package attachednetworkconnections + +import ( + "fmt" + "strings" + + "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 = &ProjectId{} + +// ProjectId is a struct representing the Resource ID for a Project +type ProjectId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string +} + +// NewProjectID returns a new ProjectId struct +func NewProjectID(subscriptionId string, resourceGroupName string, projectName string) ProjectId { + return ProjectId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + } +} + +// ParseProjectID parses 'input' into a ProjectId +func ParseProjectID(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProjectIDInsensitively parses 'input' case-insensitively into a ProjectId +// note: this method should only be used for API response data and not user input +func ParseProjectIDInsensitively(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProjectId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + return nil +} + +// ValidateProjectID checks that 'input' can be parsed as a Project ID +func ValidateProjectID(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 := ParseProjectID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Project ID +func (id ProjectId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Project ID +func (id ProjectId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + } +} + +// String returns a human-readable description of this Project ID +func (id ProjectId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + } + return fmt.Sprintf("Project (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_project_test.go b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_project_test.go new file mode 100644 index 00000000000..695924b1172 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/id_project_test.go @@ -0,0 +1,282 @@ +package attachednetworkconnections + +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 = &ProjectId{} + +func TestNewProjectID(t *testing.T) { + id := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } +} + +func TestFormatProjectID(t *testing.T) { + actual := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProjectID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestParseProjectIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestSegmentsForProjectId(t *testing.T) { + segments := ProjectId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProjectId 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/devcenter/2024-02-01/attachednetworkconnections/method_attachednetworkslistbydevcenter.go b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/method_attachednetworkslistbydevcenter.go new file mode 100644 index 00000000000..86db638c567 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/method_attachednetworkslistbydevcenter.go @@ -0,0 +1,119 @@ +package attachednetworkconnections + +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 AttachedNetworksListByDevCenterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AttachedNetworkConnection +} + +type AttachedNetworksListByDevCenterCompleteResult struct { + LatestHttpResponse *http.Response + Items []AttachedNetworkConnection +} + +type AttachedNetworksListByDevCenterOperationOptions struct { + Top *int64 +} + +func DefaultAttachedNetworksListByDevCenterOperationOptions() AttachedNetworksListByDevCenterOperationOptions { + return AttachedNetworksListByDevCenterOperationOptions{} +} + +func (o AttachedNetworksListByDevCenterOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o AttachedNetworksListByDevCenterOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o AttachedNetworksListByDevCenterOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// AttachedNetworksListByDevCenter ... +func (c AttachedNetworkConnectionsClient) AttachedNetworksListByDevCenter(ctx context.Context, id DevCenterId, options AttachedNetworksListByDevCenterOperationOptions) (result AttachedNetworksListByDevCenterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/attachednetworks", id.ID()), + OptionsObject: options, + } + + 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 *[]AttachedNetworkConnection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AttachedNetworksListByDevCenterComplete retrieves all the results into a single object +func (c AttachedNetworkConnectionsClient) AttachedNetworksListByDevCenterComplete(ctx context.Context, id DevCenterId, options AttachedNetworksListByDevCenterOperationOptions) (AttachedNetworksListByDevCenterCompleteResult, error) { + return c.AttachedNetworksListByDevCenterCompleteMatchingPredicate(ctx, id, options, AttachedNetworkConnectionOperationPredicate{}) +} + +// AttachedNetworksListByDevCenterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AttachedNetworkConnectionsClient) AttachedNetworksListByDevCenterCompleteMatchingPredicate(ctx context.Context, id DevCenterId, options AttachedNetworksListByDevCenterOperationOptions, predicate AttachedNetworkConnectionOperationPredicate) (result AttachedNetworksListByDevCenterCompleteResult, err error) { + items := make([]AttachedNetworkConnection, 0) + + resp, err := c.AttachedNetworksListByDevCenter(ctx, id, options) + if err != nil { + 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 = AttachedNetworksListByDevCenterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/attachednetworkconnections/method_attachednetworkslistbyproject.go b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/method_attachednetworkslistbyproject.go new file mode 100644 index 00000000000..76cf09581c1 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/method_attachednetworkslistbyproject.go @@ -0,0 +1,119 @@ +package attachednetworkconnections + +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 AttachedNetworksListByProjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AttachedNetworkConnection +} + +type AttachedNetworksListByProjectCompleteResult struct { + LatestHttpResponse *http.Response + Items []AttachedNetworkConnection +} + +type AttachedNetworksListByProjectOperationOptions struct { + Top *int64 +} + +func DefaultAttachedNetworksListByProjectOperationOptions() AttachedNetworksListByProjectOperationOptions { + return AttachedNetworksListByProjectOperationOptions{} +} + +func (o AttachedNetworksListByProjectOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o AttachedNetworksListByProjectOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o AttachedNetworksListByProjectOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// AttachedNetworksListByProject ... +func (c AttachedNetworkConnectionsClient) AttachedNetworksListByProject(ctx context.Context, id ProjectId, options AttachedNetworksListByProjectOperationOptions) (result AttachedNetworksListByProjectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/attachednetworks", id.ID()), + OptionsObject: options, + } + + 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 *[]AttachedNetworkConnection `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AttachedNetworksListByProjectComplete retrieves all the results into a single object +func (c AttachedNetworkConnectionsClient) AttachedNetworksListByProjectComplete(ctx context.Context, id ProjectId, options AttachedNetworksListByProjectOperationOptions) (AttachedNetworksListByProjectCompleteResult, error) { + return c.AttachedNetworksListByProjectCompleteMatchingPredicate(ctx, id, options, AttachedNetworkConnectionOperationPredicate{}) +} + +// AttachedNetworksListByProjectCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AttachedNetworkConnectionsClient) AttachedNetworksListByProjectCompleteMatchingPredicate(ctx context.Context, id ProjectId, options AttachedNetworksListByProjectOperationOptions, predicate AttachedNetworkConnectionOperationPredicate) (result AttachedNetworksListByProjectCompleteResult, err error) { + items := make([]AttachedNetworkConnection, 0) + + resp, err := c.AttachedNetworksListByProject(ctx, id, options) + if err != nil { + 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 = AttachedNetworksListByProjectCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/attachednetworkconnections/model_attachednetworkconnection.go b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/model_attachednetworkconnection.go new file mode 100644 index 00000000000..ba8b52ae22d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/model_attachednetworkconnection.go @@ -0,0 +1,16 @@ +package attachednetworkconnections + +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 AttachedNetworkConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AttachedNetworkConnectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/attachednetworkconnections/model_attachednetworkconnectionproperties.go b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/model_attachednetworkconnectionproperties.go new file mode 100644 index 00000000000..c8557609bff --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/model_attachednetworkconnectionproperties.go @@ -0,0 +1,12 @@ +package attachednetworkconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AttachedNetworkConnectionProperties struct { + DomainJoinType *DomainJoinType `json:"domainJoinType,omitempty"` + HealthCheckStatus *HealthCheckStatus `json:"healthCheckStatus,omitempty"` + NetworkConnectionId string `json:"networkConnectionId"` + NetworkConnectionLocation *string `json:"networkConnectionLocation,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/attachednetworkconnections/predicates.go b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/predicates.go new file mode 100644 index 00000000000..591ae864171 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/predicates.go @@ -0,0 +1,27 @@ +package attachednetworkconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AttachedNetworkConnectionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AttachedNetworkConnectionOperationPredicate) Matches(input AttachedNetworkConnection) 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/devcenter/2024-02-01/attachednetworkconnections/version.go b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/version.go new file mode 100644 index 00000000000..67f8686188a --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/attachednetworkconnections/version.go @@ -0,0 +1,12 @@ +package attachednetworkconnections + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/attachednetworkconnections/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/README.md b/resource-manager/devcenter/2024-02-01/catalogs/README.md new file mode 100644 index 00000000000..39434ecc569 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/README.md @@ -0,0 +1,139 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/catalogs` Documentation + +The `catalogs` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/catalogs" +``` + + +### Client Initialization + +```go +client := catalogs.NewCatalogsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CatalogsClient.Connect` + +```go +ctx := context.TODO() +id := catalogs.NewDevCenterCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue") + +if err := client.ConnectThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `CatalogsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := catalogs.NewDevCenterCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue") + +payload := catalogs.Catalog{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `CatalogsClient.Delete` + +```go +ctx := context.TODO() +id := catalogs.NewDevCenterCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `CatalogsClient.Get` + +```go +ctx := context.TODO() +id := catalogs.NewDevCenterCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue") + +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: `CatalogsClient.GetSyncErrorDetails` + +```go +ctx := context.TODO() +id := catalogs.NewDevCenterCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue") + +read, err := client.GetSyncErrorDetails(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CatalogsClient.ListByDevCenter` + +```go +ctx := context.TODO() +id := catalogs.NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + +// alternatively `client.ListByDevCenter(ctx, id, catalogs.DefaultListByDevCenterOperationOptions())` can be used to do batched pagination +items, err := client.ListByDevCenterComplete(ctx, id, catalogs.DefaultListByDevCenterOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CatalogsClient.Sync` + +```go +ctx := context.TODO() +id := catalogs.NewDevCenterCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue") + +if err := client.SyncThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `CatalogsClient.Update` + +```go +ctx := context.TODO() +id := catalogs.NewDevCenterCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue") + +payload := catalogs.CatalogUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/devcenter/2024-02-01/catalogs/client.go b/resource-manager/devcenter/2024-02-01/catalogs/client.go new file mode 100644 index 00000000000..fe6ad53cdd7 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/client.go @@ -0,0 +1,26 @@ +package catalogs + +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 CatalogsClient struct { + Client *resourcemanager.Client +} + +func NewCatalogsClientWithBaseURI(sdkApi sdkEnv.Api) (*CatalogsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "catalogs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CatalogsClient: %+v", err) + } + + return &CatalogsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/constants.go b/resource-manager/devcenter/2024-02-01/catalogs/constants.go new file mode 100644 index 00000000000..6f19809e7f3 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/constants.go @@ -0,0 +1,260 @@ +package catalogs + +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 CatalogConnectionState string + +const ( + CatalogConnectionStateConnected CatalogConnectionState = "Connected" + CatalogConnectionStateDisconnected CatalogConnectionState = "Disconnected" +) + +func PossibleValuesForCatalogConnectionState() []string { + return []string{ + string(CatalogConnectionStateConnected), + string(CatalogConnectionStateDisconnected), + } +} + +func (s *CatalogConnectionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogConnectionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogConnectionState(input string) (*CatalogConnectionState, error) { + vals := map[string]CatalogConnectionState{ + "connected": CatalogConnectionStateConnected, + "disconnected": CatalogConnectionStateDisconnected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogConnectionState(input) + return &out, nil +} + +type CatalogItemType string + +const ( + CatalogItemTypeEnvironmentDefinition CatalogItemType = "EnvironmentDefinition" +) + +func PossibleValuesForCatalogItemType() []string { + return []string{ + string(CatalogItemTypeEnvironmentDefinition), + } +} + +func (s *CatalogItemType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogItemType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogItemType(input string) (*CatalogItemType, error) { + vals := map[string]CatalogItemType{ + "environmentdefinition": CatalogItemTypeEnvironmentDefinition, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogItemType(input) + return &out, nil +} + +type CatalogSyncState string + +const ( + CatalogSyncStateCanceled CatalogSyncState = "Canceled" + CatalogSyncStateFailed CatalogSyncState = "Failed" + CatalogSyncStateInProgress CatalogSyncState = "InProgress" + CatalogSyncStateSucceeded CatalogSyncState = "Succeeded" +) + +func PossibleValuesForCatalogSyncState() []string { + return []string{ + string(CatalogSyncStateCanceled), + string(CatalogSyncStateFailed), + string(CatalogSyncStateInProgress), + string(CatalogSyncStateSucceeded), + } +} + +func (s *CatalogSyncState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogSyncState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogSyncState(input string) (*CatalogSyncState, error) { + vals := map[string]CatalogSyncState{ + "canceled": CatalogSyncStateCanceled, + "failed": CatalogSyncStateFailed, + "inprogress": CatalogSyncStateInProgress, + "succeeded": CatalogSyncStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogSyncState(input) + return &out, nil +} + +type CatalogSyncType string + +const ( + CatalogSyncTypeManual CatalogSyncType = "Manual" + CatalogSyncTypeScheduled CatalogSyncType = "Scheduled" +) + +func PossibleValuesForCatalogSyncType() []string { + return []string{ + string(CatalogSyncTypeManual), + string(CatalogSyncTypeScheduled), + } +} + +func (s *CatalogSyncType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogSyncType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogSyncType(input string) (*CatalogSyncType, error) { + vals := map[string]CatalogSyncType{ + "manual": CatalogSyncTypeManual, + "scheduled": CatalogSyncTypeScheduled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogSyncType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMovingResources ProvisioningState = "MovingResources" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateRolloutInProgress ProvisioningState = "RolloutInProgress" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateStorageProvisioningFailed ProvisioningState = "StorageProvisioningFailed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateTransientFailure ProvisioningState = "TransientFailure" + ProvisioningStateUpdated ProvisioningState = "Updated" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMovingResources), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateRolloutInProgress), + string(ProvisioningStateRunning), + string(ProvisioningStateStorageProvisioningFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateTransientFailure), + string(ProvisioningStateUpdated), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "movingresources": ProvisioningStateMovingResources, + "notspecified": ProvisioningStateNotSpecified, + "rolloutinprogress": ProvisioningStateRolloutInProgress, + "running": ProvisioningStateRunning, + "storageprovisioningfailed": ProvisioningStateStorageProvisioningFailed, + "succeeded": ProvisioningStateSucceeded, + "transientfailure": ProvisioningStateTransientFailure, + "updated": ProvisioningStateUpdated, + "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/devcenter/2024-02-01/catalogs/id_devcenter.go b/resource-manager/devcenter/2024-02-01/catalogs/id_devcenter.go new file mode 100644 index 00000000000..6a5d2b25dd4 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/id_devcenter.go @@ -0,0 +1,125 @@ +package catalogs + +import ( + "fmt" + "strings" + + "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 = &DevCenterId{} + +// DevCenterId is a struct representing the Resource ID for a Dev Center +type DevCenterId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string +} + +// NewDevCenterID returns a new DevCenterId struct +func NewDevCenterID(subscriptionId string, resourceGroupName string, devCenterName string) DevCenterId { + return DevCenterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + } +} + +// ParseDevCenterID parses 'input' into a DevCenterId +func ParseDevCenterID(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDevCenterIDInsensitively parses 'input' case-insensitively into a DevCenterId +// note: this method should only be used for API response data and not user input +func ParseDevCenterIDInsensitively(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DevCenterId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + return nil +} + +// ValidateDevCenterID checks that 'input' can be parsed as a Dev Center ID +func ValidateDevCenterID(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 := ParseDevCenterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dev Center ID +func (id DevCenterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dev Center ID +func (id DevCenterId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + } +} + +// String returns a human-readable description of this Dev Center ID +func (id DevCenterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + } + return fmt.Sprintf("Dev Center (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/id_devcenter_test.go b/resource-manager/devcenter/2024-02-01/catalogs/id_devcenter_test.go new file mode 100644 index 00000000000..abb89d625b0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/id_devcenter_test.go @@ -0,0 +1,282 @@ +package catalogs + +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 = &DevCenterId{} + +func TestNewDevCenterID(t *testing.T) { + id := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } +} + +func TestFormatDevCenterID(t *testing.T) { + actual := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDevCenterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestParseDevCenterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestSegmentsForDevCenterId(t *testing.T) { + segments := DevCenterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DevCenterId 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/devcenter/2024-02-01/catalogs/id_devcentercatalog.go b/resource-manager/devcenter/2024-02-01/catalogs/id_devcentercatalog.go new file mode 100644 index 00000000000..ef37e7779df --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/id_devcentercatalog.go @@ -0,0 +1,134 @@ +package catalogs + +import ( + "fmt" + "strings" + + "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 = &DevCenterCatalogId{} + +// DevCenterCatalogId is a struct representing the Resource ID for a Dev Center Catalog +type DevCenterCatalogId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string + CatalogName string +} + +// NewDevCenterCatalogID returns a new DevCenterCatalogId struct +func NewDevCenterCatalogID(subscriptionId string, resourceGroupName string, devCenterName string, catalogName string) DevCenterCatalogId { + return DevCenterCatalogId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + CatalogName: catalogName, + } +} + +// ParseDevCenterCatalogID parses 'input' into a DevCenterCatalogId +func ParseDevCenterCatalogID(input string) (*DevCenterCatalogId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterCatalogId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterCatalogId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDevCenterCatalogIDInsensitively parses 'input' case-insensitively into a DevCenterCatalogId +// note: this method should only be used for API response data and not user input +func ParseDevCenterCatalogIDInsensitively(input string) (*DevCenterCatalogId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterCatalogId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterCatalogId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DevCenterCatalogId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + if id.CatalogName, ok = input.Parsed["catalogName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "catalogName", input) + } + + return nil +} + +// ValidateDevCenterCatalogID checks that 'input' can be parsed as a Dev Center Catalog ID +func ValidateDevCenterCatalogID(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 := ParseDevCenterCatalogID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dev Center Catalog ID +func (id DevCenterCatalogId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s/catalogs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName, id.CatalogName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dev Center Catalog ID +func (id DevCenterCatalogId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + resourceids.StaticSegment("staticCatalogs", "catalogs", "catalogs"), + resourceids.UserSpecifiedSegment("catalogName", "catalogValue"), + } +} + +// String returns a human-readable description of this Dev Center Catalog ID +func (id DevCenterCatalogId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + fmt.Sprintf("Catalog Name: %q", id.CatalogName), + } + return fmt.Sprintf("Dev Center Catalog (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/id_devcentercatalog_test.go b/resource-manager/devcenter/2024-02-01/catalogs/id_devcentercatalog_test.go new file mode 100644 index 00000000000..fd4fcccb1d5 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/id_devcentercatalog_test.go @@ -0,0 +1,327 @@ +package catalogs + +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 = &DevCenterCatalogId{} + +func TestNewDevCenterCatalogID(t *testing.T) { + id := NewDevCenterCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } + + if id.CatalogName != "catalogValue" { + t.Fatalf("Expected %q but got %q for Segment 'CatalogName'", id.CatalogName, "catalogValue") + } +} + +func TestFormatDevCenterCatalogID(t *testing.T) { + actual := NewDevCenterCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDevCenterCatalogID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterCatalogId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue", + Expected: &DevCenterCatalogId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + CatalogName: "catalogValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterCatalogID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.CatalogName != v.Expected.CatalogName { + t.Fatalf("Expected %q but got %q for CatalogName", v.Expected.CatalogName, actual.CatalogName) + } + + } +} + +func TestParseDevCenterCatalogIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterCatalogId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/cAtAlOgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue", + Expected: &DevCenterCatalogId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + CatalogName: "catalogValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/cAtAlOgS/cAtAlOgVaLuE", + Expected: &DevCenterCatalogId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + CatalogName: "cAtAlOgVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/cAtAlOgS/cAtAlOgVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterCatalogIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.CatalogName != v.Expected.CatalogName { + t.Fatalf("Expected %q but got %q for CatalogName", v.Expected.CatalogName, actual.CatalogName) + } + + } +} + +func TestSegmentsForDevCenterCatalogId(t *testing.T) { + segments := DevCenterCatalogId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DevCenterCatalogId 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/devcenter/2024-02-01/catalogs/method_connect.go b/resource-manager/devcenter/2024-02-01/catalogs/method_connect.go new file mode 100644 index 00000000000..20c7fcde573 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/method_connect.go @@ -0,0 +1,69 @@ +package catalogs + +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 ConnectOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Connect ... +func (c CatalogsClient) Connect(ctx context.Context, id DevCenterCatalogId) (result ConnectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/connect", 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 +} + +// ConnectThenPoll performs Connect then polls until it's completed +func (c CatalogsClient) ConnectThenPoll(ctx context.Context, id DevCenterCatalogId) error { + result, err := c.Connect(ctx, id) + if err != nil { + return fmt.Errorf("performing Connect: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Connect: %+v", err) + } + + return nil +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/method_createorupdate.go b/resource-manager/devcenter/2024-02-01/catalogs/method_createorupdate.go new file mode 100644 index 00000000000..6b285be316f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/method_createorupdate.go @@ -0,0 +1,75 @@ +package catalogs + +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 *Catalog +} + +// CreateOrUpdate ... +func (c CatalogsClient) CreateOrUpdate(ctx context.Context, id DevCenterCatalogId, input Catalog) (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 CatalogsClient) CreateOrUpdateThenPoll(ctx context.Context, id DevCenterCatalogId, input Catalog) 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/devcenter/2024-02-01/catalogs/method_delete.go b/resource-manager/devcenter/2024-02-01/catalogs/method_delete.go new file mode 100644 index 00000000000..1c348bdc8b9 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/method_delete.go @@ -0,0 +1,70 @@ +package catalogs + +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 CatalogsClient) Delete(ctx context.Context, id DevCenterCatalogId) (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 CatalogsClient) DeleteThenPoll(ctx context.Context, id DevCenterCatalogId) 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/devcenter/2024-02-01/catalogs/method_get.go b/resource-manager/devcenter/2024-02-01/catalogs/method_get.go new file mode 100644 index 00000000000..ac57c556f8f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/method_get.go @@ -0,0 +1,54 @@ +package catalogs + +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 *Catalog +} + +// Get ... +func (c CatalogsClient) Get(ctx context.Context, id DevCenterCatalogId) (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 Catalog + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/method_getsyncerrordetails.go b/resource-manager/devcenter/2024-02-01/catalogs/method_getsyncerrordetails.go new file mode 100644 index 00000000000..06baffc838d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/method_getsyncerrordetails.go @@ -0,0 +1,55 @@ +package catalogs + +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 GetSyncErrorDetailsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SyncErrorDetails +} + +// GetSyncErrorDetails ... +func (c CatalogsClient) GetSyncErrorDetails(ctx context.Context, id DevCenterCatalogId) (result GetSyncErrorDetailsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getSyncErrorDetails", 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 SyncErrorDetails + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/method_listbydevcenter.go b/resource-manager/devcenter/2024-02-01/catalogs/method_listbydevcenter.go new file mode 100644 index 00000000000..a8c590e41c8 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/method_listbydevcenter.go @@ -0,0 +1,119 @@ +package catalogs + +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 ListByDevCenterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Catalog +} + +type ListByDevCenterCompleteResult struct { + LatestHttpResponse *http.Response + Items []Catalog +} + +type ListByDevCenterOperationOptions struct { + Top *int64 +} + +func DefaultListByDevCenterOperationOptions() ListByDevCenterOperationOptions { + return ListByDevCenterOperationOptions{} +} + +func (o ListByDevCenterOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDevCenterOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByDevCenterOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByDevCenter ... +func (c CatalogsClient) ListByDevCenter(ctx context.Context, id DevCenterId, options ListByDevCenterOperationOptions) (result ListByDevCenterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/catalogs", id.ID()), + OptionsObject: options, + } + + 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 *[]Catalog `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDevCenterComplete retrieves all the results into a single object +func (c CatalogsClient) ListByDevCenterComplete(ctx context.Context, id DevCenterId, options ListByDevCenterOperationOptions) (ListByDevCenterCompleteResult, error) { + return c.ListByDevCenterCompleteMatchingPredicate(ctx, id, options, CatalogOperationPredicate{}) +} + +// ListByDevCenterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CatalogsClient) ListByDevCenterCompleteMatchingPredicate(ctx context.Context, id DevCenterId, options ListByDevCenterOperationOptions, predicate CatalogOperationPredicate) (result ListByDevCenterCompleteResult, err error) { + items := make([]Catalog, 0) + + resp, err := c.ListByDevCenter(ctx, id, options) + if err != nil { + 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 = ListByDevCenterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/method_sync.go b/resource-manager/devcenter/2024-02-01/catalogs/method_sync.go new file mode 100644 index 00000000000..ae64898828c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/method_sync.go @@ -0,0 +1,69 @@ +package catalogs + +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 SyncOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Sync ... +func (c CatalogsClient) Sync(ctx context.Context, id DevCenterCatalogId) (result SyncOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/sync", 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 +} + +// SyncThenPoll performs Sync then polls until it's completed +func (c CatalogsClient) SyncThenPoll(ctx context.Context, id DevCenterCatalogId) error { + result, err := c.Sync(ctx, id) + if err != nil { + return fmt.Errorf("performing Sync: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Sync: %+v", err) + } + + return nil +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/method_update.go b/resource-manager/devcenter/2024-02-01/catalogs/method_update.go new file mode 100644 index 00000000000..8054a0a0a48 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/method_update.go @@ -0,0 +1,75 @@ +package catalogs + +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 *Catalog +} + +// Update ... +func (c CatalogsClient) Update(ctx context.Context, id DevCenterCatalogId, input CatalogUpdate) (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 CatalogsClient) UpdateThenPoll(ctx context.Context, id DevCenterCatalogId, input CatalogUpdate) 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/devcenter/2024-02-01/catalogs/model_catalog.go b/resource-manager/devcenter/2024-02-01/catalogs/model_catalog.go new file mode 100644 index 00000000000..6e459c3d7dd --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/model_catalog.go @@ -0,0 +1,16 @@ +package catalogs + +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 Catalog struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CatalogProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/model_catalogconflicterror.go b/resource-manager/devcenter/2024-02-01/catalogs/model_catalogconflicterror.go new file mode 100644 index 00000000000..91d0374e370 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/model_catalogconflicterror.go @@ -0,0 +1,9 @@ +package catalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogConflictError struct { + Name *string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/model_catalogerrordetails.go b/resource-manager/devcenter/2024-02-01/catalogs/model_catalogerrordetails.go new file mode 100644 index 00000000000..c696278ef0a --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/model_catalogerrordetails.go @@ -0,0 +1,9 @@ +package catalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogErrorDetails struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/model_catalogproperties.go b/resource-manager/devcenter/2024-02-01/catalogs/model_catalogproperties.go new file mode 100644 index 00000000000..bc75a24c4e0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/model_catalogproperties.go @@ -0,0 +1,47 @@ +package catalogs + +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 CatalogProperties struct { + AdoGit *GitCatalog `json:"adoGit,omitempty"` + ConnectionState *CatalogConnectionState `json:"connectionState,omitempty"` + GitHub *GitCatalog `json:"gitHub,omitempty"` + LastConnectionTime *string `json:"lastConnectionTime,omitempty"` + LastSyncStats *SyncStats `json:"lastSyncStats,omitempty"` + LastSyncTime *string `json:"lastSyncTime,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + SyncState *CatalogSyncState `json:"syncState,omitempty"` + SyncType *CatalogSyncType `json:"syncType,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} + +func (o *CatalogProperties) GetLastConnectionTimeAsTime() (*time.Time, error) { + if o.LastConnectionTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastConnectionTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *CatalogProperties) SetLastConnectionTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastConnectionTime = &formatted +} + +func (o *CatalogProperties) GetLastSyncTimeAsTime() (*time.Time, error) { + if o.LastSyncTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSyncTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *CatalogProperties) SetLastSyncTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSyncTime = &formatted +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/model_catalogsyncerror.go b/resource-manager/devcenter/2024-02-01/catalogs/model_catalogsyncerror.go new file mode 100644 index 00000000000..7dad94458c3 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/model_catalogsyncerror.go @@ -0,0 +1,9 @@ +package catalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogSyncError struct { + ErrorDetails *[]CatalogErrorDetails `json:"errorDetails,omitempty"` + Path *string `json:"path,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/model_catalogupdate.go b/resource-manager/devcenter/2024-02-01/catalogs/model_catalogupdate.go new file mode 100644 index 00000000000..339d6b221db --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/model_catalogupdate.go @@ -0,0 +1,8 @@ +package catalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogUpdate struct { + Properties *CatalogUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/model_catalogupdateproperties.go b/resource-manager/devcenter/2024-02-01/catalogs/model_catalogupdateproperties.go new file mode 100644 index 00000000000..177df9834da --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/model_catalogupdateproperties.go @@ -0,0 +1,11 @@ +package catalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogUpdateProperties struct { + AdoGit *GitCatalog `json:"adoGit,omitempty"` + GitHub *GitCatalog `json:"gitHub,omitempty"` + SyncType *CatalogSyncType `json:"syncType,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/model_gitcatalog.go b/resource-manager/devcenter/2024-02-01/catalogs/model_gitcatalog.go new file mode 100644 index 00000000000..dd040aa7fcf --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/model_gitcatalog.go @@ -0,0 +1,11 @@ +package catalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitCatalog struct { + Branch *string `json:"branch,omitempty"` + Path *string `json:"path,omitempty"` + SecretIdentifier *string `json:"secretIdentifier,omitempty"` + Uri *string `json:"uri,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/model_syncerrordetails.go b/resource-manager/devcenter/2024-02-01/catalogs/model_syncerrordetails.go new file mode 100644 index 00000000000..9c62e56b484 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/model_syncerrordetails.go @@ -0,0 +1,10 @@ +package catalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncErrorDetails struct { + Conflicts *[]CatalogConflictError `json:"conflicts,omitempty"` + Errors *[]CatalogSyncError `json:"errors,omitempty"` + OperationError *CatalogErrorDetails `json:"operationError,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/model_syncstats.go b/resource-manager/devcenter/2024-02-01/catalogs/model_syncstats.go new file mode 100644 index 00000000000..d6929182dd6 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/model_syncstats.go @@ -0,0 +1,14 @@ +package catalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncStats struct { + Added *int64 `json:"added,omitempty"` + Removed *int64 `json:"removed,omitempty"` + SyncedCatalogItemTypes *[]CatalogItemType `json:"syncedCatalogItemTypes,omitempty"` + SynchronizationErrors *int64 `json:"synchronizationErrors,omitempty"` + Unchanged *int64 `json:"unchanged,omitempty"` + Updated *int64 `json:"updated,omitempty"` + ValidationErrors *int64 `json:"validationErrors,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/catalogs/predicates.go b/resource-manager/devcenter/2024-02-01/catalogs/predicates.go new file mode 100644 index 00000000000..b7360c859b1 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/predicates.go @@ -0,0 +1,27 @@ +package catalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CatalogOperationPredicate) Matches(input Catalog) 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/devcenter/2024-02-01/catalogs/version.go b/resource-manager/devcenter/2024-02-01/catalogs/version.go new file mode 100644 index 00000000000..d69eccd038b --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/catalogs/version.go @@ -0,0 +1,12 @@ +package catalogs + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/catalogs/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/checknameavailability/README.md b/resource-manager/devcenter/2024-02-01/checknameavailability/README.md new file mode 100644 index 00000000000..11a6529255f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checknameavailability/README.md @@ -0,0 +1,42 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/checknameavailability` Documentation + +The `checknameavailability` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/checknameavailability" +``` + + +### Client Initialization + +```go +client := checknameavailability.NewCheckNameAvailabilityClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CheckNameAvailabilityClient.Execute` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := checknameavailability.CheckNameAvailabilityRequest{ + // ... +} + + +read, err := client.Execute(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/devcenter/2024-02-01/checknameavailability/client.go b/resource-manager/devcenter/2024-02-01/checknameavailability/client.go new file mode 100644 index 00000000000..9991e58a518 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checknameavailability/client.go @@ -0,0 +1,26 @@ +package checknameavailability + +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 CheckNameAvailabilityClient struct { + Client *resourcemanager.Client +} + +func NewCheckNameAvailabilityClientWithBaseURI(sdkApi sdkEnv.Api) (*CheckNameAvailabilityClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "checknameavailability", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CheckNameAvailabilityClient: %+v", err) + } + + return &CheckNameAvailabilityClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/checknameavailability/constants.go b/resource-manager/devcenter/2024-02-01/checknameavailability/constants.go new file mode 100644 index 00000000000..07700dec9cf --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checknameavailability/constants.go @@ -0,0 +1,51 @@ +package checknameavailability + +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 CheckNameAvailabilityReason string + +const ( + CheckNameAvailabilityReasonAlreadyExists CheckNameAvailabilityReason = "AlreadyExists" + CheckNameAvailabilityReasonInvalid CheckNameAvailabilityReason = "Invalid" +) + +func PossibleValuesForCheckNameAvailabilityReason() []string { + return []string{ + string(CheckNameAvailabilityReasonAlreadyExists), + string(CheckNameAvailabilityReasonInvalid), + } +} + +func (s *CheckNameAvailabilityReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCheckNameAvailabilityReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCheckNameAvailabilityReason(input string) (*CheckNameAvailabilityReason, error) { + vals := map[string]CheckNameAvailabilityReason{ + "alreadyexists": CheckNameAvailabilityReasonAlreadyExists, + "invalid": CheckNameAvailabilityReasonInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CheckNameAvailabilityReason(input) + return &out, nil +} diff --git a/resource-manager/devcenter/2024-02-01/checknameavailability/method_execute.go b/resource-manager/devcenter/2024-02-01/checknameavailability/method_execute.go new file mode 100644 index 00000000000..6fb99dc8a93 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checknameavailability/method_execute.go @@ -0,0 +1,60 @@ +package checknameavailability + +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 ExecuteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityResponse +} + +// Execute ... +func (c CheckNameAvailabilityClient) Execute(ctx context.Context, id commonids.SubscriptionId, input CheckNameAvailabilityRequest) (result ExecuteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.DevCenter/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 CheckNameAvailabilityResponse + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/checknameavailability/model_checknameavailabilityrequest.go b/resource-manager/devcenter/2024-02-01/checknameavailability/model_checknameavailabilityrequest.go new file mode 100644 index 00000000000..8c82090e86f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checknameavailability/model_checknameavailabilityrequest.go @@ -0,0 +1,9 @@ +package checknameavailability + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityRequest struct { + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/checknameavailability/model_checknameavailabilityresponse.go b/resource-manager/devcenter/2024-02-01/checknameavailability/model_checknameavailabilityresponse.go new file mode 100644 index 00000000000..85a80bb6429 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checknameavailability/model_checknameavailabilityresponse.go @@ -0,0 +1,10 @@ +package checknameavailability + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResponse struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *CheckNameAvailabilityReason `json:"reason,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/checknameavailability/version.go b/resource-manager/devcenter/2024-02-01/checknameavailability/version.go new file mode 100644 index 00000000000..e43d7329c52 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checknameavailability/version.go @@ -0,0 +1,12 @@ +package checknameavailability + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/checknameavailability/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/checkscopednameavailability/README.md b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/README.md new file mode 100644 index 00000000000..19e8ff82ae0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/README.md @@ -0,0 +1,42 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/checkscopednameavailability` Documentation + +The `checkscopednameavailability` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/checkscopednameavailability" +``` + + +### Client Initialization + +```go +client := checkscopednameavailability.NewCheckScopedNameAvailabilityClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CheckScopedNameAvailabilityClient.Execute` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := checkscopednameavailability.CheckScopedNameAvailabilityRequest{ + // ... +} + + +read, err := client.Execute(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/devcenter/2024-02-01/checkscopednameavailability/client.go b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/client.go new file mode 100644 index 00000000000..83d5b1b41e0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/client.go @@ -0,0 +1,26 @@ +package checkscopednameavailability + +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 CheckScopedNameAvailabilityClient struct { + Client *resourcemanager.Client +} + +func NewCheckScopedNameAvailabilityClientWithBaseURI(sdkApi sdkEnv.Api) (*CheckScopedNameAvailabilityClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "checkscopednameavailability", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CheckScopedNameAvailabilityClient: %+v", err) + } + + return &CheckScopedNameAvailabilityClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/checkscopednameavailability/constants.go b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/constants.go new file mode 100644 index 00000000000..b1a4fe731d0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/constants.go @@ -0,0 +1,51 @@ +package checkscopednameavailability + +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 CheckNameAvailabilityReason string + +const ( + CheckNameAvailabilityReasonAlreadyExists CheckNameAvailabilityReason = "AlreadyExists" + CheckNameAvailabilityReasonInvalid CheckNameAvailabilityReason = "Invalid" +) + +func PossibleValuesForCheckNameAvailabilityReason() []string { + return []string{ + string(CheckNameAvailabilityReasonAlreadyExists), + string(CheckNameAvailabilityReasonInvalid), + } +} + +func (s *CheckNameAvailabilityReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCheckNameAvailabilityReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCheckNameAvailabilityReason(input string) (*CheckNameAvailabilityReason, error) { + vals := map[string]CheckNameAvailabilityReason{ + "alreadyexists": CheckNameAvailabilityReasonAlreadyExists, + "invalid": CheckNameAvailabilityReasonInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CheckNameAvailabilityReason(input) + return &out, nil +} diff --git a/resource-manager/devcenter/2024-02-01/checkscopednameavailability/method_execute.go b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/method_execute.go new file mode 100644 index 00000000000..deafd6e2c3d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/method_execute.go @@ -0,0 +1,60 @@ +package checkscopednameavailability + +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 ExecuteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityResponse +} + +// Execute ... +func (c CheckScopedNameAvailabilityClient) Execute(ctx context.Context, id commonids.SubscriptionId, input CheckScopedNameAvailabilityRequest) (result ExecuteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.DevCenter/checkScopedNameAvailability", 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 CheckNameAvailabilityResponse + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/checkscopednameavailability/model_checknameavailabilityresponse.go b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/model_checknameavailabilityresponse.go new file mode 100644 index 00000000000..7822b59260d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/model_checknameavailabilityresponse.go @@ -0,0 +1,10 @@ +package checkscopednameavailability + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResponse struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *CheckNameAvailabilityReason `json:"reason,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/checkscopednameavailability/model_checkscopednameavailabilityrequest.go b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/model_checkscopednameavailabilityrequest.go new file mode 100644 index 00000000000..9ba9a103059 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/model_checkscopednameavailabilityrequest.go @@ -0,0 +1,10 @@ +package checkscopednameavailability + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckScopedNameAvailabilityRequest struct { + Name *string `json:"name,omitempty"` + Scope *string `json:"scope,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/checkscopednameavailability/version.go b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/version.go new file mode 100644 index 00000000000..32cadc4b7d7 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/checkscopednameavailability/version.go @@ -0,0 +1,12 @@ +package checkscopednameavailability + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/checkscopednameavailability/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/client.go b/resource-manager/devcenter/2024-02-01/client.go new file mode 100644 index 00000000000..9fe0227b691 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/client.go @@ -0,0 +1,190 @@ +package v2024_02_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/devcenter/2024-02-01/attachednetworkconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/catalogs" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/checknameavailability" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/checkscopednameavailability" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/devboxdefinitions" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/devcenters" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/environmentdefinitions" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/environmenttypes" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/galleries" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/images" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/imageversions" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/networkconnection" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/networkconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/pools" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/projectcatalogs" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/projects" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/schedules" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/skus" + "github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/usages" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + AttachedNetworkConnections *attachednetworkconnections.AttachedNetworkConnectionsClient + Catalogs *catalogs.CatalogsClient + CheckNameAvailability *checknameavailability.CheckNameAvailabilityClient + CheckScopedNameAvailability *checkscopednameavailability.CheckScopedNameAvailabilityClient + DevBoxDefinitions *devboxdefinitions.DevBoxDefinitionsClient + DevCenters *devcenters.DevCentersClient + EnvironmentDefinitions *environmentdefinitions.EnvironmentDefinitionsClient + EnvironmentTypes *environmenttypes.EnvironmentTypesClient + Galleries *galleries.GalleriesClient + ImageVersions *imageversions.ImageVersionsClient + Images *images.ImagesClient + NetworkConnection *networkconnection.NetworkConnectionClient + NetworkConnections *networkconnections.NetworkConnectionsClient + Pools *pools.PoolsClient + ProjectCatalogs *projectcatalogs.ProjectCatalogsClient + Projects *projects.ProjectsClient + SKUs *skus.SKUsClient + Schedules *schedules.SchedulesClient + Usages *usages.UsagesClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + attachedNetworkConnectionsClient, err := attachednetworkconnections.NewAttachedNetworkConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AttachedNetworkConnections client: %+v", err) + } + configureFunc(attachedNetworkConnectionsClient.Client) + + catalogsClient, err := catalogs.NewCatalogsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Catalogs client: %+v", err) + } + configureFunc(catalogsClient.Client) + + checkNameAvailabilityClient, err := checknameavailability.NewCheckNameAvailabilityClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CheckNameAvailability client: %+v", err) + } + configureFunc(checkNameAvailabilityClient.Client) + + checkScopedNameAvailabilityClient, err := checkscopednameavailability.NewCheckScopedNameAvailabilityClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CheckScopedNameAvailability client: %+v", err) + } + configureFunc(checkScopedNameAvailabilityClient.Client) + + devBoxDefinitionsClient, err := devboxdefinitions.NewDevBoxDefinitionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DevBoxDefinitions client: %+v", err) + } + configureFunc(devBoxDefinitionsClient.Client) + + devCentersClient, err := devcenters.NewDevCentersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building DevCenters client: %+v", err) + } + configureFunc(devCentersClient.Client) + + environmentDefinitionsClient, err := environmentdefinitions.NewEnvironmentDefinitionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EnvironmentDefinitions client: %+v", err) + } + configureFunc(environmentDefinitionsClient.Client) + + environmentTypesClient, err := environmenttypes.NewEnvironmentTypesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EnvironmentTypes client: %+v", err) + } + configureFunc(environmentTypesClient.Client) + + galleriesClient, err := galleries.NewGalleriesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Galleries client: %+v", err) + } + configureFunc(galleriesClient.Client) + + imageVersionsClient, err := imageversions.NewImageVersionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ImageVersions client: %+v", err) + } + configureFunc(imageVersionsClient.Client) + + imagesClient, err := images.NewImagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Images client: %+v", err) + } + configureFunc(imagesClient.Client) + + networkConnectionClient, err := networkconnection.NewNetworkConnectionClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NetworkConnection client: %+v", err) + } + configureFunc(networkConnectionClient.Client) + + networkConnectionsClient, err := networkconnections.NewNetworkConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building NetworkConnections client: %+v", err) + } + configureFunc(networkConnectionsClient.Client) + + poolsClient, err := pools.NewPoolsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Pools client: %+v", err) + } + configureFunc(poolsClient.Client) + + projectCatalogsClient, err := projectcatalogs.NewProjectCatalogsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ProjectCatalogs client: %+v", err) + } + configureFunc(projectCatalogsClient.Client) + + projectsClient, err := projects.NewProjectsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Projects client: %+v", err) + } + configureFunc(projectsClient.Client) + + sKUsClient, err := skus.NewSKUsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SKUs client: %+v", err) + } + configureFunc(sKUsClient.Client) + + schedulesClient, err := schedules.NewSchedulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Schedules client: %+v", err) + } + configureFunc(schedulesClient.Client) + + usagesClient, err := usages.NewUsagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Usages client: %+v", err) + } + configureFunc(usagesClient.Client) + + return &Client{ + AttachedNetworkConnections: attachedNetworkConnectionsClient, + Catalogs: catalogsClient, + CheckNameAvailability: checkNameAvailabilityClient, + CheckScopedNameAvailability: checkScopedNameAvailabilityClient, + DevBoxDefinitions: devBoxDefinitionsClient, + DevCenters: devCentersClient, + EnvironmentDefinitions: environmentDefinitionsClient, + EnvironmentTypes: environmentTypesClient, + Galleries: galleriesClient, + ImageVersions: imageVersionsClient, + Images: imagesClient, + NetworkConnection: networkConnectionClient, + NetworkConnections: networkConnectionsClient, + Pools: poolsClient, + ProjectCatalogs: projectCatalogsClient, + Projects: projectsClient, + SKUs: sKUsClient, + Schedules: schedulesClient, + Usages: usagesClient, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/README.md b/resource-manager/devcenter/2024-02-01/devboxdefinitions/README.md new file mode 100644 index 00000000000..f2d8bbe1c00 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/README.md @@ -0,0 +1,132 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/devboxdefinitions` Documentation + +The `devboxdefinitions` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/devboxdefinitions" +``` + + +### Client Initialization + +```go +client := devboxdefinitions.NewDevBoxDefinitionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DevBoxDefinitionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := devboxdefinitions.NewDevCenterDevBoxDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "devBoxDefinitionValue") + +payload := devboxdefinitions.DevBoxDefinition{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DevBoxDefinitionsClient.Delete` + +```go +ctx := context.TODO() +id := devboxdefinitions.NewDevCenterDevBoxDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "devBoxDefinitionValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DevBoxDefinitionsClient.Get` + +```go +ctx := context.TODO() +id := devboxdefinitions.NewDevCenterDevBoxDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "devBoxDefinitionValue") + +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: `DevBoxDefinitionsClient.GetByProject` + +```go +ctx := context.TODO() +id := devboxdefinitions.NewDevBoxDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "devBoxDefinitionValue") + +read, err := client.GetByProject(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DevBoxDefinitionsClient.ListByDevCenter` + +```go +ctx := context.TODO() +id := devboxdefinitions.NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + +// alternatively `client.ListByDevCenter(ctx, id)` can be used to do batched pagination +items, err := client.ListByDevCenterComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevBoxDefinitionsClient.ListByProject` + +```go +ctx := context.TODO() +id := devboxdefinitions.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + +// alternatively `client.ListByProject(ctx, id)` can be used to do batched pagination +items, err := client.ListByProjectComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevBoxDefinitionsClient.Update` + +```go +ctx := context.TODO() +id := devboxdefinitions.NewDevCenterDevBoxDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "devBoxDefinitionValue") + +payload := devboxdefinitions.DevBoxDefinitionUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/client.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/client.go new file mode 100644 index 00000000000..42eb06cd579 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/client.go @@ -0,0 +1,26 @@ +package devboxdefinitions + +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 DevBoxDefinitionsClient struct { + Client *resourcemanager.Client +} + +func NewDevBoxDefinitionsClientWithBaseURI(sdkApi sdkEnv.Api) (*DevBoxDefinitionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "devboxdefinitions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DevBoxDefinitionsClient: %+v", err) + } + + return &DevBoxDefinitionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/constants.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/constants.go new file mode 100644 index 00000000000..2f3c99b0d9e --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/constants.go @@ -0,0 +1,278 @@ +package devboxdefinitions + +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 CatalogResourceValidationStatus string + +const ( + CatalogResourceValidationStatusFailed CatalogResourceValidationStatus = "Failed" + CatalogResourceValidationStatusPending CatalogResourceValidationStatus = "Pending" + CatalogResourceValidationStatusSucceeded CatalogResourceValidationStatus = "Succeeded" + CatalogResourceValidationStatusUnknown CatalogResourceValidationStatus = "Unknown" +) + +func PossibleValuesForCatalogResourceValidationStatus() []string { + return []string{ + string(CatalogResourceValidationStatusFailed), + string(CatalogResourceValidationStatusPending), + string(CatalogResourceValidationStatusSucceeded), + string(CatalogResourceValidationStatusUnknown), + } +} + +func (s *CatalogResourceValidationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogResourceValidationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogResourceValidationStatus(input string) (*CatalogResourceValidationStatus, error) { + vals := map[string]CatalogResourceValidationStatus{ + "failed": CatalogResourceValidationStatusFailed, + "pending": CatalogResourceValidationStatusPending, + "succeeded": CatalogResourceValidationStatusSucceeded, + "unknown": CatalogResourceValidationStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogResourceValidationStatus(input) + return &out, nil +} + +type HibernateSupport string + +const ( + HibernateSupportDisabled HibernateSupport = "Disabled" + HibernateSupportEnabled HibernateSupport = "Enabled" +) + +func PossibleValuesForHibernateSupport() []string { + return []string{ + string(HibernateSupportDisabled), + string(HibernateSupportEnabled), + } +} + +func (s *HibernateSupport) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHibernateSupport(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHibernateSupport(input string) (*HibernateSupport, error) { + vals := map[string]HibernateSupport{ + "disabled": HibernateSupportDisabled, + "enabled": HibernateSupportEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HibernateSupport(input) + return &out, nil +} + +type ImageValidationStatus string + +const ( + ImageValidationStatusFailed ImageValidationStatus = "Failed" + ImageValidationStatusPending ImageValidationStatus = "Pending" + ImageValidationStatusSucceeded ImageValidationStatus = "Succeeded" + ImageValidationStatusTimedOut ImageValidationStatus = "TimedOut" + ImageValidationStatusUnknown ImageValidationStatus = "Unknown" +) + +func PossibleValuesForImageValidationStatus() []string { + return []string{ + string(ImageValidationStatusFailed), + string(ImageValidationStatusPending), + string(ImageValidationStatusSucceeded), + string(ImageValidationStatusTimedOut), + string(ImageValidationStatusUnknown), + } +} + +func (s *ImageValidationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseImageValidationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseImageValidationStatus(input string) (*ImageValidationStatus, error) { + vals := map[string]ImageValidationStatus{ + "failed": ImageValidationStatusFailed, + "pending": ImageValidationStatusPending, + "succeeded": ImageValidationStatusSucceeded, + "timedout": ImageValidationStatusTimedOut, + "unknown": ImageValidationStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ImageValidationStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMovingResources ProvisioningState = "MovingResources" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateRolloutInProgress ProvisioningState = "RolloutInProgress" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateStorageProvisioningFailed ProvisioningState = "StorageProvisioningFailed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateTransientFailure ProvisioningState = "TransientFailure" + ProvisioningStateUpdated ProvisioningState = "Updated" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMovingResources), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateRolloutInProgress), + string(ProvisioningStateRunning), + string(ProvisioningStateStorageProvisioningFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateTransientFailure), + string(ProvisioningStateUpdated), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "movingresources": ProvisioningStateMovingResources, + "notspecified": ProvisioningStateNotSpecified, + "rolloutinprogress": ProvisioningStateRolloutInProgress, + "running": ProvisioningStateRunning, + "storageprovisioningfailed": ProvisioningStateStorageProvisioningFailed, + "succeeded": ProvisioningStateSucceeded, + "transientfailure": ProvisioningStateTransientFailure, + "updated": ProvisioningStateUpdated, + "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 SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierFree), + 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, + "free": SkuTierFree, + "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 +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devboxdefinition.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devboxdefinition.go new file mode 100644 index 00000000000..21b42781bea --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devboxdefinition.go @@ -0,0 +1,134 @@ +package devboxdefinitions + +import ( + "fmt" + "strings" + + "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 = &DevBoxDefinitionId{} + +// DevBoxDefinitionId is a struct representing the Resource ID for a Dev Box Definition +type DevBoxDefinitionId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string + DevBoxDefinitionName string +} + +// NewDevBoxDefinitionID returns a new DevBoxDefinitionId struct +func NewDevBoxDefinitionID(subscriptionId string, resourceGroupName string, projectName string, devBoxDefinitionName string) DevBoxDefinitionId { + return DevBoxDefinitionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + DevBoxDefinitionName: devBoxDefinitionName, + } +} + +// ParseDevBoxDefinitionID parses 'input' into a DevBoxDefinitionId +func ParseDevBoxDefinitionID(input string) (*DevBoxDefinitionId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevBoxDefinitionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevBoxDefinitionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDevBoxDefinitionIDInsensitively parses 'input' case-insensitively into a DevBoxDefinitionId +// note: this method should only be used for API response data and not user input +func ParseDevBoxDefinitionIDInsensitively(input string) (*DevBoxDefinitionId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevBoxDefinitionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevBoxDefinitionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DevBoxDefinitionId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + if id.DevBoxDefinitionName, ok = input.Parsed["devBoxDefinitionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devBoxDefinitionName", input) + } + + return nil +} + +// ValidateDevBoxDefinitionID checks that 'input' can be parsed as a Dev Box Definition ID +func ValidateDevBoxDefinitionID(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 := ParseDevBoxDefinitionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dev Box Definition ID +func (id DevBoxDefinitionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s/devBoxDefinitions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName, id.DevBoxDefinitionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dev Box Definition ID +func (id DevBoxDefinitionId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + resourceids.StaticSegment("staticDevBoxDefinitions", "devBoxDefinitions", "devBoxDefinitions"), + resourceids.UserSpecifiedSegment("devBoxDefinitionName", "devBoxDefinitionValue"), + } +} + +// String returns a human-readable description of this Dev Box Definition ID +func (id DevBoxDefinitionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + fmt.Sprintf("Dev Box Definition Name: %q", id.DevBoxDefinitionName), + } + return fmt.Sprintf("Dev Box Definition (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devboxdefinition_test.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devboxdefinition_test.go new file mode 100644 index 00000000000..da326372d24 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devboxdefinition_test.go @@ -0,0 +1,327 @@ +package devboxdefinitions + +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 = &DevBoxDefinitionId{} + +func TestNewDevBoxDefinitionID(t *testing.T) { + id := NewDevBoxDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "devBoxDefinitionValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } + + if id.DevBoxDefinitionName != "devBoxDefinitionValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevBoxDefinitionName'", id.DevBoxDefinitionName, "devBoxDefinitionValue") + } +} + +func TestFormatDevBoxDefinitionID(t *testing.T) { + actual := NewDevBoxDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "devBoxDefinitionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/devBoxDefinitions/devBoxDefinitionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDevBoxDefinitionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevBoxDefinitionId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/devBoxDefinitions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/devBoxDefinitions/devBoxDefinitionValue", + Expected: &DevBoxDefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + DevBoxDefinitionName: "devBoxDefinitionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/devBoxDefinitions/devBoxDefinitionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevBoxDefinitionID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.DevBoxDefinitionName != v.Expected.DevBoxDefinitionName { + t.Fatalf("Expected %q but got %q for DevBoxDefinitionName", v.Expected.DevBoxDefinitionName, actual.DevBoxDefinitionName) + } + + } +} + +func TestParseDevBoxDefinitionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevBoxDefinitionId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/devBoxDefinitions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/dEvBoXdEfInItIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/devBoxDefinitions/devBoxDefinitionValue", + Expected: &DevBoxDefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + DevBoxDefinitionName: "devBoxDefinitionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/devBoxDefinitions/devBoxDefinitionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/dEvBoXdEfInItIoNs/dEvBoXdEfInItIoNvAlUe", + Expected: &DevBoxDefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + DevBoxDefinitionName: "dEvBoXdEfInItIoNvAlUe", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/dEvBoXdEfInItIoNs/dEvBoXdEfInItIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevBoxDefinitionIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.DevBoxDefinitionName != v.Expected.DevBoxDefinitionName { + t.Fatalf("Expected %q but got %q for DevBoxDefinitionName", v.Expected.DevBoxDefinitionName, actual.DevBoxDefinitionName) + } + + } +} + +func TestSegmentsForDevBoxDefinitionId(t *testing.T) { + segments := DevBoxDefinitionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DevBoxDefinitionId 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/devcenter/2024-02-01/devboxdefinitions/id_devcenter.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenter.go new file mode 100644 index 00000000000..7ab6a3fbc7e --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenter.go @@ -0,0 +1,125 @@ +package devboxdefinitions + +import ( + "fmt" + "strings" + + "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 = &DevCenterId{} + +// DevCenterId is a struct representing the Resource ID for a Dev Center +type DevCenterId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string +} + +// NewDevCenterID returns a new DevCenterId struct +func NewDevCenterID(subscriptionId string, resourceGroupName string, devCenterName string) DevCenterId { + return DevCenterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + } +} + +// ParseDevCenterID parses 'input' into a DevCenterId +func ParseDevCenterID(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDevCenterIDInsensitively parses 'input' case-insensitively into a DevCenterId +// note: this method should only be used for API response data and not user input +func ParseDevCenterIDInsensitively(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DevCenterId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + return nil +} + +// ValidateDevCenterID checks that 'input' can be parsed as a Dev Center ID +func ValidateDevCenterID(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 := ParseDevCenterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dev Center ID +func (id DevCenterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dev Center ID +func (id DevCenterId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + } +} + +// String returns a human-readable description of this Dev Center ID +func (id DevCenterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + } + return fmt.Sprintf("Dev Center (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenter_test.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenter_test.go new file mode 100644 index 00000000000..54d097040f2 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenter_test.go @@ -0,0 +1,282 @@ +package devboxdefinitions + +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 = &DevCenterId{} + +func TestNewDevCenterID(t *testing.T) { + id := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } +} + +func TestFormatDevCenterID(t *testing.T) { + actual := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDevCenterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestParseDevCenterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestSegmentsForDevCenterId(t *testing.T) { + segments := DevCenterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DevCenterId 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/devcenter/2024-02-01/devboxdefinitions/id_devcenterdevboxdefinition.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenterdevboxdefinition.go new file mode 100644 index 00000000000..9cf420f1acb --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenterdevboxdefinition.go @@ -0,0 +1,134 @@ +package devboxdefinitions + +import ( + "fmt" + "strings" + + "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 = &DevCenterDevBoxDefinitionId{} + +// DevCenterDevBoxDefinitionId is a struct representing the Resource ID for a Dev Center Dev Box Definition +type DevCenterDevBoxDefinitionId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string + DevBoxDefinitionName string +} + +// NewDevCenterDevBoxDefinitionID returns a new DevCenterDevBoxDefinitionId struct +func NewDevCenterDevBoxDefinitionID(subscriptionId string, resourceGroupName string, devCenterName string, devBoxDefinitionName string) DevCenterDevBoxDefinitionId { + return DevCenterDevBoxDefinitionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + DevBoxDefinitionName: devBoxDefinitionName, + } +} + +// ParseDevCenterDevBoxDefinitionID parses 'input' into a DevCenterDevBoxDefinitionId +func ParseDevCenterDevBoxDefinitionID(input string) (*DevCenterDevBoxDefinitionId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterDevBoxDefinitionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterDevBoxDefinitionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDevCenterDevBoxDefinitionIDInsensitively parses 'input' case-insensitively into a DevCenterDevBoxDefinitionId +// note: this method should only be used for API response data and not user input +func ParseDevCenterDevBoxDefinitionIDInsensitively(input string) (*DevCenterDevBoxDefinitionId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterDevBoxDefinitionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterDevBoxDefinitionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DevCenterDevBoxDefinitionId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + if id.DevBoxDefinitionName, ok = input.Parsed["devBoxDefinitionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devBoxDefinitionName", input) + } + + return nil +} + +// ValidateDevCenterDevBoxDefinitionID checks that 'input' can be parsed as a Dev Center Dev Box Definition ID +func ValidateDevCenterDevBoxDefinitionID(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 := ParseDevCenterDevBoxDefinitionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dev Center Dev Box Definition ID +func (id DevCenterDevBoxDefinitionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s/devBoxDefinitions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName, id.DevBoxDefinitionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dev Center Dev Box Definition ID +func (id DevCenterDevBoxDefinitionId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + resourceids.StaticSegment("staticDevBoxDefinitions", "devBoxDefinitions", "devBoxDefinitions"), + resourceids.UserSpecifiedSegment("devBoxDefinitionName", "devBoxDefinitionValue"), + } +} + +// String returns a human-readable description of this Dev Center Dev Box Definition ID +func (id DevCenterDevBoxDefinitionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + fmt.Sprintf("Dev Box Definition Name: %q", id.DevBoxDefinitionName), + } + return fmt.Sprintf("Dev Center Dev Box Definition (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenterdevboxdefinition_test.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenterdevboxdefinition_test.go new file mode 100644 index 00000000000..b41b7ebd6b0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_devcenterdevboxdefinition_test.go @@ -0,0 +1,327 @@ +package devboxdefinitions + +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 = &DevCenterDevBoxDefinitionId{} + +func TestNewDevCenterDevBoxDefinitionID(t *testing.T) { + id := NewDevCenterDevBoxDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "devBoxDefinitionValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } + + if id.DevBoxDefinitionName != "devBoxDefinitionValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevBoxDefinitionName'", id.DevBoxDefinitionName, "devBoxDefinitionValue") + } +} + +func TestFormatDevCenterDevBoxDefinitionID(t *testing.T) { + actual := NewDevCenterDevBoxDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "devBoxDefinitionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/devBoxDefinitions/devBoxDefinitionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDevCenterDevBoxDefinitionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterDevBoxDefinitionId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/devBoxDefinitions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/devBoxDefinitions/devBoxDefinitionValue", + Expected: &DevCenterDevBoxDefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + DevBoxDefinitionName: "devBoxDefinitionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/devBoxDefinitions/devBoxDefinitionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterDevBoxDefinitionID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.DevBoxDefinitionName != v.Expected.DevBoxDefinitionName { + t.Fatalf("Expected %q but got %q for DevBoxDefinitionName", v.Expected.DevBoxDefinitionName, actual.DevBoxDefinitionName) + } + + } +} + +func TestParseDevCenterDevBoxDefinitionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterDevBoxDefinitionId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/devBoxDefinitions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/dEvBoXdEfInItIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/devBoxDefinitions/devBoxDefinitionValue", + Expected: &DevCenterDevBoxDefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + DevBoxDefinitionName: "devBoxDefinitionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/devBoxDefinitions/devBoxDefinitionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/dEvBoXdEfInItIoNs/dEvBoXdEfInItIoNvAlUe", + Expected: &DevCenterDevBoxDefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + DevBoxDefinitionName: "dEvBoXdEfInItIoNvAlUe", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/dEvBoXdEfInItIoNs/dEvBoXdEfInItIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterDevBoxDefinitionIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.DevBoxDefinitionName != v.Expected.DevBoxDefinitionName { + t.Fatalf("Expected %q but got %q for DevBoxDefinitionName", v.Expected.DevBoxDefinitionName, actual.DevBoxDefinitionName) + } + + } +} + +func TestSegmentsForDevCenterDevBoxDefinitionId(t *testing.T) { + segments := DevCenterDevBoxDefinitionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DevCenterDevBoxDefinitionId 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/devcenter/2024-02-01/devboxdefinitions/id_project.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_project.go new file mode 100644 index 00000000000..07d072f3372 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_project.go @@ -0,0 +1,125 @@ +package devboxdefinitions + +import ( + "fmt" + "strings" + + "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 = &ProjectId{} + +// ProjectId is a struct representing the Resource ID for a Project +type ProjectId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string +} + +// NewProjectID returns a new ProjectId struct +func NewProjectID(subscriptionId string, resourceGroupName string, projectName string) ProjectId { + return ProjectId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + } +} + +// ParseProjectID parses 'input' into a ProjectId +func ParseProjectID(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProjectIDInsensitively parses 'input' case-insensitively into a ProjectId +// note: this method should only be used for API response data and not user input +func ParseProjectIDInsensitively(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProjectId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + return nil +} + +// ValidateProjectID checks that 'input' can be parsed as a Project ID +func ValidateProjectID(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 := ParseProjectID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Project ID +func (id ProjectId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Project ID +func (id ProjectId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + } +} + +// String returns a human-readable description of this Project ID +func (id ProjectId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + } + return fmt.Sprintf("Project (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_project_test.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_project_test.go new file mode 100644 index 00000000000..0b7e18858fc --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/id_project_test.go @@ -0,0 +1,282 @@ +package devboxdefinitions + +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 = &ProjectId{} + +func TestNewProjectID(t *testing.T) { + id := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } +} + +func TestFormatProjectID(t *testing.T) { + actual := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProjectID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestParseProjectIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestSegmentsForProjectId(t *testing.T) { + segments := ProjectId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProjectId 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/devcenter/2024-02-01/devboxdefinitions/method_createorupdate.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_createorupdate.go new file mode 100644 index 00000000000..df7896a1f4f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_createorupdate.go @@ -0,0 +1,75 @@ +package devboxdefinitions + +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 *DevBoxDefinition +} + +// CreateOrUpdate ... +func (c DevBoxDefinitionsClient) CreateOrUpdate(ctx context.Context, id DevCenterDevBoxDefinitionId, input DevBoxDefinition) (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 DevBoxDefinitionsClient) CreateOrUpdateThenPoll(ctx context.Context, id DevCenterDevBoxDefinitionId, input DevBoxDefinition) 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/devcenter/2024-02-01/devboxdefinitions/method_delete.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_delete.go new file mode 100644 index 00000000000..795e45250d5 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_delete.go @@ -0,0 +1,70 @@ +package devboxdefinitions + +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 DevBoxDefinitionsClient) Delete(ctx context.Context, id DevCenterDevBoxDefinitionId) (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 DevBoxDefinitionsClient) DeleteThenPoll(ctx context.Context, id DevCenterDevBoxDefinitionId) 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/devcenter/2024-02-01/devboxdefinitions/method_get.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_get.go new file mode 100644 index 00000000000..4797f572dfe --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_get.go @@ -0,0 +1,54 @@ +package devboxdefinitions + +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 *DevBoxDefinition +} + +// Get ... +func (c DevBoxDefinitionsClient) Get(ctx context.Context, id DevCenterDevBoxDefinitionId) (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 DevBoxDefinition + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_getbyproject.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_getbyproject.go new file mode 100644 index 00000000000..1cc47c3e4ff --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_getbyproject.go @@ -0,0 +1,54 @@ +package devboxdefinitions + +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 GetByProjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DevBoxDefinition +} + +// GetByProject ... +func (c DevBoxDefinitionsClient) GetByProject(ctx context.Context, id DevBoxDefinitionId) (result GetByProjectOperationResponse, 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 DevBoxDefinition + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_listbydevcenter.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_listbydevcenter.go new file mode 100644 index 00000000000..36285df0db4 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_listbydevcenter.go @@ -0,0 +1,91 @@ +package devboxdefinitions + +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 ListByDevCenterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DevBoxDefinition +} + +type ListByDevCenterCompleteResult struct { + LatestHttpResponse *http.Response + Items []DevBoxDefinition +} + +// ListByDevCenter ... +func (c DevBoxDefinitionsClient) ListByDevCenter(ctx context.Context, id DevCenterId) (result ListByDevCenterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/devBoxDefinitions", 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 *[]DevBoxDefinition `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDevCenterComplete retrieves all the results into a single object +func (c DevBoxDefinitionsClient) ListByDevCenterComplete(ctx context.Context, id DevCenterId) (ListByDevCenterCompleteResult, error) { + return c.ListByDevCenterCompleteMatchingPredicate(ctx, id, DevBoxDefinitionOperationPredicate{}) +} + +// ListByDevCenterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevBoxDefinitionsClient) ListByDevCenterCompleteMatchingPredicate(ctx context.Context, id DevCenterId, predicate DevBoxDefinitionOperationPredicate) (result ListByDevCenterCompleteResult, err error) { + items := make([]DevBoxDefinition, 0) + + resp, err := c.ListByDevCenter(ctx, id) + if err != nil { + 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 = ListByDevCenterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_listbyproject.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_listbyproject.go new file mode 100644 index 00000000000..f584201347d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_listbyproject.go @@ -0,0 +1,91 @@ +package devboxdefinitions + +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 ListByProjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DevBoxDefinition +} + +type ListByProjectCompleteResult struct { + LatestHttpResponse *http.Response + Items []DevBoxDefinition +} + +// ListByProject ... +func (c DevBoxDefinitionsClient) ListByProject(ctx context.Context, id ProjectId) (result ListByProjectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/devBoxDefinitions", 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 *[]DevBoxDefinition `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProjectComplete retrieves all the results into a single object +func (c DevBoxDefinitionsClient) ListByProjectComplete(ctx context.Context, id ProjectId) (ListByProjectCompleteResult, error) { + return c.ListByProjectCompleteMatchingPredicate(ctx, id, DevBoxDefinitionOperationPredicate{}) +} + +// ListByProjectCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevBoxDefinitionsClient) ListByProjectCompleteMatchingPredicate(ctx context.Context, id ProjectId, predicate DevBoxDefinitionOperationPredicate) (result ListByProjectCompleteResult, err error) { + items := make([]DevBoxDefinition, 0) + + resp, err := c.ListByProject(ctx, id) + if err != nil { + 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 = ListByProjectCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_update.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_update.go new file mode 100644 index 00000000000..0583fce3a95 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/method_update.go @@ -0,0 +1,75 @@ +package devboxdefinitions + +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 *DevBoxDefinition +} + +// Update ... +func (c DevBoxDefinitionsClient) Update(ctx context.Context, id DevCenterDevBoxDefinitionId, input DevBoxDefinitionUpdate) (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 DevBoxDefinitionsClient) UpdateThenPoll(ctx context.Context, id DevCenterDevBoxDefinitionId, input DevBoxDefinitionUpdate) 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/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinition.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinition.go new file mode 100644 index 00000000000..b2741fc5422 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinition.go @@ -0,0 +1,18 @@ +package devboxdefinitions + +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 DevBoxDefinition struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *DevBoxDefinitionProperties `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/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinitionproperties.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinitionproperties.go new file mode 100644 index 00000000000..4bf54857262 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinitionproperties.go @@ -0,0 +1,16 @@ +package devboxdefinitions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DevBoxDefinitionProperties struct { + ActiveImageReference *ImageReference `json:"activeImageReference,omitempty"` + HibernateSupport *HibernateSupport `json:"hibernateSupport,omitempty"` + ImageReference *ImageReference `json:"imageReference,omitempty"` + ImageValidationErrorDetails *ImageValidationErrorDetails `json:"imageValidationErrorDetails,omitempty"` + ImageValidationStatus *ImageValidationStatus `json:"imageValidationStatus,omitempty"` + OsStorageType *string `json:"osStorageType,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + Sku *Sku `json:"sku,omitempty"` + ValidationStatus *CatalogResourceValidationStatus `json:"validationStatus,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinitionupdate.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinitionupdate.go new file mode 100644 index 00000000000..b2869a10abf --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinitionupdate.go @@ -0,0 +1,10 @@ +package devboxdefinitions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DevBoxDefinitionUpdate struct { + Location *string `json:"location,omitempty"` + Properties *DevBoxDefinitionUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinitionupdateproperties.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinitionupdateproperties.go new file mode 100644 index 00000000000..fc0a59c4ac6 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_devboxdefinitionupdateproperties.go @@ -0,0 +1,11 @@ +package devboxdefinitions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DevBoxDefinitionUpdateProperties struct { + HibernateSupport *HibernateSupport `json:"hibernateSupport,omitempty"` + ImageReference *ImageReference `json:"imageReference,omitempty"` + OsStorageType *string `json:"osStorageType,omitempty"` + Sku *Sku `json:"sku,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_imagereference.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_imagereference.go new file mode 100644 index 00000000000..141cbfc3ce4 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_imagereference.go @@ -0,0 +1,9 @@ +package devboxdefinitions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImageReference struct { + ExactVersion *string `json:"exactVersion,omitempty"` + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_imagevalidationerrordetails.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_imagevalidationerrordetails.go new file mode 100644 index 00000000000..1dce4adcbaa --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_imagevalidationerrordetails.go @@ -0,0 +1,9 @@ +package devboxdefinitions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImageValidationErrorDetails struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_sku.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_sku.go new file mode 100644 index 00000000000..76a348c8d14 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/model_sku.go @@ -0,0 +1,12 @@ +package devboxdefinitions + +// 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"` + Family *string `json:"family,omitempty"` + Name string `json:"name"` + Size *string `json:"size,omitempty"` + Tier *SkuTier `json:"tier,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/devboxdefinitions/predicates.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/predicates.go new file mode 100644 index 00000000000..3b9b533b894 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/predicates.go @@ -0,0 +1,32 @@ +package devboxdefinitions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DevBoxDefinitionOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p DevBoxDefinitionOperationPredicate) Matches(input DevBoxDefinition) 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/devcenter/2024-02-01/devboxdefinitions/version.go b/resource-manager/devcenter/2024-02-01/devboxdefinitions/version.go new file mode 100644 index 00000000000..a0f0b3ede0f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devboxdefinitions/version.go @@ -0,0 +1,12 @@ +package devboxdefinitions + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/devboxdefinitions/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/devcenters/README.md b/resource-manager/devcenter/2024-02-01/devcenters/README.md new file mode 100644 index 00000000000..2e83f67ffa9 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/devcenters` Documentation + +The `devcenters` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/devcenters" +``` + + +### Client Initialization + +```go +client := devcenters.NewDevCentersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DevCentersClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := devcenters.NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + +payload := devcenters.DevCenter{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DevCentersClient.Delete` + +```go +ctx := context.TODO() +id := devcenters.NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DevCentersClient.Get` + +```go +ctx := context.TODO() +id := devcenters.NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + +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: `DevCentersClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, devcenters.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, devcenters.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevCentersClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id, devcenters.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, devcenters.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DevCentersClient.Update` + +```go +ctx := context.TODO() +id := devcenters.NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + +payload := devcenters.DevCenterUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/devcenter/2024-02-01/devcenters/client.go b/resource-manager/devcenter/2024-02-01/devcenters/client.go new file mode 100644 index 00000000000..166e4043995 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/client.go @@ -0,0 +1,26 @@ +package devcenters + +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 DevCentersClient struct { + Client *resourcemanager.Client +} + +func NewDevCentersClientWithBaseURI(sdkApi sdkEnv.Api) (*DevCentersClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "devcenters", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DevCentersClient: %+v", err) + } + + return &DevCentersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/devcenters/constants.go b/resource-manager/devcenter/2024-02-01/devcenters/constants.go new file mode 100644 index 00000000000..c23d8205268 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/constants.go @@ -0,0 +1,178 @@ +package devcenters + +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 CatalogItemSyncEnableStatus string + +const ( + CatalogItemSyncEnableStatusDisabled CatalogItemSyncEnableStatus = "Disabled" + CatalogItemSyncEnableStatusEnabled CatalogItemSyncEnableStatus = "Enabled" +) + +func PossibleValuesForCatalogItemSyncEnableStatus() []string { + return []string{ + string(CatalogItemSyncEnableStatusDisabled), + string(CatalogItemSyncEnableStatusEnabled), + } +} + +func (s *CatalogItemSyncEnableStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogItemSyncEnableStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogItemSyncEnableStatus(input string) (*CatalogItemSyncEnableStatus, error) { + vals := map[string]CatalogItemSyncEnableStatus{ + "disabled": CatalogItemSyncEnableStatusDisabled, + "enabled": CatalogItemSyncEnableStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogItemSyncEnableStatus(input) + return &out, nil +} + +type IdentityType string + +const ( + IdentityTypeDelegatedResourceIdentity IdentityType = "delegatedResourceIdentity" + IdentityTypeSystemAssignedIdentity IdentityType = "systemAssignedIdentity" + IdentityTypeUserAssignedIdentity IdentityType = "userAssignedIdentity" +) + +func PossibleValuesForIdentityType() []string { + return []string{ + string(IdentityTypeDelegatedResourceIdentity), + string(IdentityTypeSystemAssignedIdentity), + string(IdentityTypeUserAssignedIdentity), + } +} + +func (s *IdentityType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseIdentityType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseIdentityType(input string) (*IdentityType, error) { + vals := map[string]IdentityType{ + "delegatedresourceidentity": IdentityTypeDelegatedResourceIdentity, + "systemassignedidentity": IdentityTypeSystemAssignedIdentity, + "userassignedidentity": IdentityTypeUserAssignedIdentity, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IdentityType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMovingResources ProvisioningState = "MovingResources" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateRolloutInProgress ProvisioningState = "RolloutInProgress" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateStorageProvisioningFailed ProvisioningState = "StorageProvisioningFailed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateTransientFailure ProvisioningState = "TransientFailure" + ProvisioningStateUpdated ProvisioningState = "Updated" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMovingResources), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateRolloutInProgress), + string(ProvisioningStateRunning), + string(ProvisioningStateStorageProvisioningFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateTransientFailure), + string(ProvisioningStateUpdated), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "movingresources": ProvisioningStateMovingResources, + "notspecified": ProvisioningStateNotSpecified, + "rolloutinprogress": ProvisioningStateRolloutInProgress, + "running": ProvisioningStateRunning, + "storageprovisioningfailed": ProvisioningStateStorageProvisioningFailed, + "succeeded": ProvisioningStateSucceeded, + "transientfailure": ProvisioningStateTransientFailure, + "updated": ProvisioningStateUpdated, + "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/devcenter/2024-02-01/devcenters/id_devcenter.go b/resource-manager/devcenter/2024-02-01/devcenters/id_devcenter.go new file mode 100644 index 00000000000..d0da32966a9 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/id_devcenter.go @@ -0,0 +1,125 @@ +package devcenters + +import ( + "fmt" + "strings" + + "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 = &DevCenterId{} + +// DevCenterId is a struct representing the Resource ID for a Dev Center +type DevCenterId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string +} + +// NewDevCenterID returns a new DevCenterId struct +func NewDevCenterID(subscriptionId string, resourceGroupName string, devCenterName string) DevCenterId { + return DevCenterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + } +} + +// ParseDevCenterID parses 'input' into a DevCenterId +func ParseDevCenterID(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDevCenterIDInsensitively parses 'input' case-insensitively into a DevCenterId +// note: this method should only be used for API response data and not user input +func ParseDevCenterIDInsensitively(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DevCenterId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + return nil +} + +// ValidateDevCenterID checks that 'input' can be parsed as a Dev Center ID +func ValidateDevCenterID(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 := ParseDevCenterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dev Center ID +func (id DevCenterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dev Center ID +func (id DevCenterId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + } +} + +// String returns a human-readable description of this Dev Center ID +func (id DevCenterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + } + return fmt.Sprintf("Dev Center (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/devcenters/id_devcenter_test.go b/resource-manager/devcenter/2024-02-01/devcenters/id_devcenter_test.go new file mode 100644 index 00000000000..2dd37d19f31 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/id_devcenter_test.go @@ -0,0 +1,282 @@ +package devcenters + +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 = &DevCenterId{} + +func TestNewDevCenterID(t *testing.T) { + id := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } +} + +func TestFormatDevCenterID(t *testing.T) { + actual := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDevCenterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestParseDevCenterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestSegmentsForDevCenterId(t *testing.T) { + segments := DevCenterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DevCenterId 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/devcenter/2024-02-01/devcenters/method_createorupdate.go b/resource-manager/devcenter/2024-02-01/devcenters/method_createorupdate.go new file mode 100644 index 00000000000..df9478283f3 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/method_createorupdate.go @@ -0,0 +1,75 @@ +package devcenters + +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 *DevCenter +} + +// CreateOrUpdate ... +func (c DevCentersClient) CreateOrUpdate(ctx context.Context, id DevCenterId, input DevCenter) (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 DevCentersClient) CreateOrUpdateThenPoll(ctx context.Context, id DevCenterId, input DevCenter) 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/devcenter/2024-02-01/devcenters/method_delete.go b/resource-manager/devcenter/2024-02-01/devcenters/method_delete.go new file mode 100644 index 00000000000..763f788dcf1 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/method_delete.go @@ -0,0 +1,70 @@ +package devcenters + +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 DevCentersClient) Delete(ctx context.Context, id DevCenterId) (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 DevCentersClient) DeleteThenPoll(ctx context.Context, id DevCenterId) 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/devcenter/2024-02-01/devcenters/method_get.go b/resource-manager/devcenter/2024-02-01/devcenters/method_get.go new file mode 100644 index 00000000000..66374322581 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/method_get.go @@ -0,0 +1,54 @@ +package devcenters + +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 *DevCenter +} + +// Get ... +func (c DevCentersClient) Get(ctx context.Context, id DevCenterId) (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 DevCenter + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/devcenters/method_listbyresourcegroup.go b/resource-manager/devcenter/2024-02-01/devcenters/method_listbyresourcegroup.go new file mode 100644 index 00000000000..c52eb39da09 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/method_listbyresourcegroup.go @@ -0,0 +1,120 @@ +package devcenters + +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 *[]DevCenter +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []DevCenter +} + +type ListByResourceGroupOperationOptions struct { + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByResourceGroup ... +func (c DevCentersClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.DevCenter/devCenters", id.ID()), + OptionsObject: options, + } + + 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 *[]DevCenter `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 DevCentersClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, DevCenterOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevCentersClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate DevCenterOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]DevCenter, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + 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/devcenter/2024-02-01/devcenters/method_listbysubscription.go b/resource-manager/devcenter/2024-02-01/devcenters/method_listbysubscription.go new file mode 100644 index 00000000000..2e107e1fb13 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/method_listbysubscription.go @@ -0,0 +1,120 @@ +package devcenters + +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 *[]DevCenter +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []DevCenter +} + +type ListBySubscriptionOperationOptions struct { + Top *int64 +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListBySubscription ... +func (c DevCentersClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.DevCenter/devCenters", id.ID()), + OptionsObject: options, + } + + 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 *[]DevCenter `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 DevCentersClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, DevCenterOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DevCentersClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate DevCenterOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]DevCenter, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + 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/devcenter/2024-02-01/devcenters/method_update.go b/resource-manager/devcenter/2024-02-01/devcenters/method_update.go new file mode 100644 index 00000000000..83417e8b707 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/method_update.go @@ -0,0 +1,75 @@ +package devcenters + +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 *DevCenter +} + +// Update ... +func (c DevCentersClient) Update(ctx context.Context, id DevCenterId, input DevCenterUpdate) (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 DevCentersClient) UpdateThenPoll(ctx context.Context, id DevCenterId, input DevCenterUpdate) 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/devcenter/2024-02-01/devcenters/model_customermanagedkeyencryption.go b/resource-manager/devcenter/2024-02-01/devcenters/model_customermanagedkeyencryption.go new file mode 100644 index 00000000000..4b41a19c823 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/model_customermanagedkeyencryption.go @@ -0,0 +1,9 @@ +package devcenters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomerManagedKeyEncryption struct { + KeyEncryptionKeyIdentity *CustomerManagedKeyEncryptionKeyEncryptionKeyIdentity `json:"keyEncryptionKeyIdentity,omitempty"` + KeyEncryptionKeyUrl *string `json:"keyEncryptionKeyUrl,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/devcenters/model_customermanagedkeyencryptionkeyencryptionkeyidentity.go b/resource-manager/devcenter/2024-02-01/devcenters/model_customermanagedkeyencryptionkeyencryptionkeyidentity.go new file mode 100644 index 00000000000..8edd658099f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/model_customermanagedkeyencryptionkeyencryptionkeyidentity.go @@ -0,0 +1,10 @@ +package devcenters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomerManagedKeyEncryptionKeyEncryptionKeyIdentity struct { + DelegatedIdentityClientId *string `json:"delegatedIdentityClientId,omitempty"` + IdentityType *IdentityType `json:"identityType,omitempty"` + UserAssignedIdentityResourceId *string `json:"userAssignedIdentityResourceId,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/devcenters/model_devcenter.go b/resource-manager/devcenter/2024-02-01/devcenters/model_devcenter.go new file mode 100644 index 00000000000..a6ca99f8955 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/model_devcenter.go @@ -0,0 +1,20 @@ +package devcenters + +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 DevCenter struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *DevCenterProperties `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/devcenter/2024-02-01/devcenters/model_devcenterprojectcatalogsettings.go b/resource-manager/devcenter/2024-02-01/devcenters/model_devcenterprojectcatalogsettings.go new file mode 100644 index 00000000000..c85382fa7d8 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/model_devcenterprojectcatalogsettings.go @@ -0,0 +1,8 @@ +package devcenters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DevCenterProjectCatalogSettings struct { + CatalogItemSyncEnableStatus *CatalogItemSyncEnableStatus `json:"catalogItemSyncEnableStatus,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/devcenters/model_devcenterproperties.go b/resource-manager/devcenter/2024-02-01/devcenters/model_devcenterproperties.go new file mode 100644 index 00000000000..451dbe7b1a5 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/model_devcenterproperties.go @@ -0,0 +1,12 @@ +package devcenters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DevCenterProperties struct { + DevCenterUri *string `json:"devCenterUri,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Encryption *Encryption `json:"encryption,omitempty"` + ProjectCatalogSettings *DevCenterProjectCatalogSettings `json:"projectCatalogSettings,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/devcenters/model_devcenterupdate.go b/resource-manager/devcenter/2024-02-01/devcenters/model_devcenterupdate.go new file mode 100644 index 00000000000..3bfe9c89662 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/model_devcenterupdate.go @@ -0,0 +1,15 @@ +package devcenters + +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 DevCenterUpdate struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Properties *DevCenterUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/devcenters/model_devcenterupdateproperties.go b/resource-manager/devcenter/2024-02-01/devcenters/model_devcenterupdateproperties.go new file mode 100644 index 00000000000..6ce231ae430 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/model_devcenterupdateproperties.go @@ -0,0 +1,10 @@ +package devcenters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DevCenterUpdateProperties struct { + DisplayName *string `json:"displayName,omitempty"` + Encryption *Encryption `json:"encryption,omitempty"` + ProjectCatalogSettings *DevCenterProjectCatalogSettings `json:"projectCatalogSettings,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/devcenters/model_encryption.go b/resource-manager/devcenter/2024-02-01/devcenters/model_encryption.go new file mode 100644 index 00000000000..41a4fb33a6c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/model_encryption.go @@ -0,0 +1,8 @@ +package devcenters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Encryption struct { + CustomerManagedKeyEncryption *CustomerManagedKeyEncryption `json:"customerManagedKeyEncryption,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/devcenters/predicates.go b/resource-manager/devcenter/2024-02-01/devcenters/predicates.go new file mode 100644 index 00000000000..ff0eefcdfd6 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/predicates.go @@ -0,0 +1,32 @@ +package devcenters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DevCenterOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p DevCenterOperationPredicate) Matches(input DevCenter) 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/devcenter/2024-02-01/devcenters/version.go b/resource-manager/devcenter/2024-02-01/devcenters/version.go new file mode 100644 index 00000000000..a54f986004f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/devcenters/version.go @@ -0,0 +1,12 @@ +package devcenters + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/devcenters/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/README.md b/resource-manager/devcenter/2024-02-01/environmentdefinitions/README.md new file mode 100644 index 00000000000..a28a130d0c5 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/README.md @@ -0,0 +1,118 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/environmentdefinitions` Documentation + +The `environmentdefinitions` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/environmentdefinitions" +``` + + +### Client Initialization + +```go +client := environmentdefinitions.NewEnvironmentDefinitionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `EnvironmentDefinitionsClient.EnvironmentDefinitionsGet` + +```go +ctx := context.TODO() +id := environmentdefinitions.NewCatalogEnvironmentDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue", "environmentDefinitionValue") + +read, err := client.EnvironmentDefinitionsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EnvironmentDefinitionsClient.EnvironmentDefinitionsGetByProjectCatalog` + +```go +ctx := context.TODO() +id := environmentdefinitions.NewEnvironmentDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue", "environmentDefinitionValue") + +read, err := client.EnvironmentDefinitionsGetByProjectCatalog(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EnvironmentDefinitionsClient.EnvironmentDefinitionsGetErrorDetails` + +```go +ctx := context.TODO() +id := environmentdefinitions.NewCatalogEnvironmentDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue", "environmentDefinitionValue") + +read, err := client.EnvironmentDefinitionsGetErrorDetails(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EnvironmentDefinitionsClient.EnvironmentDefinitionsListByCatalog` + +```go +ctx := context.TODO() +id := environmentdefinitions.NewDevCenterCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue") + +// alternatively `client.EnvironmentDefinitionsListByCatalog(ctx, id, environmentdefinitions.DefaultEnvironmentDefinitionsListByCatalogOperationOptions())` can be used to do batched pagination +items, err := client.EnvironmentDefinitionsListByCatalogComplete(ctx, id, environmentdefinitions.DefaultEnvironmentDefinitionsListByCatalogOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EnvironmentDefinitionsClient.EnvironmentDefinitionsListByProjectCatalog` + +```go +ctx := context.TODO() +id := environmentdefinitions.NewCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue") + +// alternatively `client.EnvironmentDefinitionsListByProjectCatalog(ctx, id)` can be used to do batched pagination +items, err := client.EnvironmentDefinitionsListByProjectCatalogComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EnvironmentDefinitionsClient.ProjectCatalogEnvironmentDefinitionsGetErrorDetails` + +```go +ctx := context.TODO() +id := environmentdefinitions.NewEnvironmentDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue", "environmentDefinitionValue") + +read, err := client.ProjectCatalogEnvironmentDefinitionsGetErrorDetails(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/devcenter/2024-02-01/environmentdefinitions/client.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/client.go new file mode 100644 index 00000000000..696e8a84381 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/client.go @@ -0,0 +1,26 @@ +package environmentdefinitions + +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 EnvironmentDefinitionsClient struct { + Client *resourcemanager.Client +} + +func NewEnvironmentDefinitionsClientWithBaseURI(sdkApi sdkEnv.Api) (*EnvironmentDefinitionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "environmentdefinitions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EnvironmentDefinitionsClient: %+v", err) + } + + return &EnvironmentDefinitionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/constants.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/constants.go new file mode 100644 index 00000000000..a6999586a36 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/constants.go @@ -0,0 +1,110 @@ +package environmentdefinitions + +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 CatalogResourceValidationStatus string + +const ( + CatalogResourceValidationStatusFailed CatalogResourceValidationStatus = "Failed" + CatalogResourceValidationStatusPending CatalogResourceValidationStatus = "Pending" + CatalogResourceValidationStatusSucceeded CatalogResourceValidationStatus = "Succeeded" + CatalogResourceValidationStatusUnknown CatalogResourceValidationStatus = "Unknown" +) + +func PossibleValuesForCatalogResourceValidationStatus() []string { + return []string{ + string(CatalogResourceValidationStatusFailed), + string(CatalogResourceValidationStatusPending), + string(CatalogResourceValidationStatusSucceeded), + string(CatalogResourceValidationStatusUnknown), + } +} + +func (s *CatalogResourceValidationStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogResourceValidationStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogResourceValidationStatus(input string) (*CatalogResourceValidationStatus, error) { + vals := map[string]CatalogResourceValidationStatus{ + "failed": CatalogResourceValidationStatusFailed, + "pending": CatalogResourceValidationStatusPending, + "succeeded": CatalogResourceValidationStatusSucceeded, + "unknown": CatalogResourceValidationStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogResourceValidationStatus(input) + return &out, nil +} + +type ParameterType string + +const ( + ParameterTypeArray ParameterType = "array" + ParameterTypeBoolean ParameterType = "boolean" + ParameterTypeInteger ParameterType = "integer" + ParameterTypeNumber ParameterType = "number" + ParameterTypeObject ParameterType = "object" + ParameterTypeString ParameterType = "string" +) + +func PossibleValuesForParameterType() []string { + return []string{ + string(ParameterTypeArray), + string(ParameterTypeBoolean), + string(ParameterTypeInteger), + string(ParameterTypeNumber), + string(ParameterTypeObject), + string(ParameterTypeString), + } +} + +func (s *ParameterType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseParameterType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseParameterType(input string) (*ParameterType, error) { + vals := map[string]ParameterType{ + "array": ParameterTypeArray, + "boolean": ParameterTypeBoolean, + "integer": ParameterTypeInteger, + "number": ParameterTypeNumber, + "object": ParameterTypeObject, + "string": ParameterTypeString, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ParameterType(input) + return &out, nil +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalog.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalog.go new file mode 100644 index 00000000000..001c6a6eaec --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalog.go @@ -0,0 +1,134 @@ +package environmentdefinitions + +import ( + "fmt" + "strings" + + "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 = &CatalogId{} + +// CatalogId is a struct representing the Resource ID for a Catalog +type CatalogId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string + CatalogName string +} + +// NewCatalogID returns a new CatalogId struct +func NewCatalogID(subscriptionId string, resourceGroupName string, projectName string, catalogName string) CatalogId { + return CatalogId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + CatalogName: catalogName, + } +} + +// ParseCatalogID parses 'input' into a CatalogId +func ParseCatalogID(input string) (*CatalogId, error) { + parser := resourceids.NewParserFromResourceIdType(&CatalogId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CatalogId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCatalogIDInsensitively parses 'input' case-insensitively into a CatalogId +// note: this method should only be used for API response data and not user input +func ParseCatalogIDInsensitively(input string) (*CatalogId, error) { + parser := resourceids.NewParserFromResourceIdType(&CatalogId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CatalogId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CatalogId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + if id.CatalogName, ok = input.Parsed["catalogName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "catalogName", input) + } + + return nil +} + +// ValidateCatalogID checks that 'input' can be parsed as a Catalog ID +func ValidateCatalogID(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 := ParseCatalogID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Catalog ID +func (id CatalogId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s/catalogs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName, id.CatalogName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Catalog ID +func (id CatalogId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + resourceids.StaticSegment("staticCatalogs", "catalogs", "catalogs"), + resourceids.UserSpecifiedSegment("catalogName", "catalogValue"), + } +} + +// String returns a human-readable description of this Catalog ID +func (id CatalogId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + fmt.Sprintf("Catalog Name: %q", id.CatalogName), + } + return fmt.Sprintf("Catalog (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalog_test.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalog_test.go new file mode 100644 index 00000000000..2ad12e093c1 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalog_test.go @@ -0,0 +1,327 @@ +package environmentdefinitions + +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 = &CatalogId{} + +func TestNewCatalogID(t *testing.T) { + id := NewCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } + + if id.CatalogName != "catalogValue" { + t.Fatalf("Expected %q but got %q for Segment 'CatalogName'", id.CatalogName, "catalogValue") + } +} + +func TestFormatCatalogID(t *testing.T) { + actual := NewCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCatalogID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CatalogId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue", + Expected: &CatalogId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + CatalogName: "catalogValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCatalogID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.CatalogName != v.Expected.CatalogName { + t.Fatalf("Expected %q but got %q for CatalogName", v.Expected.CatalogName, actual.CatalogName) + } + + } +} + +func TestParseCatalogIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CatalogId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/cAtAlOgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue", + Expected: &CatalogId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + CatalogName: "catalogValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/cAtAlOgS/cAtAlOgVaLuE", + Expected: &CatalogId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + CatalogName: "cAtAlOgVaLuE", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/cAtAlOgS/cAtAlOgVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCatalogIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.CatalogName != v.Expected.CatalogName { + t.Fatalf("Expected %q but got %q for CatalogName", v.Expected.CatalogName, actual.CatalogName) + } + + } +} + +func TestSegmentsForCatalogId(t *testing.T) { + segments := CatalogId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CatalogId 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/devcenter/2024-02-01/environmentdefinitions/id_catalogenvironmentdefinition.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalogenvironmentdefinition.go new file mode 100644 index 00000000000..10a45e36daf --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalogenvironmentdefinition.go @@ -0,0 +1,143 @@ +package environmentdefinitions + +import ( + "fmt" + "strings" + + "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 = &CatalogEnvironmentDefinitionId{} + +// CatalogEnvironmentDefinitionId is a struct representing the Resource ID for a Catalog Environment Definition +type CatalogEnvironmentDefinitionId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string + CatalogName string + EnvironmentDefinitionName string +} + +// NewCatalogEnvironmentDefinitionID returns a new CatalogEnvironmentDefinitionId struct +func NewCatalogEnvironmentDefinitionID(subscriptionId string, resourceGroupName string, devCenterName string, catalogName string, environmentDefinitionName string) CatalogEnvironmentDefinitionId { + return CatalogEnvironmentDefinitionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + CatalogName: catalogName, + EnvironmentDefinitionName: environmentDefinitionName, + } +} + +// ParseCatalogEnvironmentDefinitionID parses 'input' into a CatalogEnvironmentDefinitionId +func ParseCatalogEnvironmentDefinitionID(input string) (*CatalogEnvironmentDefinitionId, error) { + parser := resourceids.NewParserFromResourceIdType(&CatalogEnvironmentDefinitionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CatalogEnvironmentDefinitionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCatalogEnvironmentDefinitionIDInsensitively parses 'input' case-insensitively into a CatalogEnvironmentDefinitionId +// note: this method should only be used for API response data and not user input +func ParseCatalogEnvironmentDefinitionIDInsensitively(input string) (*CatalogEnvironmentDefinitionId, error) { + parser := resourceids.NewParserFromResourceIdType(&CatalogEnvironmentDefinitionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CatalogEnvironmentDefinitionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CatalogEnvironmentDefinitionId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + if id.CatalogName, ok = input.Parsed["catalogName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "catalogName", input) + } + + if id.EnvironmentDefinitionName, ok = input.Parsed["environmentDefinitionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "environmentDefinitionName", input) + } + + return nil +} + +// ValidateCatalogEnvironmentDefinitionID checks that 'input' can be parsed as a Catalog Environment Definition ID +func ValidateCatalogEnvironmentDefinitionID(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 := ParseCatalogEnvironmentDefinitionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Catalog Environment Definition ID +func (id CatalogEnvironmentDefinitionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s/catalogs/%s/environmentDefinitions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName, id.CatalogName, id.EnvironmentDefinitionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Catalog Environment Definition ID +func (id CatalogEnvironmentDefinitionId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + resourceids.StaticSegment("staticCatalogs", "catalogs", "catalogs"), + resourceids.UserSpecifiedSegment("catalogName", "catalogValue"), + resourceids.StaticSegment("staticEnvironmentDefinitions", "environmentDefinitions", "environmentDefinitions"), + resourceids.UserSpecifiedSegment("environmentDefinitionName", "environmentDefinitionValue"), + } +} + +// String returns a human-readable description of this Catalog Environment Definition ID +func (id CatalogEnvironmentDefinitionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + fmt.Sprintf("Catalog Name: %q", id.CatalogName), + fmt.Sprintf("Environment Definition Name: %q", id.EnvironmentDefinitionName), + } + return fmt.Sprintf("Catalog Environment Definition (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalogenvironmentdefinition_test.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalogenvironmentdefinition_test.go new file mode 100644 index 00000000000..c9315c8348c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_catalogenvironmentdefinition_test.go @@ -0,0 +1,372 @@ +package environmentdefinitions + +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 = &CatalogEnvironmentDefinitionId{} + +func TestNewCatalogEnvironmentDefinitionID(t *testing.T) { + id := NewCatalogEnvironmentDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue", "environmentDefinitionValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } + + if id.CatalogName != "catalogValue" { + t.Fatalf("Expected %q but got %q for Segment 'CatalogName'", id.CatalogName, "catalogValue") + } + + if id.EnvironmentDefinitionName != "environmentDefinitionValue" { + t.Fatalf("Expected %q but got %q for Segment 'EnvironmentDefinitionName'", id.EnvironmentDefinitionName, "environmentDefinitionValue") + } +} + +func TestFormatCatalogEnvironmentDefinitionID(t *testing.T) { + actual := NewCatalogEnvironmentDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue", "environmentDefinitionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue/environmentDefinitions/environmentDefinitionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCatalogEnvironmentDefinitionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CatalogEnvironmentDefinitionId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue/environmentDefinitions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue/environmentDefinitions/environmentDefinitionValue", + Expected: &CatalogEnvironmentDefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + CatalogName: "catalogValue", + EnvironmentDefinitionName: "environmentDefinitionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue/environmentDefinitions/environmentDefinitionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCatalogEnvironmentDefinitionID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.CatalogName != v.Expected.CatalogName { + t.Fatalf("Expected %q but got %q for CatalogName", v.Expected.CatalogName, actual.CatalogName) + } + + if actual.EnvironmentDefinitionName != v.Expected.EnvironmentDefinitionName { + t.Fatalf("Expected %q but got %q for EnvironmentDefinitionName", v.Expected.EnvironmentDefinitionName, actual.EnvironmentDefinitionName) + } + + } +} + +func TestParseCatalogEnvironmentDefinitionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CatalogEnvironmentDefinitionId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/cAtAlOgS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/cAtAlOgS/cAtAlOgVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue/environmentDefinitions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/cAtAlOgS/cAtAlOgVaLuE/eNvIrOnMeNtDeFiNiTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue/environmentDefinitions/environmentDefinitionValue", + Expected: &CatalogEnvironmentDefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + CatalogName: "catalogValue", + EnvironmentDefinitionName: "environmentDefinitionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue/environmentDefinitions/environmentDefinitionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/cAtAlOgS/cAtAlOgVaLuE/eNvIrOnMeNtDeFiNiTiOnS/eNvIrOnMeNtDeFiNiTiOnVaLuE", + Expected: &CatalogEnvironmentDefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + CatalogName: "cAtAlOgVaLuE", + EnvironmentDefinitionName: "eNvIrOnMeNtDeFiNiTiOnVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/cAtAlOgS/cAtAlOgVaLuE/eNvIrOnMeNtDeFiNiTiOnS/eNvIrOnMeNtDeFiNiTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCatalogEnvironmentDefinitionIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.CatalogName != v.Expected.CatalogName { + t.Fatalf("Expected %q but got %q for CatalogName", v.Expected.CatalogName, actual.CatalogName) + } + + if actual.EnvironmentDefinitionName != v.Expected.EnvironmentDefinitionName { + t.Fatalf("Expected %q but got %q for EnvironmentDefinitionName", v.Expected.EnvironmentDefinitionName, actual.EnvironmentDefinitionName) + } + + } +} + +func TestSegmentsForCatalogEnvironmentDefinitionId(t *testing.T) { + segments := CatalogEnvironmentDefinitionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CatalogEnvironmentDefinitionId 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/devcenter/2024-02-01/environmentdefinitions/id_devcentercatalog.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_devcentercatalog.go new file mode 100644 index 00000000000..9af9ab04ebe --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_devcentercatalog.go @@ -0,0 +1,134 @@ +package environmentdefinitions + +import ( + "fmt" + "strings" + + "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 = &DevCenterCatalogId{} + +// DevCenterCatalogId is a struct representing the Resource ID for a Dev Center Catalog +type DevCenterCatalogId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string + CatalogName string +} + +// NewDevCenterCatalogID returns a new DevCenterCatalogId struct +func NewDevCenterCatalogID(subscriptionId string, resourceGroupName string, devCenterName string, catalogName string) DevCenterCatalogId { + return DevCenterCatalogId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + CatalogName: catalogName, + } +} + +// ParseDevCenterCatalogID parses 'input' into a DevCenterCatalogId +func ParseDevCenterCatalogID(input string) (*DevCenterCatalogId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterCatalogId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterCatalogId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDevCenterCatalogIDInsensitively parses 'input' case-insensitively into a DevCenterCatalogId +// note: this method should only be used for API response data and not user input +func ParseDevCenterCatalogIDInsensitively(input string) (*DevCenterCatalogId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterCatalogId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterCatalogId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DevCenterCatalogId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + if id.CatalogName, ok = input.Parsed["catalogName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "catalogName", input) + } + + return nil +} + +// ValidateDevCenterCatalogID checks that 'input' can be parsed as a Dev Center Catalog ID +func ValidateDevCenterCatalogID(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 := ParseDevCenterCatalogID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dev Center Catalog ID +func (id DevCenterCatalogId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s/catalogs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName, id.CatalogName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dev Center Catalog ID +func (id DevCenterCatalogId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + resourceids.StaticSegment("staticCatalogs", "catalogs", "catalogs"), + resourceids.UserSpecifiedSegment("catalogName", "catalogValue"), + } +} + +// String returns a human-readable description of this Dev Center Catalog ID +func (id DevCenterCatalogId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + fmt.Sprintf("Catalog Name: %q", id.CatalogName), + } + return fmt.Sprintf("Dev Center Catalog (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_devcentercatalog_test.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_devcentercatalog_test.go new file mode 100644 index 00000000000..abc0e5cd7fe --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_devcentercatalog_test.go @@ -0,0 +1,327 @@ +package environmentdefinitions + +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 = &DevCenterCatalogId{} + +func TestNewDevCenterCatalogID(t *testing.T) { + id := NewDevCenterCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } + + if id.CatalogName != "catalogValue" { + t.Fatalf("Expected %q but got %q for Segment 'CatalogName'", id.CatalogName, "catalogValue") + } +} + +func TestFormatDevCenterCatalogID(t *testing.T) { + actual := NewDevCenterCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "catalogValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDevCenterCatalogID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterCatalogId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue", + Expected: &DevCenterCatalogId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + CatalogName: "catalogValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterCatalogID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.CatalogName != v.Expected.CatalogName { + t.Fatalf("Expected %q but got %q for CatalogName", v.Expected.CatalogName, actual.CatalogName) + } + + } +} + +func TestParseDevCenterCatalogIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterCatalogId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/cAtAlOgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue", + Expected: &DevCenterCatalogId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + CatalogName: "catalogValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/catalogs/catalogValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/cAtAlOgS/cAtAlOgVaLuE", + Expected: &DevCenterCatalogId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + CatalogName: "cAtAlOgVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/cAtAlOgS/cAtAlOgVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterCatalogIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.CatalogName != v.Expected.CatalogName { + t.Fatalf("Expected %q but got %q for CatalogName", v.Expected.CatalogName, actual.CatalogName) + } + + } +} + +func TestSegmentsForDevCenterCatalogId(t *testing.T) { + segments := DevCenterCatalogId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DevCenterCatalogId 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/devcenter/2024-02-01/environmentdefinitions/id_environmentdefinition.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_environmentdefinition.go new file mode 100644 index 00000000000..6f06cab969c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_environmentdefinition.go @@ -0,0 +1,143 @@ +package environmentdefinitions + +import ( + "fmt" + "strings" + + "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 = &EnvironmentDefinitionId{} + +// EnvironmentDefinitionId is a struct representing the Resource ID for a Environment Definition +type EnvironmentDefinitionId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string + CatalogName string + EnvironmentDefinitionName string +} + +// NewEnvironmentDefinitionID returns a new EnvironmentDefinitionId struct +func NewEnvironmentDefinitionID(subscriptionId string, resourceGroupName string, projectName string, catalogName string, environmentDefinitionName string) EnvironmentDefinitionId { + return EnvironmentDefinitionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + CatalogName: catalogName, + EnvironmentDefinitionName: environmentDefinitionName, + } +} + +// ParseEnvironmentDefinitionID parses 'input' into a EnvironmentDefinitionId +func ParseEnvironmentDefinitionID(input string) (*EnvironmentDefinitionId, error) { + parser := resourceids.NewParserFromResourceIdType(&EnvironmentDefinitionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EnvironmentDefinitionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseEnvironmentDefinitionIDInsensitively parses 'input' case-insensitively into a EnvironmentDefinitionId +// note: this method should only be used for API response data and not user input +func ParseEnvironmentDefinitionIDInsensitively(input string) (*EnvironmentDefinitionId, error) { + parser := resourceids.NewParserFromResourceIdType(&EnvironmentDefinitionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EnvironmentDefinitionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *EnvironmentDefinitionId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + if id.CatalogName, ok = input.Parsed["catalogName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "catalogName", input) + } + + if id.EnvironmentDefinitionName, ok = input.Parsed["environmentDefinitionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "environmentDefinitionName", input) + } + + return nil +} + +// ValidateEnvironmentDefinitionID checks that 'input' can be parsed as a Environment Definition ID +func ValidateEnvironmentDefinitionID(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 := ParseEnvironmentDefinitionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Environment Definition ID +func (id EnvironmentDefinitionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s/catalogs/%s/environmentDefinitions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName, id.CatalogName, id.EnvironmentDefinitionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Environment Definition ID +func (id EnvironmentDefinitionId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + resourceids.StaticSegment("staticCatalogs", "catalogs", "catalogs"), + resourceids.UserSpecifiedSegment("catalogName", "catalogValue"), + resourceids.StaticSegment("staticEnvironmentDefinitions", "environmentDefinitions", "environmentDefinitions"), + resourceids.UserSpecifiedSegment("environmentDefinitionName", "environmentDefinitionValue"), + } +} + +// String returns a human-readable description of this Environment Definition ID +func (id EnvironmentDefinitionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + fmt.Sprintf("Catalog Name: %q", id.CatalogName), + fmt.Sprintf("Environment Definition Name: %q", id.EnvironmentDefinitionName), + } + return fmt.Sprintf("Environment Definition (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_environmentdefinition_test.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_environmentdefinition_test.go new file mode 100644 index 00000000000..f89561ff817 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/id_environmentdefinition_test.go @@ -0,0 +1,372 @@ +package environmentdefinitions + +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 = &EnvironmentDefinitionId{} + +func TestNewEnvironmentDefinitionID(t *testing.T) { + id := NewEnvironmentDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue", "environmentDefinitionValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } + + if id.CatalogName != "catalogValue" { + t.Fatalf("Expected %q but got %q for Segment 'CatalogName'", id.CatalogName, "catalogValue") + } + + if id.EnvironmentDefinitionName != "environmentDefinitionValue" { + t.Fatalf("Expected %q but got %q for Segment 'EnvironmentDefinitionName'", id.EnvironmentDefinitionName, "environmentDefinitionValue") + } +} + +func TestFormatEnvironmentDefinitionID(t *testing.T) { + actual := NewEnvironmentDefinitionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue", "environmentDefinitionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue/environmentDefinitions/environmentDefinitionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseEnvironmentDefinitionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EnvironmentDefinitionId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue/environmentDefinitions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue/environmentDefinitions/environmentDefinitionValue", + Expected: &EnvironmentDefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + CatalogName: "catalogValue", + EnvironmentDefinitionName: "environmentDefinitionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue/environmentDefinitions/environmentDefinitionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEnvironmentDefinitionID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.CatalogName != v.Expected.CatalogName { + t.Fatalf("Expected %q but got %q for CatalogName", v.Expected.CatalogName, actual.CatalogName) + } + + if actual.EnvironmentDefinitionName != v.Expected.EnvironmentDefinitionName { + t.Fatalf("Expected %q but got %q for EnvironmentDefinitionName", v.Expected.EnvironmentDefinitionName, actual.EnvironmentDefinitionName) + } + + } +} + +func TestParseEnvironmentDefinitionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EnvironmentDefinitionId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/cAtAlOgS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/cAtAlOgS/cAtAlOgVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue/environmentDefinitions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/cAtAlOgS/cAtAlOgVaLuE/eNvIrOnMeNtDeFiNiTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue/environmentDefinitions/environmentDefinitionValue", + Expected: &EnvironmentDefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + CatalogName: "catalogValue", + EnvironmentDefinitionName: "environmentDefinitionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue/environmentDefinitions/environmentDefinitionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/cAtAlOgS/cAtAlOgVaLuE/eNvIrOnMeNtDeFiNiTiOnS/eNvIrOnMeNtDeFiNiTiOnVaLuE", + Expected: &EnvironmentDefinitionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + CatalogName: "cAtAlOgVaLuE", + EnvironmentDefinitionName: "eNvIrOnMeNtDeFiNiTiOnVaLuE", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/cAtAlOgS/cAtAlOgVaLuE/eNvIrOnMeNtDeFiNiTiOnS/eNvIrOnMeNtDeFiNiTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEnvironmentDefinitionIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.CatalogName != v.Expected.CatalogName { + t.Fatalf("Expected %q but got %q for CatalogName", v.Expected.CatalogName, actual.CatalogName) + } + + if actual.EnvironmentDefinitionName != v.Expected.EnvironmentDefinitionName { + t.Fatalf("Expected %q but got %q for EnvironmentDefinitionName", v.Expected.EnvironmentDefinitionName, actual.EnvironmentDefinitionName) + } + + } +} + +func TestSegmentsForEnvironmentDefinitionId(t *testing.T) { + segments := EnvironmentDefinitionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("EnvironmentDefinitionId 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/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionsget.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionsget.go new file mode 100644 index 00000000000..3e0c5a39352 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionsget.go @@ -0,0 +1,54 @@ +package environmentdefinitions + +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 EnvironmentDefinitionsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EnvironmentDefinition +} + +// EnvironmentDefinitionsGet ... +func (c EnvironmentDefinitionsClient) EnvironmentDefinitionsGet(ctx context.Context, id CatalogEnvironmentDefinitionId) (result EnvironmentDefinitionsGetOperationResponse, 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 EnvironmentDefinition + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionsgetbyprojectcatalog.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionsgetbyprojectcatalog.go new file mode 100644 index 00000000000..06310f30dbb --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionsgetbyprojectcatalog.go @@ -0,0 +1,54 @@ +package environmentdefinitions + +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 EnvironmentDefinitionsGetByProjectCatalogOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EnvironmentDefinition +} + +// EnvironmentDefinitionsGetByProjectCatalog ... +func (c EnvironmentDefinitionsClient) EnvironmentDefinitionsGetByProjectCatalog(ctx context.Context, id EnvironmentDefinitionId) (result EnvironmentDefinitionsGetByProjectCatalogOperationResponse, 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 EnvironmentDefinition + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionsgeterrordetails.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionsgeterrordetails.go new file mode 100644 index 00000000000..2d05c22c3c2 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionsgeterrordetails.go @@ -0,0 +1,55 @@ +package environmentdefinitions + +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 EnvironmentDefinitionsGetErrorDetailsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CatalogResourceValidationErrorDetails +} + +// EnvironmentDefinitionsGetErrorDetails ... +func (c EnvironmentDefinitionsClient) EnvironmentDefinitionsGetErrorDetails(ctx context.Context, id CatalogEnvironmentDefinitionId) (result EnvironmentDefinitionsGetErrorDetailsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getErrorDetails", 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 CatalogResourceValidationErrorDetails + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionslistbycatalog.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionslistbycatalog.go new file mode 100644 index 00000000000..1293120f39b --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionslistbycatalog.go @@ -0,0 +1,119 @@ +package environmentdefinitions + +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 EnvironmentDefinitionsListByCatalogOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EnvironmentDefinition +} + +type EnvironmentDefinitionsListByCatalogCompleteResult struct { + LatestHttpResponse *http.Response + Items []EnvironmentDefinition +} + +type EnvironmentDefinitionsListByCatalogOperationOptions struct { + Top *int64 +} + +func DefaultEnvironmentDefinitionsListByCatalogOperationOptions() EnvironmentDefinitionsListByCatalogOperationOptions { + return EnvironmentDefinitionsListByCatalogOperationOptions{} +} + +func (o EnvironmentDefinitionsListByCatalogOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o EnvironmentDefinitionsListByCatalogOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o EnvironmentDefinitionsListByCatalogOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// EnvironmentDefinitionsListByCatalog ... +func (c EnvironmentDefinitionsClient) EnvironmentDefinitionsListByCatalog(ctx context.Context, id DevCenterCatalogId, options EnvironmentDefinitionsListByCatalogOperationOptions) (result EnvironmentDefinitionsListByCatalogOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/environmentDefinitions", id.ID()), + OptionsObject: options, + } + + 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 *[]EnvironmentDefinition `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// EnvironmentDefinitionsListByCatalogComplete retrieves all the results into a single object +func (c EnvironmentDefinitionsClient) EnvironmentDefinitionsListByCatalogComplete(ctx context.Context, id DevCenterCatalogId, options EnvironmentDefinitionsListByCatalogOperationOptions) (EnvironmentDefinitionsListByCatalogCompleteResult, error) { + return c.EnvironmentDefinitionsListByCatalogCompleteMatchingPredicate(ctx, id, options, EnvironmentDefinitionOperationPredicate{}) +} + +// EnvironmentDefinitionsListByCatalogCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EnvironmentDefinitionsClient) EnvironmentDefinitionsListByCatalogCompleteMatchingPredicate(ctx context.Context, id DevCenterCatalogId, options EnvironmentDefinitionsListByCatalogOperationOptions, predicate EnvironmentDefinitionOperationPredicate) (result EnvironmentDefinitionsListByCatalogCompleteResult, err error) { + items := make([]EnvironmentDefinition, 0) + + resp, err := c.EnvironmentDefinitionsListByCatalog(ctx, id, options) + if err != nil { + 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 = EnvironmentDefinitionsListByCatalogCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionslistbyprojectcatalog.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionslistbyprojectcatalog.go new file mode 100644 index 00000000000..420fbb18478 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_environmentdefinitionslistbyprojectcatalog.go @@ -0,0 +1,91 @@ +package environmentdefinitions + +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 EnvironmentDefinitionsListByProjectCatalogOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EnvironmentDefinition +} + +type EnvironmentDefinitionsListByProjectCatalogCompleteResult struct { + LatestHttpResponse *http.Response + Items []EnvironmentDefinition +} + +// EnvironmentDefinitionsListByProjectCatalog ... +func (c EnvironmentDefinitionsClient) EnvironmentDefinitionsListByProjectCatalog(ctx context.Context, id CatalogId) (result EnvironmentDefinitionsListByProjectCatalogOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/environmentDefinitions", 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 *[]EnvironmentDefinition `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// EnvironmentDefinitionsListByProjectCatalogComplete retrieves all the results into a single object +func (c EnvironmentDefinitionsClient) EnvironmentDefinitionsListByProjectCatalogComplete(ctx context.Context, id CatalogId) (EnvironmentDefinitionsListByProjectCatalogCompleteResult, error) { + return c.EnvironmentDefinitionsListByProjectCatalogCompleteMatchingPredicate(ctx, id, EnvironmentDefinitionOperationPredicate{}) +} + +// EnvironmentDefinitionsListByProjectCatalogCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EnvironmentDefinitionsClient) EnvironmentDefinitionsListByProjectCatalogCompleteMatchingPredicate(ctx context.Context, id CatalogId, predicate EnvironmentDefinitionOperationPredicate) (result EnvironmentDefinitionsListByProjectCatalogCompleteResult, err error) { + items := make([]EnvironmentDefinition, 0) + + resp, err := c.EnvironmentDefinitionsListByProjectCatalog(ctx, id) + if err != nil { + 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 = EnvironmentDefinitionsListByProjectCatalogCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_projectcatalogenvironmentdefinitionsgeterrordetails.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_projectcatalogenvironmentdefinitionsgeterrordetails.go new file mode 100644 index 00000000000..bd809e9a8c7 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/method_projectcatalogenvironmentdefinitionsgeterrordetails.go @@ -0,0 +1,55 @@ +package environmentdefinitions + +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 ProjectCatalogEnvironmentDefinitionsGetErrorDetailsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CatalogResourceValidationErrorDetails +} + +// ProjectCatalogEnvironmentDefinitionsGetErrorDetails ... +func (c EnvironmentDefinitionsClient) ProjectCatalogEnvironmentDefinitionsGetErrorDetails(ctx context.Context, id EnvironmentDefinitionId) (result ProjectCatalogEnvironmentDefinitionsGetErrorDetailsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getErrorDetails", 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 CatalogResourceValidationErrorDetails + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_catalogerrordetails.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_catalogerrordetails.go new file mode 100644 index 00000000000..9cddffc7e14 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_catalogerrordetails.go @@ -0,0 +1,9 @@ +package environmentdefinitions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogErrorDetails struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_catalogresourcevalidationerrordetails.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_catalogresourcevalidationerrordetails.go new file mode 100644 index 00000000000..58915d0fb8a --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_catalogresourcevalidationerrordetails.go @@ -0,0 +1,8 @@ +package environmentdefinitions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogResourceValidationErrorDetails struct { + Errors *[]CatalogErrorDetails `json:"errors,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_environmentdefinition.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_environmentdefinition.go new file mode 100644 index 00000000000..6d912ac157a --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_environmentdefinition.go @@ -0,0 +1,16 @@ +package environmentdefinitions + +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 EnvironmentDefinition struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EnvironmentDefinitionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_environmentdefinitionparameter.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_environmentdefinitionparameter.go new file mode 100644 index 00000000000..b462485aa80 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_environmentdefinitionparameter.go @@ -0,0 +1,13 @@ +package environmentdefinitions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnvironmentDefinitionParameter struct { + Description *string `json:"description,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + ReadOnly *bool `json:"readOnly,omitempty"` + Required *bool `json:"required,omitempty"` + Type *ParameterType `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_environmentdefinitionproperties.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_environmentdefinitionproperties.go new file mode 100644 index 00000000000..dc062862514 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/model_environmentdefinitionproperties.go @@ -0,0 +1,11 @@ +package environmentdefinitions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnvironmentDefinitionProperties struct { + Description *string `json:"description,omitempty"` + Parameters *[]EnvironmentDefinitionParameter `json:"parameters,omitempty"` + TemplatePath *string `json:"templatePath,omitempty"` + ValidationStatus *CatalogResourceValidationStatus `json:"validationStatus,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmentdefinitions/predicates.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/predicates.go new file mode 100644 index 00000000000..b18a7cf72a6 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/predicates.go @@ -0,0 +1,27 @@ +package environmentdefinitions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnvironmentDefinitionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p EnvironmentDefinitionOperationPredicate) Matches(input EnvironmentDefinition) 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/devcenter/2024-02-01/environmentdefinitions/version.go b/resource-manager/devcenter/2024-02-01/environmentdefinitions/version.go new file mode 100644 index 00000000000..4e50411b970 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmentdefinitions/version.go @@ -0,0 +1,12 @@ +package environmentdefinitions + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/environmentdefinitions/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/README.md b/resource-manager/devcenter/2024-02-01/environmenttypes/README.md new file mode 100644 index 00000000000..af6e0ffa6c0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/README.md @@ -0,0 +1,235 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/environmenttypes` Documentation + +The `environmenttypes` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/environmenttypes" +``` + + +### Client Initialization + +```go +client := environmenttypes.NewEnvironmentTypesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `EnvironmentTypesClient.EnvironmentTypesCreateOrUpdate` + +```go +ctx := context.TODO() +id := environmenttypes.NewDevCenterEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "environmentTypeValue") + +payload := environmenttypes.EnvironmentType{ + // ... +} + + +read, err := client.EnvironmentTypesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EnvironmentTypesClient.EnvironmentTypesDelete` + +```go +ctx := context.TODO() +id := environmenttypes.NewDevCenterEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "environmentTypeValue") + +read, err := client.EnvironmentTypesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EnvironmentTypesClient.EnvironmentTypesGet` + +```go +ctx := context.TODO() +id := environmenttypes.NewDevCenterEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "environmentTypeValue") + +read, err := client.EnvironmentTypesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EnvironmentTypesClient.EnvironmentTypesListByDevCenter` + +```go +ctx := context.TODO() +id := environmenttypes.NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + +// alternatively `client.EnvironmentTypesListByDevCenter(ctx, id, environmenttypes.DefaultEnvironmentTypesListByDevCenterOperationOptions())` can be used to do batched pagination +items, err := client.EnvironmentTypesListByDevCenterComplete(ctx, id, environmenttypes.DefaultEnvironmentTypesListByDevCenterOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EnvironmentTypesClient.EnvironmentTypesUpdate` + +```go +ctx := context.TODO() +id := environmenttypes.NewDevCenterEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "environmentTypeValue") + +payload := environmenttypes.EnvironmentTypeUpdate{ + // ... +} + + +read, err := client.EnvironmentTypesUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EnvironmentTypesClient.ProjectAllowedEnvironmentTypesGet` + +```go +ctx := context.TODO() +id := environmenttypes.NewAllowedEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "allowedEnvironmentTypeValue") + +read, err := client.ProjectAllowedEnvironmentTypesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EnvironmentTypesClient.ProjectAllowedEnvironmentTypesList` + +```go +ctx := context.TODO() +id := environmenttypes.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + +// alternatively `client.ProjectAllowedEnvironmentTypesList(ctx, id, environmenttypes.DefaultProjectAllowedEnvironmentTypesListOperationOptions())` can be used to do batched pagination +items, err := client.ProjectAllowedEnvironmentTypesListComplete(ctx, id, environmenttypes.DefaultProjectAllowedEnvironmentTypesListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EnvironmentTypesClient.ProjectEnvironmentTypesCreateOrUpdate` + +```go +ctx := context.TODO() +id := environmenttypes.NewEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "environmentTypeValue") + +payload := environmenttypes.ProjectEnvironmentType{ + // ... +} + + +read, err := client.ProjectEnvironmentTypesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EnvironmentTypesClient.ProjectEnvironmentTypesDelete` + +```go +ctx := context.TODO() +id := environmenttypes.NewEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "environmentTypeValue") + +read, err := client.ProjectEnvironmentTypesDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EnvironmentTypesClient.ProjectEnvironmentTypesGet` + +```go +ctx := context.TODO() +id := environmenttypes.NewEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "environmentTypeValue") + +read, err := client.ProjectEnvironmentTypesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EnvironmentTypesClient.ProjectEnvironmentTypesList` + +```go +ctx := context.TODO() +id := environmenttypes.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + +// alternatively `client.ProjectEnvironmentTypesList(ctx, id, environmenttypes.DefaultProjectEnvironmentTypesListOperationOptions())` can be used to do batched pagination +items, err := client.ProjectEnvironmentTypesListComplete(ctx, id, environmenttypes.DefaultProjectEnvironmentTypesListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `EnvironmentTypesClient.ProjectEnvironmentTypesUpdate` + +```go +ctx := context.TODO() +id := environmenttypes.NewEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "environmentTypeValue") + +payload := environmenttypes.ProjectEnvironmentTypeUpdate{ + // ... +} + + +read, err := client.ProjectEnvironmentTypesUpdate(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/devcenter/2024-02-01/environmenttypes/client.go b/resource-manager/devcenter/2024-02-01/environmenttypes/client.go new file mode 100644 index 00000000000..9e3aa2ec5db --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/client.go @@ -0,0 +1,26 @@ +package environmenttypes + +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 EnvironmentTypesClient struct { + Client *resourcemanager.Client +} + +func NewEnvironmentTypesClientWithBaseURI(sdkApi sdkEnv.Api) (*EnvironmentTypesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "environmenttypes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EnvironmentTypesClient: %+v", err) + } + + return &EnvironmentTypesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/constants.go b/resource-manager/devcenter/2024-02-01/environmenttypes/constants.go new file mode 100644 index 00000000000..a1acb6c4fb0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/constants.go @@ -0,0 +1,134 @@ +package environmenttypes + +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 EnvironmentTypeEnableStatus string + +const ( + EnvironmentTypeEnableStatusDisabled EnvironmentTypeEnableStatus = "Disabled" + EnvironmentTypeEnableStatusEnabled EnvironmentTypeEnableStatus = "Enabled" +) + +func PossibleValuesForEnvironmentTypeEnableStatus() []string { + return []string{ + string(EnvironmentTypeEnableStatusDisabled), + string(EnvironmentTypeEnableStatusEnabled), + } +} + +func (s *EnvironmentTypeEnableStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEnvironmentTypeEnableStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEnvironmentTypeEnableStatus(input string) (*EnvironmentTypeEnableStatus, error) { + vals := map[string]EnvironmentTypeEnableStatus{ + "disabled": EnvironmentTypeEnableStatusDisabled, + "enabled": EnvironmentTypeEnableStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EnvironmentTypeEnableStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMovingResources ProvisioningState = "MovingResources" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateRolloutInProgress ProvisioningState = "RolloutInProgress" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateStorageProvisioningFailed ProvisioningState = "StorageProvisioningFailed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateTransientFailure ProvisioningState = "TransientFailure" + ProvisioningStateUpdated ProvisioningState = "Updated" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMovingResources), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateRolloutInProgress), + string(ProvisioningStateRunning), + string(ProvisioningStateStorageProvisioningFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateTransientFailure), + string(ProvisioningStateUpdated), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "movingresources": ProvisioningStateMovingResources, + "notspecified": ProvisioningStateNotSpecified, + "rolloutinprogress": ProvisioningStateRolloutInProgress, + "running": ProvisioningStateRunning, + "storageprovisioningfailed": ProvisioningStateStorageProvisioningFailed, + "succeeded": ProvisioningStateSucceeded, + "transientfailure": ProvisioningStateTransientFailure, + "updated": ProvisioningStateUpdated, + "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/devcenter/2024-02-01/environmenttypes/id_allowedenvironmenttype.go b/resource-manager/devcenter/2024-02-01/environmenttypes/id_allowedenvironmenttype.go new file mode 100644 index 00000000000..a3521f6cdbf --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/id_allowedenvironmenttype.go @@ -0,0 +1,134 @@ +package environmenttypes + +import ( + "fmt" + "strings" + + "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 = &AllowedEnvironmentTypeId{} + +// AllowedEnvironmentTypeId is a struct representing the Resource ID for a Allowed Environment Type +type AllowedEnvironmentTypeId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string + AllowedEnvironmentTypeName string +} + +// NewAllowedEnvironmentTypeID returns a new AllowedEnvironmentTypeId struct +func NewAllowedEnvironmentTypeID(subscriptionId string, resourceGroupName string, projectName string, allowedEnvironmentTypeName string) AllowedEnvironmentTypeId { + return AllowedEnvironmentTypeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + AllowedEnvironmentTypeName: allowedEnvironmentTypeName, + } +} + +// ParseAllowedEnvironmentTypeID parses 'input' into a AllowedEnvironmentTypeId +func ParseAllowedEnvironmentTypeID(input string) (*AllowedEnvironmentTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&AllowedEnvironmentTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AllowedEnvironmentTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAllowedEnvironmentTypeIDInsensitively parses 'input' case-insensitively into a AllowedEnvironmentTypeId +// note: this method should only be used for API response data and not user input +func ParseAllowedEnvironmentTypeIDInsensitively(input string) (*AllowedEnvironmentTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&AllowedEnvironmentTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AllowedEnvironmentTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AllowedEnvironmentTypeId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + if id.AllowedEnvironmentTypeName, ok = input.Parsed["allowedEnvironmentTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "allowedEnvironmentTypeName", input) + } + + return nil +} + +// ValidateAllowedEnvironmentTypeID checks that 'input' can be parsed as a Allowed Environment Type ID +func ValidateAllowedEnvironmentTypeID(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 := ParseAllowedEnvironmentTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Allowed Environment Type ID +func (id AllowedEnvironmentTypeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s/allowedEnvironmentTypes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName, id.AllowedEnvironmentTypeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Allowed Environment Type ID +func (id AllowedEnvironmentTypeId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + resourceids.StaticSegment("staticAllowedEnvironmentTypes", "allowedEnvironmentTypes", "allowedEnvironmentTypes"), + resourceids.UserSpecifiedSegment("allowedEnvironmentTypeName", "allowedEnvironmentTypeValue"), + } +} + +// String returns a human-readable description of this Allowed Environment Type ID +func (id AllowedEnvironmentTypeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + fmt.Sprintf("Allowed Environment Type Name: %q", id.AllowedEnvironmentTypeName), + } + return fmt.Sprintf("Allowed Environment Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/id_allowedenvironmenttype_test.go b/resource-manager/devcenter/2024-02-01/environmenttypes/id_allowedenvironmenttype_test.go new file mode 100644 index 00000000000..d4dc30414cc --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/id_allowedenvironmenttype_test.go @@ -0,0 +1,327 @@ +package environmenttypes + +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 = &AllowedEnvironmentTypeId{} + +func TestNewAllowedEnvironmentTypeID(t *testing.T) { + id := NewAllowedEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "allowedEnvironmentTypeValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } + + if id.AllowedEnvironmentTypeName != "allowedEnvironmentTypeValue" { + t.Fatalf("Expected %q but got %q for Segment 'AllowedEnvironmentTypeName'", id.AllowedEnvironmentTypeName, "allowedEnvironmentTypeValue") + } +} + +func TestFormatAllowedEnvironmentTypeID(t *testing.T) { + actual := NewAllowedEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "allowedEnvironmentTypeValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/allowedEnvironmentTypes/allowedEnvironmentTypeValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAllowedEnvironmentTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AllowedEnvironmentTypeId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/allowedEnvironmentTypes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/allowedEnvironmentTypes/allowedEnvironmentTypeValue", + Expected: &AllowedEnvironmentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + AllowedEnvironmentTypeName: "allowedEnvironmentTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/allowedEnvironmentTypes/allowedEnvironmentTypeValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAllowedEnvironmentTypeID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.AllowedEnvironmentTypeName != v.Expected.AllowedEnvironmentTypeName { + t.Fatalf("Expected %q but got %q for AllowedEnvironmentTypeName", v.Expected.AllowedEnvironmentTypeName, actual.AllowedEnvironmentTypeName) + } + + } +} + +func TestParseAllowedEnvironmentTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AllowedEnvironmentTypeId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/allowedEnvironmentTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/aLlOwEdEnViRoNmEnTtYpEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/allowedEnvironmentTypes/allowedEnvironmentTypeValue", + Expected: &AllowedEnvironmentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + AllowedEnvironmentTypeName: "allowedEnvironmentTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/allowedEnvironmentTypes/allowedEnvironmentTypeValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/aLlOwEdEnViRoNmEnTtYpEs/aLlOwEdEnViRoNmEnTtYpEvAlUe", + Expected: &AllowedEnvironmentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + AllowedEnvironmentTypeName: "aLlOwEdEnViRoNmEnTtYpEvAlUe", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/aLlOwEdEnViRoNmEnTtYpEs/aLlOwEdEnViRoNmEnTtYpEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAllowedEnvironmentTypeIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.AllowedEnvironmentTypeName != v.Expected.AllowedEnvironmentTypeName { + t.Fatalf("Expected %q but got %q for AllowedEnvironmentTypeName", v.Expected.AllowedEnvironmentTypeName, actual.AllowedEnvironmentTypeName) + } + + } +} + +func TestSegmentsForAllowedEnvironmentTypeId(t *testing.T) { + segments := AllowedEnvironmentTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AllowedEnvironmentTypeId 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/devcenter/2024-02-01/environmenttypes/id_devcenter.go b/resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenter.go new file mode 100644 index 00000000000..0cba73a94a0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenter.go @@ -0,0 +1,125 @@ +package environmenttypes + +import ( + "fmt" + "strings" + + "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 = &DevCenterId{} + +// DevCenterId is a struct representing the Resource ID for a Dev Center +type DevCenterId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string +} + +// NewDevCenterID returns a new DevCenterId struct +func NewDevCenterID(subscriptionId string, resourceGroupName string, devCenterName string) DevCenterId { + return DevCenterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + } +} + +// ParseDevCenterID parses 'input' into a DevCenterId +func ParseDevCenterID(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDevCenterIDInsensitively parses 'input' case-insensitively into a DevCenterId +// note: this method should only be used for API response data and not user input +func ParseDevCenterIDInsensitively(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DevCenterId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + return nil +} + +// ValidateDevCenterID checks that 'input' can be parsed as a Dev Center ID +func ValidateDevCenterID(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 := ParseDevCenterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dev Center ID +func (id DevCenterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dev Center ID +func (id DevCenterId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + } +} + +// String returns a human-readable description of this Dev Center ID +func (id DevCenterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + } + return fmt.Sprintf("Dev Center (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenter_test.go b/resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenter_test.go new file mode 100644 index 00000000000..22ce285d6a3 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenter_test.go @@ -0,0 +1,282 @@ +package environmenttypes + +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 = &DevCenterId{} + +func TestNewDevCenterID(t *testing.T) { + id := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } +} + +func TestFormatDevCenterID(t *testing.T) { + actual := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDevCenterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestParseDevCenterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestSegmentsForDevCenterId(t *testing.T) { + segments := DevCenterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DevCenterId 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/devcenter/2024-02-01/environmenttypes/id_devcenterenvironmenttype.go b/resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenterenvironmenttype.go new file mode 100644 index 00000000000..4cb1a55eee5 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenterenvironmenttype.go @@ -0,0 +1,134 @@ +package environmenttypes + +import ( + "fmt" + "strings" + + "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 = &DevCenterEnvironmentTypeId{} + +// DevCenterEnvironmentTypeId is a struct representing the Resource ID for a Dev Center Environment Type +type DevCenterEnvironmentTypeId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string + EnvironmentTypeName string +} + +// NewDevCenterEnvironmentTypeID returns a new DevCenterEnvironmentTypeId struct +func NewDevCenterEnvironmentTypeID(subscriptionId string, resourceGroupName string, devCenterName string, environmentTypeName string) DevCenterEnvironmentTypeId { + return DevCenterEnvironmentTypeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + EnvironmentTypeName: environmentTypeName, + } +} + +// ParseDevCenterEnvironmentTypeID parses 'input' into a DevCenterEnvironmentTypeId +func ParseDevCenterEnvironmentTypeID(input string) (*DevCenterEnvironmentTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterEnvironmentTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterEnvironmentTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDevCenterEnvironmentTypeIDInsensitively parses 'input' case-insensitively into a DevCenterEnvironmentTypeId +// note: this method should only be used for API response data and not user input +func ParseDevCenterEnvironmentTypeIDInsensitively(input string) (*DevCenterEnvironmentTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterEnvironmentTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterEnvironmentTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DevCenterEnvironmentTypeId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + if id.EnvironmentTypeName, ok = input.Parsed["environmentTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "environmentTypeName", input) + } + + return nil +} + +// ValidateDevCenterEnvironmentTypeID checks that 'input' can be parsed as a Dev Center Environment Type ID +func ValidateDevCenterEnvironmentTypeID(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 := ParseDevCenterEnvironmentTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dev Center Environment Type ID +func (id DevCenterEnvironmentTypeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s/environmentTypes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName, id.EnvironmentTypeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dev Center Environment Type ID +func (id DevCenterEnvironmentTypeId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + resourceids.StaticSegment("staticEnvironmentTypes", "environmentTypes", "environmentTypes"), + resourceids.UserSpecifiedSegment("environmentTypeName", "environmentTypeValue"), + } +} + +// String returns a human-readable description of this Dev Center Environment Type ID +func (id DevCenterEnvironmentTypeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + fmt.Sprintf("Environment Type Name: %q", id.EnvironmentTypeName), + } + return fmt.Sprintf("Dev Center Environment Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenterenvironmenttype_test.go b/resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenterenvironmenttype_test.go new file mode 100644 index 00000000000..29219e94132 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/id_devcenterenvironmenttype_test.go @@ -0,0 +1,327 @@ +package environmenttypes + +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 = &DevCenterEnvironmentTypeId{} + +func TestNewDevCenterEnvironmentTypeID(t *testing.T) { + id := NewDevCenterEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "environmentTypeValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } + + if id.EnvironmentTypeName != "environmentTypeValue" { + t.Fatalf("Expected %q but got %q for Segment 'EnvironmentTypeName'", id.EnvironmentTypeName, "environmentTypeValue") + } +} + +func TestFormatDevCenterEnvironmentTypeID(t *testing.T) { + actual := NewDevCenterEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "environmentTypeValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/environmentTypes/environmentTypeValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDevCenterEnvironmentTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterEnvironmentTypeId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/environmentTypes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/environmentTypes/environmentTypeValue", + Expected: &DevCenterEnvironmentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + EnvironmentTypeName: "environmentTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/environmentTypes/environmentTypeValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterEnvironmentTypeID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.EnvironmentTypeName != v.Expected.EnvironmentTypeName { + t.Fatalf("Expected %q but got %q for EnvironmentTypeName", v.Expected.EnvironmentTypeName, actual.EnvironmentTypeName) + } + + } +} + +func TestParseDevCenterEnvironmentTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterEnvironmentTypeId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/environmentTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/eNvIrOnMeNtTyPeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/environmentTypes/environmentTypeValue", + Expected: &DevCenterEnvironmentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + EnvironmentTypeName: "environmentTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/environmentTypes/environmentTypeValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/eNvIrOnMeNtTyPeS/eNvIrOnMeNtTyPeVaLuE", + Expected: &DevCenterEnvironmentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + EnvironmentTypeName: "eNvIrOnMeNtTyPeVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/eNvIrOnMeNtTyPeS/eNvIrOnMeNtTyPeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterEnvironmentTypeIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.EnvironmentTypeName != v.Expected.EnvironmentTypeName { + t.Fatalf("Expected %q but got %q for EnvironmentTypeName", v.Expected.EnvironmentTypeName, actual.EnvironmentTypeName) + } + + } +} + +func TestSegmentsForDevCenterEnvironmentTypeId(t *testing.T) { + segments := DevCenterEnvironmentTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DevCenterEnvironmentTypeId 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/devcenter/2024-02-01/environmenttypes/id_environmenttype.go b/resource-manager/devcenter/2024-02-01/environmenttypes/id_environmenttype.go new file mode 100644 index 00000000000..8664f980def --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/id_environmenttype.go @@ -0,0 +1,134 @@ +package environmenttypes + +import ( + "fmt" + "strings" + + "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 = &EnvironmentTypeId{} + +// EnvironmentTypeId is a struct representing the Resource ID for a Environment Type +type EnvironmentTypeId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string + EnvironmentTypeName string +} + +// NewEnvironmentTypeID returns a new EnvironmentTypeId struct +func NewEnvironmentTypeID(subscriptionId string, resourceGroupName string, projectName string, environmentTypeName string) EnvironmentTypeId { + return EnvironmentTypeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + EnvironmentTypeName: environmentTypeName, + } +} + +// ParseEnvironmentTypeID parses 'input' into a EnvironmentTypeId +func ParseEnvironmentTypeID(input string) (*EnvironmentTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&EnvironmentTypeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EnvironmentTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseEnvironmentTypeIDInsensitively parses 'input' case-insensitively into a EnvironmentTypeId +// note: this method should only be used for API response data and not user input +func ParseEnvironmentTypeIDInsensitively(input string) (*EnvironmentTypeId, error) { + parser := resourceids.NewParserFromResourceIdType(&EnvironmentTypeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EnvironmentTypeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *EnvironmentTypeId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + if id.EnvironmentTypeName, ok = input.Parsed["environmentTypeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "environmentTypeName", input) + } + + return nil +} + +// ValidateEnvironmentTypeID checks that 'input' can be parsed as a Environment Type ID +func ValidateEnvironmentTypeID(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 := ParseEnvironmentTypeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Environment Type ID +func (id EnvironmentTypeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s/environmentTypes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName, id.EnvironmentTypeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Environment Type ID +func (id EnvironmentTypeId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + resourceids.StaticSegment("staticEnvironmentTypes", "environmentTypes", "environmentTypes"), + resourceids.UserSpecifiedSegment("environmentTypeName", "environmentTypeValue"), + } +} + +// String returns a human-readable description of this Environment Type ID +func (id EnvironmentTypeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + fmt.Sprintf("Environment Type Name: %q", id.EnvironmentTypeName), + } + return fmt.Sprintf("Environment Type (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/id_environmenttype_test.go b/resource-manager/devcenter/2024-02-01/environmenttypes/id_environmenttype_test.go new file mode 100644 index 00000000000..7503db817dc --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/id_environmenttype_test.go @@ -0,0 +1,327 @@ +package environmenttypes + +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 = &EnvironmentTypeId{} + +func TestNewEnvironmentTypeID(t *testing.T) { + id := NewEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "environmentTypeValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } + + if id.EnvironmentTypeName != "environmentTypeValue" { + t.Fatalf("Expected %q but got %q for Segment 'EnvironmentTypeName'", id.EnvironmentTypeName, "environmentTypeValue") + } +} + +func TestFormatEnvironmentTypeID(t *testing.T) { + actual := NewEnvironmentTypeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "environmentTypeValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/environmentTypes/environmentTypeValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseEnvironmentTypeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EnvironmentTypeId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/environmentTypes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/environmentTypes/environmentTypeValue", + Expected: &EnvironmentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + EnvironmentTypeName: "environmentTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/environmentTypes/environmentTypeValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEnvironmentTypeID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.EnvironmentTypeName != v.Expected.EnvironmentTypeName { + t.Fatalf("Expected %q but got %q for EnvironmentTypeName", v.Expected.EnvironmentTypeName, actual.EnvironmentTypeName) + } + + } +} + +func TestParseEnvironmentTypeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EnvironmentTypeId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/environmentTypes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/eNvIrOnMeNtTyPeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/environmentTypes/environmentTypeValue", + Expected: &EnvironmentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + EnvironmentTypeName: "environmentTypeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/environmentTypes/environmentTypeValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/eNvIrOnMeNtTyPeS/eNvIrOnMeNtTyPeVaLuE", + Expected: &EnvironmentTypeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + EnvironmentTypeName: "eNvIrOnMeNtTyPeVaLuE", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/eNvIrOnMeNtTyPeS/eNvIrOnMeNtTyPeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEnvironmentTypeIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.EnvironmentTypeName != v.Expected.EnvironmentTypeName { + t.Fatalf("Expected %q but got %q for EnvironmentTypeName", v.Expected.EnvironmentTypeName, actual.EnvironmentTypeName) + } + + } +} + +func TestSegmentsForEnvironmentTypeId(t *testing.T) { + segments := EnvironmentTypeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("EnvironmentTypeId 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/devcenter/2024-02-01/environmenttypes/id_project.go b/resource-manager/devcenter/2024-02-01/environmenttypes/id_project.go new file mode 100644 index 00000000000..bc6bcc685ce --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/id_project.go @@ -0,0 +1,125 @@ +package environmenttypes + +import ( + "fmt" + "strings" + + "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 = &ProjectId{} + +// ProjectId is a struct representing the Resource ID for a Project +type ProjectId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string +} + +// NewProjectID returns a new ProjectId struct +func NewProjectID(subscriptionId string, resourceGroupName string, projectName string) ProjectId { + return ProjectId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + } +} + +// ParseProjectID parses 'input' into a ProjectId +func ParseProjectID(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProjectIDInsensitively parses 'input' case-insensitively into a ProjectId +// note: this method should only be used for API response data and not user input +func ParseProjectIDInsensitively(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProjectId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + return nil +} + +// ValidateProjectID checks that 'input' can be parsed as a Project ID +func ValidateProjectID(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 := ParseProjectID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Project ID +func (id ProjectId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Project ID +func (id ProjectId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + } +} + +// String returns a human-readable description of this Project ID +func (id ProjectId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + } + return fmt.Sprintf("Project (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/id_project_test.go b/resource-manager/devcenter/2024-02-01/environmenttypes/id_project_test.go new file mode 100644 index 00000000000..a464b1d2015 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/id_project_test.go @@ -0,0 +1,282 @@ +package environmenttypes + +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 = &ProjectId{} + +func TestNewProjectID(t *testing.T) { + id := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } +} + +func TestFormatProjectID(t *testing.T) { + actual := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProjectID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestParseProjectIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestSegmentsForProjectId(t *testing.T) { + segments := ProjectId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProjectId 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/devcenter/2024-02-01/environmenttypes/method_environmenttypescreateorupdate.go b/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypescreateorupdate.go new file mode 100644 index 00000000000..caf724e7b5f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypescreateorupdate.go @@ -0,0 +1,59 @@ +package environmenttypes + +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 EnvironmentTypesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EnvironmentType +} + +// EnvironmentTypesCreateOrUpdate ... +func (c EnvironmentTypesClient) EnvironmentTypesCreateOrUpdate(ctx context.Context, id DevCenterEnvironmentTypeId, input EnvironmentType) (result EnvironmentTypesCreateOrUpdateOperationResponse, 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 + } + + var model EnvironmentType + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypesdelete.go b/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypesdelete.go new file mode 100644 index 00000000000..3674aef3622 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypesdelete.go @@ -0,0 +1,47 @@ +package environmenttypes + +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 EnvironmentTypesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// EnvironmentTypesDelete ... +func (c EnvironmentTypesClient) EnvironmentTypesDelete(ctx context.Context, id DevCenterEnvironmentTypeId) (result EnvironmentTypesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + 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 + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypesget.go b/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypesget.go new file mode 100644 index 00000000000..ac45221fa84 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypesget.go @@ -0,0 +1,54 @@ +package environmenttypes + +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 EnvironmentTypesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EnvironmentType +} + +// EnvironmentTypesGet ... +func (c EnvironmentTypesClient) EnvironmentTypesGet(ctx context.Context, id DevCenterEnvironmentTypeId) (result EnvironmentTypesGetOperationResponse, 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 EnvironmentType + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypeslistbydevcenter.go b/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypeslistbydevcenter.go new file mode 100644 index 00000000000..7605583ac59 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypeslistbydevcenter.go @@ -0,0 +1,119 @@ +package environmenttypes + +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 EnvironmentTypesListByDevCenterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]EnvironmentType +} + +type EnvironmentTypesListByDevCenterCompleteResult struct { + LatestHttpResponse *http.Response + Items []EnvironmentType +} + +type EnvironmentTypesListByDevCenterOperationOptions struct { + Top *int64 +} + +func DefaultEnvironmentTypesListByDevCenterOperationOptions() EnvironmentTypesListByDevCenterOperationOptions { + return EnvironmentTypesListByDevCenterOperationOptions{} +} + +func (o EnvironmentTypesListByDevCenterOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o EnvironmentTypesListByDevCenterOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o EnvironmentTypesListByDevCenterOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// EnvironmentTypesListByDevCenter ... +func (c EnvironmentTypesClient) EnvironmentTypesListByDevCenter(ctx context.Context, id DevCenterId, options EnvironmentTypesListByDevCenterOperationOptions) (result EnvironmentTypesListByDevCenterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/environmentTypes", id.ID()), + OptionsObject: options, + } + + 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 *[]EnvironmentType `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// EnvironmentTypesListByDevCenterComplete retrieves all the results into a single object +func (c EnvironmentTypesClient) EnvironmentTypesListByDevCenterComplete(ctx context.Context, id DevCenterId, options EnvironmentTypesListByDevCenterOperationOptions) (EnvironmentTypesListByDevCenterCompleteResult, error) { + return c.EnvironmentTypesListByDevCenterCompleteMatchingPredicate(ctx, id, options, EnvironmentTypeOperationPredicate{}) +} + +// EnvironmentTypesListByDevCenterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EnvironmentTypesClient) EnvironmentTypesListByDevCenterCompleteMatchingPredicate(ctx context.Context, id DevCenterId, options EnvironmentTypesListByDevCenterOperationOptions, predicate EnvironmentTypeOperationPredicate) (result EnvironmentTypesListByDevCenterCompleteResult, err error) { + items := make([]EnvironmentType, 0) + + resp, err := c.EnvironmentTypesListByDevCenter(ctx, id, options) + if err != nil { + 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 = EnvironmentTypesListByDevCenterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypesupdate.go b/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypesupdate.go new file mode 100644 index 00000000000..563d3525a9a --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/method_environmenttypesupdate.go @@ -0,0 +1,58 @@ +package environmenttypes + +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 EnvironmentTypesUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EnvironmentType +} + +// EnvironmentTypesUpdate ... +func (c EnvironmentTypesClient) EnvironmentTypesUpdate(ctx context.Context, id DevCenterEnvironmentTypeId, input EnvironmentTypeUpdate) (result EnvironmentTypesUpdateOperationResponse, 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 EnvironmentType + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectallowedenvironmenttypesget.go b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectallowedenvironmenttypesget.go new file mode 100644 index 00000000000..2a648560215 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectallowedenvironmenttypesget.go @@ -0,0 +1,54 @@ +package environmenttypes + +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 ProjectAllowedEnvironmentTypesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AllowedEnvironmentType +} + +// ProjectAllowedEnvironmentTypesGet ... +func (c EnvironmentTypesClient) ProjectAllowedEnvironmentTypesGet(ctx context.Context, id AllowedEnvironmentTypeId) (result ProjectAllowedEnvironmentTypesGetOperationResponse, 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 AllowedEnvironmentType + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectallowedenvironmenttypeslist.go b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectallowedenvironmenttypeslist.go new file mode 100644 index 00000000000..738c5acc870 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectallowedenvironmenttypeslist.go @@ -0,0 +1,119 @@ +package environmenttypes + +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 ProjectAllowedEnvironmentTypesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AllowedEnvironmentType +} + +type ProjectAllowedEnvironmentTypesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []AllowedEnvironmentType +} + +type ProjectAllowedEnvironmentTypesListOperationOptions struct { + Top *int64 +} + +func DefaultProjectAllowedEnvironmentTypesListOperationOptions() ProjectAllowedEnvironmentTypesListOperationOptions { + return ProjectAllowedEnvironmentTypesListOperationOptions{} +} + +func (o ProjectAllowedEnvironmentTypesListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ProjectAllowedEnvironmentTypesListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ProjectAllowedEnvironmentTypesListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ProjectAllowedEnvironmentTypesList ... +func (c EnvironmentTypesClient) ProjectAllowedEnvironmentTypesList(ctx context.Context, id ProjectId, options ProjectAllowedEnvironmentTypesListOperationOptions) (result ProjectAllowedEnvironmentTypesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/allowedEnvironmentTypes", id.ID()), + OptionsObject: options, + } + + 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 *[]AllowedEnvironmentType `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ProjectAllowedEnvironmentTypesListComplete retrieves all the results into a single object +func (c EnvironmentTypesClient) ProjectAllowedEnvironmentTypesListComplete(ctx context.Context, id ProjectId, options ProjectAllowedEnvironmentTypesListOperationOptions) (ProjectAllowedEnvironmentTypesListCompleteResult, error) { + return c.ProjectAllowedEnvironmentTypesListCompleteMatchingPredicate(ctx, id, options, AllowedEnvironmentTypeOperationPredicate{}) +} + +// ProjectAllowedEnvironmentTypesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EnvironmentTypesClient) ProjectAllowedEnvironmentTypesListCompleteMatchingPredicate(ctx context.Context, id ProjectId, options ProjectAllowedEnvironmentTypesListOperationOptions, predicate AllowedEnvironmentTypeOperationPredicate) (result ProjectAllowedEnvironmentTypesListCompleteResult, err error) { + items := make([]AllowedEnvironmentType, 0) + + resp, err := c.ProjectAllowedEnvironmentTypesList(ctx, id, options) + if err != nil { + 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 = ProjectAllowedEnvironmentTypesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypescreateorupdate.go b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypescreateorupdate.go new file mode 100644 index 00000000000..204649cf11c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypescreateorupdate.go @@ -0,0 +1,59 @@ +package environmenttypes + +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 ProjectEnvironmentTypesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProjectEnvironmentType +} + +// ProjectEnvironmentTypesCreateOrUpdate ... +func (c EnvironmentTypesClient) ProjectEnvironmentTypesCreateOrUpdate(ctx context.Context, id EnvironmentTypeId, input ProjectEnvironmentType) (result ProjectEnvironmentTypesCreateOrUpdateOperationResponse, 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 + } + + var model ProjectEnvironmentType + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypesdelete.go b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypesdelete.go new file mode 100644 index 00000000000..9e5b47a66cf --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypesdelete.go @@ -0,0 +1,47 @@ +package environmenttypes + +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 ProjectEnvironmentTypesDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// ProjectEnvironmentTypesDelete ... +func (c EnvironmentTypesClient) ProjectEnvironmentTypesDelete(ctx context.Context, id EnvironmentTypeId) (result ProjectEnvironmentTypesDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + 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 + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypesget.go b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypesget.go new file mode 100644 index 00000000000..9b790b8dccd --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypesget.go @@ -0,0 +1,54 @@ +package environmenttypes + +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 ProjectEnvironmentTypesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProjectEnvironmentType +} + +// ProjectEnvironmentTypesGet ... +func (c EnvironmentTypesClient) ProjectEnvironmentTypesGet(ctx context.Context, id EnvironmentTypeId) (result ProjectEnvironmentTypesGetOperationResponse, 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 ProjectEnvironmentType + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypeslist.go b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypeslist.go new file mode 100644 index 00000000000..d8b1fa025ff --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypeslist.go @@ -0,0 +1,119 @@ +package environmenttypes + +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 ProjectEnvironmentTypesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ProjectEnvironmentType +} + +type ProjectEnvironmentTypesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ProjectEnvironmentType +} + +type ProjectEnvironmentTypesListOperationOptions struct { + Top *int64 +} + +func DefaultProjectEnvironmentTypesListOperationOptions() ProjectEnvironmentTypesListOperationOptions { + return ProjectEnvironmentTypesListOperationOptions{} +} + +func (o ProjectEnvironmentTypesListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ProjectEnvironmentTypesListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ProjectEnvironmentTypesListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ProjectEnvironmentTypesList ... +func (c EnvironmentTypesClient) ProjectEnvironmentTypesList(ctx context.Context, id ProjectId, options ProjectEnvironmentTypesListOperationOptions) (result ProjectEnvironmentTypesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/environmentTypes", id.ID()), + OptionsObject: options, + } + + 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 *[]ProjectEnvironmentType `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ProjectEnvironmentTypesListComplete retrieves all the results into a single object +func (c EnvironmentTypesClient) ProjectEnvironmentTypesListComplete(ctx context.Context, id ProjectId, options ProjectEnvironmentTypesListOperationOptions) (ProjectEnvironmentTypesListCompleteResult, error) { + return c.ProjectEnvironmentTypesListCompleteMatchingPredicate(ctx, id, options, ProjectEnvironmentTypeOperationPredicate{}) +} + +// ProjectEnvironmentTypesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EnvironmentTypesClient) ProjectEnvironmentTypesListCompleteMatchingPredicate(ctx context.Context, id ProjectId, options ProjectEnvironmentTypesListOperationOptions, predicate ProjectEnvironmentTypeOperationPredicate) (result ProjectEnvironmentTypesListCompleteResult, err error) { + items := make([]ProjectEnvironmentType, 0) + + resp, err := c.ProjectEnvironmentTypesList(ctx, id, options) + if err != nil { + 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 = ProjectEnvironmentTypesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypesupdate.go b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypesupdate.go new file mode 100644 index 00000000000..e4505a1a71f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/method_projectenvironmenttypesupdate.go @@ -0,0 +1,58 @@ +package environmenttypes + +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 ProjectEnvironmentTypesUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ProjectEnvironmentType +} + +// ProjectEnvironmentTypesUpdate ... +func (c EnvironmentTypesClient) ProjectEnvironmentTypesUpdate(ctx context.Context, id EnvironmentTypeId, input ProjectEnvironmentTypeUpdate) (result ProjectEnvironmentTypesUpdateOperationResponse, 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 ProjectEnvironmentType + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/model_allowedenvironmenttype.go b/resource-manager/devcenter/2024-02-01/environmenttypes/model_allowedenvironmenttype.go new file mode 100644 index 00000000000..36c6b2c3022 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/model_allowedenvironmenttype.go @@ -0,0 +1,16 @@ +package environmenttypes + +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 AllowedEnvironmentType struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AllowedEnvironmentTypeProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/model_allowedenvironmenttypeproperties.go b/resource-manager/devcenter/2024-02-01/environmenttypes/model_allowedenvironmenttypeproperties.go new file mode 100644 index 00000000000..72f5524acfa --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/model_allowedenvironmenttypeproperties.go @@ -0,0 +1,9 @@ +package environmenttypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AllowedEnvironmentTypeProperties struct { + DisplayName *string `json:"displayName,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmentrole.go b/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmentrole.go new file mode 100644 index 00000000000..d90ac0927d4 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmentrole.go @@ -0,0 +1,9 @@ +package environmenttypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnvironmentRole struct { + Description *string `json:"description,omitempty"` + RoleName *string `json:"roleName,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttype.go b/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttype.go new file mode 100644 index 00000000000..7489cf1eee9 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttype.go @@ -0,0 +1,17 @@ +package environmenttypes + +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 EnvironmentType struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EnvironmentTypeProperties `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/devcenter/2024-02-01/environmenttypes/model_environmenttypeproperties.go b/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttypeproperties.go new file mode 100644 index 00000000000..dd6ff6dc2e6 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttypeproperties.go @@ -0,0 +1,9 @@ +package environmenttypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnvironmentTypeProperties struct { + DisplayName *string `json:"displayName,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttypeupdate.go b/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttypeupdate.go new file mode 100644 index 00000000000..3ddfe96b862 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttypeupdate.go @@ -0,0 +1,9 @@ +package environmenttypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnvironmentTypeUpdate struct { + Properties *EnvironmentTypeUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttypeupdateproperties.go b/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttypeupdateproperties.go new file mode 100644 index 00000000000..c0ec36b1450 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/model_environmenttypeupdateproperties.go @@ -0,0 +1,8 @@ +package environmenttypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EnvironmentTypeUpdateProperties struct { + DisplayName *string `json:"displayName,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttype.go b/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttype.go new file mode 100644 index 00000000000..a9dae4ee7bd --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttype.go @@ -0,0 +1,20 @@ +package environmenttypes + +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 ProjectEnvironmentType struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ProjectEnvironmentTypeProperties `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/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeproperties.go b/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeproperties.go new file mode 100644 index 00000000000..a381ae774f8 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeproperties.go @@ -0,0 +1,14 @@ +package environmenttypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProjectEnvironmentTypeProperties struct { + CreatorRoleAssignment *ProjectEnvironmentTypeUpdatePropertiesCreatorRoleAssignment `json:"creatorRoleAssignment,omitempty"` + DeploymentTargetId *string `json:"deploymentTargetId,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + EnvironmentCount *int64 `json:"environmentCount,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + Status *EnvironmentTypeEnableStatus `json:"status,omitempty"` + UserRoleAssignments *map[string]UserRoleAssignment `json:"userRoleAssignments,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeupdate.go b/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeupdate.go new file mode 100644 index 00000000000..b2ba53ab095 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeupdate.go @@ -0,0 +1,14 @@ +package environmenttypes + +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 ProjectEnvironmentTypeUpdate struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *ProjectEnvironmentTypeUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeupdateproperties.go b/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeupdateproperties.go new file mode 100644 index 00000000000..30a71af0d51 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeupdateproperties.go @@ -0,0 +1,12 @@ +package environmenttypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProjectEnvironmentTypeUpdateProperties struct { + CreatorRoleAssignment *ProjectEnvironmentTypeUpdatePropertiesCreatorRoleAssignment `json:"creatorRoleAssignment,omitempty"` + DeploymentTargetId *string `json:"deploymentTargetId,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + Status *EnvironmentTypeEnableStatus `json:"status,omitempty"` + UserRoleAssignments *map[string]UserRoleAssignment `json:"userRoleAssignments,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeupdatepropertiescreatorroleassignment.go b/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeupdatepropertiescreatorroleassignment.go new file mode 100644 index 00000000000..0b23c9e9674 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/model_projectenvironmenttypeupdatepropertiescreatorroleassignment.go @@ -0,0 +1,8 @@ +package environmenttypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProjectEnvironmentTypeUpdatePropertiesCreatorRoleAssignment struct { + Roles *map[string]EnvironmentRole `json:"roles,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/model_userroleassignment.go b/resource-manager/devcenter/2024-02-01/environmenttypes/model_userroleassignment.go new file mode 100644 index 00000000000..19dcc142347 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/model_userroleassignment.go @@ -0,0 +1,8 @@ +package environmenttypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserRoleAssignment struct { + Roles *map[string]EnvironmentRole `json:"roles,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/environmenttypes/predicates.go b/resource-manager/devcenter/2024-02-01/environmenttypes/predicates.go new file mode 100644 index 00000000000..5f2969a1aa3 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/predicates.go @@ -0,0 +1,78 @@ +package environmenttypes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AllowedEnvironmentTypeOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p AllowedEnvironmentTypeOperationPredicate) Matches(input AllowedEnvironmentType) 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 EnvironmentTypeOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p EnvironmentTypeOperationPredicate) Matches(input EnvironmentType) 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 ProjectEnvironmentTypeOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ProjectEnvironmentTypeOperationPredicate) Matches(input ProjectEnvironmentType) 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/devcenter/2024-02-01/environmenttypes/version.go b/resource-manager/devcenter/2024-02-01/environmenttypes/version.go new file mode 100644 index 00000000000..9b61bc5c6af --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/environmenttypes/version.go @@ -0,0 +1,12 @@ +package environmenttypes + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/environmenttypes/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/galleries/README.md b/resource-manager/devcenter/2024-02-01/galleries/README.md new file mode 100644 index 00000000000..bdd416b7527 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/galleries` Documentation + +The `galleries` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/galleries" +``` + + +### Client Initialization + +```go +client := galleries.NewGalleriesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GalleriesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := galleries.NewGalleryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue") + +payload := galleries.Gallery{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `GalleriesClient.Delete` + +```go +ctx := context.TODO() +id := galleries.NewGalleryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `GalleriesClient.Get` + +```go +ctx := context.TODO() +id := galleries.NewGalleryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue") + +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: `GalleriesClient.ListByDevCenter` + +```go +ctx := context.TODO() +id := galleries.NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + +// alternatively `client.ListByDevCenter(ctx, id, galleries.DefaultListByDevCenterOperationOptions())` can be used to do batched pagination +items, err := client.ListByDevCenterComplete(ctx, id, galleries.DefaultListByDevCenterOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/devcenter/2024-02-01/galleries/client.go b/resource-manager/devcenter/2024-02-01/galleries/client.go new file mode 100644 index 00000000000..624f4aaf60a --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/client.go @@ -0,0 +1,26 @@ +package galleries + +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 GalleriesClient struct { + Client *resourcemanager.Client +} + +func NewGalleriesClientWithBaseURI(sdkApi sdkEnv.Api) (*GalleriesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "galleries", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating GalleriesClient: %+v", err) + } + + return &GalleriesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/galleries/constants.go b/resource-manager/devcenter/2024-02-01/galleries/constants.go new file mode 100644 index 00000000000..18040c92fad --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/constants.go @@ -0,0 +1,93 @@ +package galleries + +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 ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMovingResources ProvisioningState = "MovingResources" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateRolloutInProgress ProvisioningState = "RolloutInProgress" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateStorageProvisioningFailed ProvisioningState = "StorageProvisioningFailed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateTransientFailure ProvisioningState = "TransientFailure" + ProvisioningStateUpdated ProvisioningState = "Updated" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMovingResources), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateRolloutInProgress), + string(ProvisioningStateRunning), + string(ProvisioningStateStorageProvisioningFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateTransientFailure), + string(ProvisioningStateUpdated), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "movingresources": ProvisioningStateMovingResources, + "notspecified": ProvisioningStateNotSpecified, + "rolloutinprogress": ProvisioningStateRolloutInProgress, + "running": ProvisioningStateRunning, + "storageprovisioningfailed": ProvisioningStateStorageProvisioningFailed, + "succeeded": ProvisioningStateSucceeded, + "transientfailure": ProvisioningStateTransientFailure, + "updated": ProvisioningStateUpdated, + "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/devcenter/2024-02-01/galleries/id_devcenter.go b/resource-manager/devcenter/2024-02-01/galleries/id_devcenter.go new file mode 100644 index 00000000000..8059cf633d3 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/id_devcenter.go @@ -0,0 +1,125 @@ +package galleries + +import ( + "fmt" + "strings" + + "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 = &DevCenterId{} + +// DevCenterId is a struct representing the Resource ID for a Dev Center +type DevCenterId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string +} + +// NewDevCenterID returns a new DevCenterId struct +func NewDevCenterID(subscriptionId string, resourceGroupName string, devCenterName string) DevCenterId { + return DevCenterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + } +} + +// ParseDevCenterID parses 'input' into a DevCenterId +func ParseDevCenterID(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDevCenterIDInsensitively parses 'input' case-insensitively into a DevCenterId +// note: this method should only be used for API response data and not user input +func ParseDevCenterIDInsensitively(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DevCenterId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + return nil +} + +// ValidateDevCenterID checks that 'input' can be parsed as a Dev Center ID +func ValidateDevCenterID(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 := ParseDevCenterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dev Center ID +func (id DevCenterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dev Center ID +func (id DevCenterId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + } +} + +// String returns a human-readable description of this Dev Center ID +func (id DevCenterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + } + return fmt.Sprintf("Dev Center (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/galleries/id_devcenter_test.go b/resource-manager/devcenter/2024-02-01/galleries/id_devcenter_test.go new file mode 100644 index 00000000000..a23718704b7 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/id_devcenter_test.go @@ -0,0 +1,282 @@ +package galleries + +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 = &DevCenterId{} + +func TestNewDevCenterID(t *testing.T) { + id := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } +} + +func TestFormatDevCenterID(t *testing.T) { + actual := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDevCenterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestParseDevCenterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestSegmentsForDevCenterId(t *testing.T) { + segments := DevCenterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DevCenterId 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/devcenter/2024-02-01/galleries/id_gallery.go b/resource-manager/devcenter/2024-02-01/galleries/id_gallery.go new file mode 100644 index 00000000000..9c40ada56fb --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/id_gallery.go @@ -0,0 +1,134 @@ +package galleries + +import ( + "fmt" + "strings" + + "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 = &GalleryId{} + +// GalleryId is a struct representing the Resource ID for a Gallery +type GalleryId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string + GalleryName string +} + +// NewGalleryID returns a new GalleryId struct +func NewGalleryID(subscriptionId string, resourceGroupName string, devCenterName string, galleryName string) GalleryId { + return GalleryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + GalleryName: galleryName, + } +} + +// ParseGalleryID parses 'input' into a GalleryId +func ParseGalleryID(input string) (*GalleryId, error) { + parser := resourceids.NewParserFromResourceIdType(&GalleryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GalleryId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGalleryIDInsensitively parses 'input' case-insensitively into a GalleryId +// note: this method should only be used for API response data and not user input +func ParseGalleryIDInsensitively(input string) (*GalleryId, error) { + parser := resourceids.NewParserFromResourceIdType(&GalleryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GalleryId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GalleryId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + if id.GalleryName, ok = input.Parsed["galleryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "galleryName", input) + } + + return nil +} + +// ValidateGalleryID checks that 'input' can be parsed as a Gallery ID +func ValidateGalleryID(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 := ParseGalleryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Gallery ID +func (id GalleryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s/galleries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName, id.GalleryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Gallery ID +func (id GalleryId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + resourceids.StaticSegment("staticGalleries", "galleries", "galleries"), + resourceids.UserSpecifiedSegment("galleryName", "galleryValue"), + } +} + +// String returns a human-readable description of this Gallery ID +func (id GalleryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + fmt.Sprintf("Gallery Name: %q", id.GalleryName), + } + return fmt.Sprintf("Gallery (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/galleries/id_gallery_test.go b/resource-manager/devcenter/2024-02-01/galleries/id_gallery_test.go new file mode 100644 index 00000000000..ddb2fe73b8c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/id_gallery_test.go @@ -0,0 +1,327 @@ +package galleries + +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 = &GalleryId{} + +func TestNewGalleryID(t *testing.T) { + id := NewGalleryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } + + if id.GalleryName != "galleryValue" { + t.Fatalf("Expected %q but got %q for Segment 'GalleryName'", id.GalleryName, "galleryValue") + } +} + +func TestFormatGalleryID(t *testing.T) { + actual := NewGalleryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGalleryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GalleryId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue", + Expected: &GalleryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + GalleryName: "galleryValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGalleryID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.GalleryName != v.Expected.GalleryName { + t.Fatalf("Expected %q but got %q for GalleryName", v.Expected.GalleryName, actual.GalleryName) + } + + } +} + +func TestParseGalleryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GalleryId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue", + Expected: &GalleryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + GalleryName: "galleryValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE", + Expected: &GalleryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + GalleryName: "gAlLeRyVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGalleryIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.GalleryName != v.Expected.GalleryName { + t.Fatalf("Expected %q but got %q for GalleryName", v.Expected.GalleryName, actual.GalleryName) + } + + } +} + +func TestSegmentsForGalleryId(t *testing.T) { + segments := GalleryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GalleryId 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/devcenter/2024-02-01/galleries/method_createorupdate.go b/resource-manager/devcenter/2024-02-01/galleries/method_createorupdate.go new file mode 100644 index 00000000000..5e45a00584f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/method_createorupdate.go @@ -0,0 +1,75 @@ +package galleries + +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 *Gallery +} + +// CreateOrUpdate ... +func (c GalleriesClient) CreateOrUpdate(ctx context.Context, id GalleryId, input Gallery) (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 GalleriesClient) CreateOrUpdateThenPoll(ctx context.Context, id GalleryId, input Gallery) 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/devcenter/2024-02-01/galleries/method_delete.go b/resource-manager/devcenter/2024-02-01/galleries/method_delete.go new file mode 100644 index 00000000000..b8d76c37e70 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/method_delete.go @@ -0,0 +1,70 @@ +package galleries + +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 GalleriesClient) Delete(ctx context.Context, id GalleryId) (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 GalleriesClient) DeleteThenPoll(ctx context.Context, id GalleryId) 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/devcenter/2024-02-01/galleries/method_get.go b/resource-manager/devcenter/2024-02-01/galleries/method_get.go new file mode 100644 index 00000000000..5262914c268 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/method_get.go @@ -0,0 +1,54 @@ +package galleries + +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 *Gallery +} + +// Get ... +func (c GalleriesClient) Get(ctx context.Context, id GalleryId) (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 Gallery + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/galleries/method_listbydevcenter.go b/resource-manager/devcenter/2024-02-01/galleries/method_listbydevcenter.go new file mode 100644 index 00000000000..12213c86621 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/method_listbydevcenter.go @@ -0,0 +1,119 @@ +package galleries + +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 ListByDevCenterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Gallery +} + +type ListByDevCenterCompleteResult struct { + LatestHttpResponse *http.Response + Items []Gallery +} + +type ListByDevCenterOperationOptions struct { + Top *int64 +} + +func DefaultListByDevCenterOperationOptions() ListByDevCenterOperationOptions { + return ListByDevCenterOperationOptions{} +} + +func (o ListByDevCenterOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDevCenterOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByDevCenterOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByDevCenter ... +func (c GalleriesClient) ListByDevCenter(ctx context.Context, id DevCenterId, options ListByDevCenterOperationOptions) (result ListByDevCenterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/galleries", id.ID()), + OptionsObject: options, + } + + 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 *[]Gallery `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDevCenterComplete retrieves all the results into a single object +func (c GalleriesClient) ListByDevCenterComplete(ctx context.Context, id DevCenterId, options ListByDevCenterOperationOptions) (ListByDevCenterCompleteResult, error) { + return c.ListByDevCenterCompleteMatchingPredicate(ctx, id, options, GalleryOperationPredicate{}) +} + +// ListByDevCenterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c GalleriesClient) ListByDevCenterCompleteMatchingPredicate(ctx context.Context, id DevCenterId, options ListByDevCenterOperationOptions, predicate GalleryOperationPredicate) (result ListByDevCenterCompleteResult, err error) { + items := make([]Gallery, 0) + + resp, err := c.ListByDevCenter(ctx, id, options) + if err != nil { + 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 = ListByDevCenterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/galleries/model_gallery.go b/resource-manager/devcenter/2024-02-01/galleries/model_gallery.go new file mode 100644 index 00000000000..80cd2ef549c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/model_gallery.go @@ -0,0 +1,16 @@ +package galleries + +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 Gallery struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *GalleryProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/galleries/model_galleryproperties.go b/resource-manager/devcenter/2024-02-01/galleries/model_galleryproperties.go new file mode 100644 index 00000000000..82a6d21cec8 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/model_galleryproperties.go @@ -0,0 +1,9 @@ +package galleries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryProperties struct { + GalleryResourceId string `json:"galleryResourceId"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/galleries/predicates.go b/resource-manager/devcenter/2024-02-01/galleries/predicates.go new file mode 100644 index 00000000000..9239985c7ba --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/predicates.go @@ -0,0 +1,27 @@ +package galleries + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GalleryOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p GalleryOperationPredicate) Matches(input Gallery) 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/devcenter/2024-02-01/galleries/version.go b/resource-manager/devcenter/2024-02-01/galleries/version.go new file mode 100644 index 00000000000..3c625285d93 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/galleries/version.go @@ -0,0 +1,12 @@ +package galleries + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/galleries/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/images/README.md b/resource-manager/devcenter/2024-02-01/images/README.md new file mode 100644 index 00000000000..a393946a878 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/images` Documentation + +The `images` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/images" +``` + + +### Client Initialization + +```go +client := images.NewImagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ImagesClient.Get` + +```go +ctx := context.TODO() +id := images.NewImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue", "imageValue") + +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: `ImagesClient.ListByDevCenter` + +```go +ctx := context.TODO() +id := images.NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + +// alternatively `client.ListByDevCenter(ctx, id, images.DefaultListByDevCenterOperationOptions())` can be used to do batched pagination +items, err := client.ListByDevCenterComplete(ctx, id, images.DefaultListByDevCenterOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ImagesClient.ListByGallery` + +```go +ctx := context.TODO() +id := images.NewGalleryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue") + +// alternatively `client.ListByGallery(ctx, id, images.DefaultListByGalleryOperationOptions())` can be used to do batched pagination +items, err := client.ListByGalleryComplete(ctx, id, images.DefaultListByGalleryOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/devcenter/2024-02-01/images/client.go b/resource-manager/devcenter/2024-02-01/images/client.go new file mode 100644 index 00000000000..efdeb17e082 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/client.go @@ -0,0 +1,26 @@ +package images + +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 ImagesClient struct { + Client *resourcemanager.Client +} + +func NewImagesClientWithBaseURI(sdkApi sdkEnv.Api) (*ImagesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "images", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ImagesClient: %+v", err) + } + + return &ImagesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/images/constants.go b/resource-manager/devcenter/2024-02-01/images/constants.go new file mode 100644 index 00000000000..26969e92d5d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/constants.go @@ -0,0 +1,134 @@ +package images + +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 HibernateSupport string + +const ( + HibernateSupportDisabled HibernateSupport = "Disabled" + HibernateSupportEnabled HibernateSupport = "Enabled" +) + +func PossibleValuesForHibernateSupport() []string { + return []string{ + string(HibernateSupportDisabled), + string(HibernateSupportEnabled), + } +} + +func (s *HibernateSupport) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHibernateSupport(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHibernateSupport(input string) (*HibernateSupport, error) { + vals := map[string]HibernateSupport{ + "disabled": HibernateSupportDisabled, + "enabled": HibernateSupportEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HibernateSupport(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMovingResources ProvisioningState = "MovingResources" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateRolloutInProgress ProvisioningState = "RolloutInProgress" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateStorageProvisioningFailed ProvisioningState = "StorageProvisioningFailed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateTransientFailure ProvisioningState = "TransientFailure" + ProvisioningStateUpdated ProvisioningState = "Updated" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMovingResources), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateRolloutInProgress), + string(ProvisioningStateRunning), + string(ProvisioningStateStorageProvisioningFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateTransientFailure), + string(ProvisioningStateUpdated), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "movingresources": ProvisioningStateMovingResources, + "notspecified": ProvisioningStateNotSpecified, + "rolloutinprogress": ProvisioningStateRolloutInProgress, + "running": ProvisioningStateRunning, + "storageprovisioningfailed": ProvisioningStateStorageProvisioningFailed, + "succeeded": ProvisioningStateSucceeded, + "transientfailure": ProvisioningStateTransientFailure, + "updated": ProvisioningStateUpdated, + "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/devcenter/2024-02-01/images/id_devcenter.go b/resource-manager/devcenter/2024-02-01/images/id_devcenter.go new file mode 100644 index 00000000000..1b54c4596e6 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/id_devcenter.go @@ -0,0 +1,125 @@ +package images + +import ( + "fmt" + "strings" + + "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 = &DevCenterId{} + +// DevCenterId is a struct representing the Resource ID for a Dev Center +type DevCenterId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string +} + +// NewDevCenterID returns a new DevCenterId struct +func NewDevCenterID(subscriptionId string, resourceGroupName string, devCenterName string) DevCenterId { + return DevCenterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + } +} + +// ParseDevCenterID parses 'input' into a DevCenterId +func ParseDevCenterID(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDevCenterIDInsensitively parses 'input' case-insensitively into a DevCenterId +// note: this method should only be used for API response data and not user input +func ParseDevCenterIDInsensitively(input string) (*DevCenterId, error) { + parser := resourceids.NewParserFromResourceIdType(&DevCenterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DevCenterId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DevCenterId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + return nil +} + +// ValidateDevCenterID checks that 'input' can be parsed as a Dev Center ID +func ValidateDevCenterID(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 := ParseDevCenterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Dev Center ID +func (id DevCenterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Dev Center ID +func (id DevCenterId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + } +} + +// String returns a human-readable description of this Dev Center ID +func (id DevCenterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + } + return fmt.Sprintf("Dev Center (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/images/id_devcenter_test.go b/resource-manager/devcenter/2024-02-01/images/id_devcenter_test.go new file mode 100644 index 00000000000..842d00dd646 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/id_devcenter_test.go @@ -0,0 +1,282 @@ +package images + +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 = &DevCenterId{} + +func TestNewDevCenterID(t *testing.T) { + id := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } +} + +func TestFormatDevCenterID(t *testing.T) { + actual := NewDevCenterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDevCenterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestParseDevCenterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DevCenterId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Expected: &DevCenterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDevCenterIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + } +} + +func TestSegmentsForDevCenterId(t *testing.T) { + segments := DevCenterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DevCenterId 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/devcenter/2024-02-01/images/id_gallery.go b/resource-manager/devcenter/2024-02-01/images/id_gallery.go new file mode 100644 index 00000000000..d76d2da1147 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/id_gallery.go @@ -0,0 +1,134 @@ +package images + +import ( + "fmt" + "strings" + + "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 = &GalleryId{} + +// GalleryId is a struct representing the Resource ID for a Gallery +type GalleryId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string + GalleryName string +} + +// NewGalleryID returns a new GalleryId struct +func NewGalleryID(subscriptionId string, resourceGroupName string, devCenterName string, galleryName string) GalleryId { + return GalleryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + GalleryName: galleryName, + } +} + +// ParseGalleryID parses 'input' into a GalleryId +func ParseGalleryID(input string) (*GalleryId, error) { + parser := resourceids.NewParserFromResourceIdType(&GalleryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GalleryId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseGalleryIDInsensitively parses 'input' case-insensitively into a GalleryId +// note: this method should only be used for API response data and not user input +func ParseGalleryIDInsensitively(input string) (*GalleryId, error) { + parser := resourceids.NewParserFromResourceIdType(&GalleryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := GalleryId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *GalleryId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + if id.GalleryName, ok = input.Parsed["galleryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "galleryName", input) + } + + return nil +} + +// ValidateGalleryID checks that 'input' can be parsed as a Gallery ID +func ValidateGalleryID(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 := ParseGalleryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Gallery ID +func (id GalleryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s/galleries/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName, id.GalleryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Gallery ID +func (id GalleryId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + resourceids.StaticSegment("staticGalleries", "galleries", "galleries"), + resourceids.UserSpecifiedSegment("galleryName", "galleryValue"), + } +} + +// String returns a human-readable description of this Gallery ID +func (id GalleryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + fmt.Sprintf("Gallery Name: %q", id.GalleryName), + } + return fmt.Sprintf("Gallery (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/images/id_gallery_test.go b/resource-manager/devcenter/2024-02-01/images/id_gallery_test.go new file mode 100644 index 00000000000..dff3fd526ea --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/id_gallery_test.go @@ -0,0 +1,327 @@ +package images + +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 = &GalleryId{} + +func TestNewGalleryID(t *testing.T) { + id := NewGalleryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } + + if id.GalleryName != "galleryValue" { + t.Fatalf("Expected %q but got %q for Segment 'GalleryName'", id.GalleryName, "galleryValue") + } +} + +func TestFormatGalleryID(t *testing.T) { + actual := NewGalleryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseGalleryID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GalleryId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue", + Expected: &GalleryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + GalleryName: "galleryValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGalleryID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.GalleryName != v.Expected.GalleryName { + t.Fatalf("Expected %q but got %q for GalleryName", v.Expected.GalleryName, actual.GalleryName) + } + + } +} + +func TestParseGalleryIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *GalleryId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue", + Expected: &GalleryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + GalleryName: "galleryValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE", + Expected: &GalleryId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + GalleryName: "gAlLeRyVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseGalleryIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.GalleryName != v.Expected.GalleryName { + t.Fatalf("Expected %q but got %q for GalleryName", v.Expected.GalleryName, actual.GalleryName) + } + + } +} + +func TestSegmentsForGalleryId(t *testing.T) { + segments := GalleryId{}.Segments() + if len(segments) == 0 { + t.Fatalf("GalleryId 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/devcenter/2024-02-01/images/id_image.go b/resource-manager/devcenter/2024-02-01/images/id_image.go new file mode 100644 index 00000000000..e394622df76 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/id_image.go @@ -0,0 +1,143 @@ +package images + +import ( + "fmt" + "strings" + + "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 = &ImageId{} + +// ImageId is a struct representing the Resource ID for a Image +type ImageId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string + GalleryName string + ImageName string +} + +// NewImageID returns a new ImageId struct +func NewImageID(subscriptionId string, resourceGroupName string, devCenterName string, galleryName string, imageName string) ImageId { + return ImageId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + GalleryName: galleryName, + ImageName: imageName, + } +} + +// ParseImageID parses 'input' into a ImageId +func ParseImageID(input string) (*ImageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ImageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ImageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseImageIDInsensitively parses 'input' case-insensitively into a ImageId +// note: this method should only be used for API response data and not user input +func ParseImageIDInsensitively(input string) (*ImageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ImageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ImageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ImageId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + if id.GalleryName, ok = input.Parsed["galleryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "galleryName", input) + } + + if id.ImageName, ok = input.Parsed["imageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "imageName", input) + } + + return nil +} + +// ValidateImageID checks that 'input' can be parsed as a Image ID +func ValidateImageID(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 := ParseImageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Image ID +func (id ImageId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s/galleries/%s/images/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName, id.GalleryName, id.ImageName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Image ID +func (id ImageId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + resourceids.StaticSegment("staticGalleries", "galleries", "galleries"), + resourceids.UserSpecifiedSegment("galleryName", "galleryValue"), + resourceids.StaticSegment("staticImages", "images", "images"), + resourceids.UserSpecifiedSegment("imageName", "imageValue"), + } +} + +// String returns a human-readable description of this Image ID +func (id ImageId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + fmt.Sprintf("Gallery Name: %q", id.GalleryName), + fmt.Sprintf("Image Name: %q", id.ImageName), + } + return fmt.Sprintf("Image (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/images/id_image_test.go b/resource-manager/devcenter/2024-02-01/images/id_image_test.go new file mode 100644 index 00000000000..ab0c2cf30b3 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/id_image_test.go @@ -0,0 +1,372 @@ +package images + +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 = &ImageId{} + +func TestNewImageID(t *testing.T) { + id := NewImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue", "imageValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } + + if id.GalleryName != "galleryValue" { + t.Fatalf("Expected %q but got %q for Segment 'GalleryName'", id.GalleryName, "galleryValue") + } + + if id.ImageName != "imageValue" { + t.Fatalf("Expected %q but got %q for Segment 'ImageName'", id.ImageName, "imageValue") + } +} + +func TestFormatImageID(t *testing.T) { + actual := NewImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue", "imageValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseImageID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ImageId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue", + Expected: &ImageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + GalleryName: "galleryValue", + ImageName: "imageValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseImageID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.GalleryName != v.Expected.GalleryName { + t.Fatalf("Expected %q but got %q for GalleryName", v.Expected.GalleryName, actual.GalleryName) + } + + if actual.ImageName != v.Expected.ImageName { + t.Fatalf("Expected %q but got %q for ImageName", v.Expected.ImageName, actual.ImageName) + } + + } +} + +func TestParseImageIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ImageId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE/iMaGeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue", + Expected: &ImageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + GalleryName: "galleryValue", + ImageName: "imageValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE/iMaGeS/iMaGeVaLuE", + Expected: &ImageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + GalleryName: "gAlLeRyVaLuE", + ImageName: "iMaGeVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE/iMaGeS/iMaGeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseImageIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.GalleryName != v.Expected.GalleryName { + t.Fatalf("Expected %q but got %q for GalleryName", v.Expected.GalleryName, actual.GalleryName) + } + + if actual.ImageName != v.Expected.ImageName { + t.Fatalf("Expected %q but got %q for ImageName", v.Expected.ImageName, actual.ImageName) + } + + } +} + +func TestSegmentsForImageId(t *testing.T) { + segments := ImageId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ImageId 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/devcenter/2024-02-01/images/method_get.go b/resource-manager/devcenter/2024-02-01/images/method_get.go new file mode 100644 index 00000000000..07d56032538 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/method_get.go @@ -0,0 +1,54 @@ +package images + +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 *Image +} + +// Get ... +func (c ImagesClient) Get(ctx context.Context, id ImageId) (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 Image + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/images/method_listbydevcenter.go b/resource-manager/devcenter/2024-02-01/images/method_listbydevcenter.go new file mode 100644 index 00000000000..ffdba8a89a9 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/method_listbydevcenter.go @@ -0,0 +1,119 @@ +package images + +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 ListByDevCenterOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Image +} + +type ListByDevCenterCompleteResult struct { + LatestHttpResponse *http.Response + Items []Image +} + +type ListByDevCenterOperationOptions struct { + Top *int64 +} + +func DefaultListByDevCenterOperationOptions() ListByDevCenterOperationOptions { + return ListByDevCenterOperationOptions{} +} + +func (o ListByDevCenterOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByDevCenterOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByDevCenterOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByDevCenter ... +func (c ImagesClient) ListByDevCenter(ctx context.Context, id DevCenterId, options ListByDevCenterOperationOptions) (result ListByDevCenterOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/images", id.ID()), + OptionsObject: options, + } + + 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 *[]Image `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByDevCenterComplete retrieves all the results into a single object +func (c ImagesClient) ListByDevCenterComplete(ctx context.Context, id DevCenterId, options ListByDevCenterOperationOptions) (ListByDevCenterCompleteResult, error) { + return c.ListByDevCenterCompleteMatchingPredicate(ctx, id, options, ImageOperationPredicate{}) +} + +// ListByDevCenterCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ImagesClient) ListByDevCenterCompleteMatchingPredicate(ctx context.Context, id DevCenterId, options ListByDevCenterOperationOptions, predicate ImageOperationPredicate) (result ListByDevCenterCompleteResult, err error) { + items := make([]Image, 0) + + resp, err := c.ListByDevCenter(ctx, id, options) + if err != nil { + 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 = ListByDevCenterCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/images/method_listbygallery.go b/resource-manager/devcenter/2024-02-01/images/method_listbygallery.go new file mode 100644 index 00000000000..82ddc7f1e08 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/method_listbygallery.go @@ -0,0 +1,119 @@ +package images + +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 ListByGalleryOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Image +} + +type ListByGalleryCompleteResult struct { + LatestHttpResponse *http.Response + Items []Image +} + +type ListByGalleryOperationOptions struct { + Top *int64 +} + +func DefaultListByGalleryOperationOptions() ListByGalleryOperationOptions { + return ListByGalleryOperationOptions{} +} + +func (o ListByGalleryOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByGalleryOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByGalleryOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByGallery ... +func (c ImagesClient) ListByGallery(ctx context.Context, id GalleryId, options ListByGalleryOperationOptions) (result ListByGalleryOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/images", id.ID()), + OptionsObject: options, + } + + 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 *[]Image `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByGalleryComplete retrieves all the results into a single object +func (c ImagesClient) ListByGalleryComplete(ctx context.Context, id GalleryId, options ListByGalleryOperationOptions) (ListByGalleryCompleteResult, error) { + return c.ListByGalleryCompleteMatchingPredicate(ctx, id, options, ImageOperationPredicate{}) +} + +// ListByGalleryCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ImagesClient) ListByGalleryCompleteMatchingPredicate(ctx context.Context, id GalleryId, options ListByGalleryOperationOptions, predicate ImageOperationPredicate) (result ListByGalleryCompleteResult, err error) { + items := make([]Image, 0) + + resp, err := c.ListByGallery(ctx, id, options) + if err != nil { + 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 = ListByGalleryCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/images/model_image.go b/resource-manager/devcenter/2024-02-01/images/model_image.go new file mode 100644 index 00000000000..0d7bfed1afb --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/model_image.go @@ -0,0 +1,16 @@ +package images + +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 Image struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ImageProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/images/model_imageproperties.go b/resource-manager/devcenter/2024-02-01/images/model_imageproperties.go new file mode 100644 index 00000000000..605ad2f38a0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/model_imageproperties.go @@ -0,0 +1,14 @@ +package images + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImageProperties struct { + Description *string `json:"description,omitempty"` + HibernateSupport *HibernateSupport `json:"hibernateSupport,omitempty"` + Offer *string `json:"offer,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + Publisher *string `json:"publisher,omitempty"` + RecommendedMachineConfiguration *RecommendedMachineConfiguration `json:"recommendedMachineConfiguration,omitempty"` + Sku *string `json:"sku,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/images/model_recommendedmachineconfiguration.go b/resource-manager/devcenter/2024-02-01/images/model_recommendedmachineconfiguration.go new file mode 100644 index 00000000000..c97d4e521f1 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/model_recommendedmachineconfiguration.go @@ -0,0 +1,9 @@ +package images + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RecommendedMachineConfiguration struct { + Memory *ResourceRange `json:"memory,omitempty"` + VCPUs *ResourceRange `json:"vCPUs,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/images/model_resourcerange.go b/resource-manager/devcenter/2024-02-01/images/model_resourcerange.go new file mode 100644 index 00000000000..440cf0b86a6 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/model_resourcerange.go @@ -0,0 +1,9 @@ +package images + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceRange struct { + Max *int64 `json:"max,omitempty"` + Min *int64 `json:"min,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/images/predicates.go b/resource-manager/devcenter/2024-02-01/images/predicates.go new file mode 100644 index 00000000000..482466c517c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/predicates.go @@ -0,0 +1,27 @@ +package images + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImageOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ImageOperationPredicate) Matches(input Image) 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/devcenter/2024-02-01/images/version.go b/resource-manager/devcenter/2024-02-01/images/version.go new file mode 100644 index 00000000000..4ef5ec2c5cd --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/images/version.go @@ -0,0 +1,12 @@ +package images + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/images/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/imageversions/README.md b/resource-manager/devcenter/2024-02-01/imageversions/README.md new file mode 100644 index 00000000000..c005455ba94 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/imageversions/README.md @@ -0,0 +1,53 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/imageversions` Documentation + +The `imageversions` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/imageversions" +``` + + +### Client Initialization + +```go +client := imageversions.NewImageVersionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ImageVersionsClient.Get` + +```go +ctx := context.TODO() +id := imageversions.NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue", "imageValue", "versionValue") + +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: `ImageVersionsClient.ListByImage` + +```go +ctx := context.TODO() +id := imageversions.NewImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue", "imageValue") + +// alternatively `client.ListByImage(ctx, id)` can be used to do batched pagination +items, err := client.ListByImageComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/devcenter/2024-02-01/imageversions/client.go b/resource-manager/devcenter/2024-02-01/imageversions/client.go new file mode 100644 index 00000000000..e7f72638c73 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/imageversions/client.go @@ -0,0 +1,26 @@ +package imageversions + +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 ImageVersionsClient struct { + Client *resourcemanager.Client +} + +func NewImageVersionsClientWithBaseURI(sdkApi sdkEnv.Api) (*ImageVersionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "imageversions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ImageVersionsClient: %+v", err) + } + + return &ImageVersionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/imageversions/constants.go b/resource-manager/devcenter/2024-02-01/imageversions/constants.go new file mode 100644 index 00000000000..5882b6cff21 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/imageversions/constants.go @@ -0,0 +1,93 @@ +package imageversions + +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 ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMovingResources ProvisioningState = "MovingResources" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateRolloutInProgress ProvisioningState = "RolloutInProgress" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateStorageProvisioningFailed ProvisioningState = "StorageProvisioningFailed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateTransientFailure ProvisioningState = "TransientFailure" + ProvisioningStateUpdated ProvisioningState = "Updated" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMovingResources), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateRolloutInProgress), + string(ProvisioningStateRunning), + string(ProvisioningStateStorageProvisioningFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateTransientFailure), + string(ProvisioningStateUpdated), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "movingresources": ProvisioningStateMovingResources, + "notspecified": ProvisioningStateNotSpecified, + "rolloutinprogress": ProvisioningStateRolloutInProgress, + "running": ProvisioningStateRunning, + "storageprovisioningfailed": ProvisioningStateStorageProvisioningFailed, + "succeeded": ProvisioningStateSucceeded, + "transientfailure": ProvisioningStateTransientFailure, + "updated": ProvisioningStateUpdated, + "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/devcenter/2024-02-01/imageversions/id_image.go b/resource-manager/devcenter/2024-02-01/imageversions/id_image.go new file mode 100644 index 00000000000..1ef414a3451 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/imageversions/id_image.go @@ -0,0 +1,143 @@ +package imageversions + +import ( + "fmt" + "strings" + + "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 = &ImageId{} + +// ImageId is a struct representing the Resource ID for a Image +type ImageId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string + GalleryName string + ImageName string +} + +// NewImageID returns a new ImageId struct +func NewImageID(subscriptionId string, resourceGroupName string, devCenterName string, galleryName string, imageName string) ImageId { + return ImageId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + GalleryName: galleryName, + ImageName: imageName, + } +} + +// ParseImageID parses 'input' into a ImageId +func ParseImageID(input string) (*ImageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ImageId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ImageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseImageIDInsensitively parses 'input' case-insensitively into a ImageId +// note: this method should only be used for API response data and not user input +func ParseImageIDInsensitively(input string) (*ImageId, error) { + parser := resourceids.NewParserFromResourceIdType(&ImageId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ImageId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ImageId) 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + if id.GalleryName, ok = input.Parsed["galleryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "galleryName", input) + } + + if id.ImageName, ok = input.Parsed["imageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "imageName", input) + } + + return nil +} + +// ValidateImageID checks that 'input' can be parsed as a Image ID +func ValidateImageID(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 := ParseImageID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Image ID +func (id ImageId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/devCenters/%s/galleries/%s/images/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName, id.GalleryName, id.ImageName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Image ID +func (id ImageId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + resourceids.StaticSegment("staticGalleries", "galleries", "galleries"), + resourceids.UserSpecifiedSegment("galleryName", "galleryValue"), + resourceids.StaticSegment("staticImages", "images", "images"), + resourceids.UserSpecifiedSegment("imageName", "imageValue"), + } +} + +// String returns a human-readable description of this Image ID +func (id ImageId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Dev Center Name: %q", id.DevCenterName), + fmt.Sprintf("Gallery Name: %q", id.GalleryName), + fmt.Sprintf("Image Name: %q", id.ImageName), + } + return fmt.Sprintf("Image (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/imageversions/id_image_test.go b/resource-manager/devcenter/2024-02-01/imageversions/id_image_test.go new file mode 100644 index 00000000000..d9cd7d81dee --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/imageversions/id_image_test.go @@ -0,0 +1,372 @@ +package imageversions + +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 = &ImageId{} + +func TestNewImageID(t *testing.T) { + id := NewImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue", "imageValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } + + if id.GalleryName != "galleryValue" { + t.Fatalf("Expected %q but got %q for Segment 'GalleryName'", id.GalleryName, "galleryValue") + } + + if id.ImageName != "imageValue" { + t.Fatalf("Expected %q but got %q for Segment 'ImageName'", id.ImageName, "imageValue") + } +} + +func TestFormatImageID(t *testing.T) { + actual := NewImageID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue", "imageValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseImageID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ImageId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue", + Expected: &ImageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + GalleryName: "galleryValue", + ImageName: "imageValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseImageID(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.GalleryName != v.Expected.GalleryName { + t.Fatalf("Expected %q but got %q for GalleryName", v.Expected.GalleryName, actual.GalleryName) + } + + if actual.ImageName != v.Expected.ImageName { + t.Fatalf("Expected %q but got %q for ImageName", v.Expected.ImageName, actual.ImageName) + } + + } +} + +func TestParseImageIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ImageId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE/iMaGeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue", + Expected: &ImageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + GalleryName: "galleryValue", + ImageName: "imageValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE/iMaGeS/iMaGeVaLuE", + Expected: &ImageId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + GalleryName: "gAlLeRyVaLuE", + ImageName: "iMaGeVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE/iMaGeS/iMaGeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseImageIDInsensitively(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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.GalleryName != v.Expected.GalleryName { + t.Fatalf("Expected %q but got %q for GalleryName", v.Expected.GalleryName, actual.GalleryName) + } + + if actual.ImageName != v.Expected.ImageName { + t.Fatalf("Expected %q but got %q for ImageName", v.Expected.ImageName, actual.ImageName) + } + + } +} + +func TestSegmentsForImageId(t *testing.T) { + segments := ImageId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ImageId 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/devcenter/2024-02-01/imageversions/id_version.go b/resource-manager/devcenter/2024-02-01/imageversions/id_version.go new file mode 100644 index 00000000000..32d350073aa --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/imageversions/id_version.go @@ -0,0 +1,152 @@ +package imageversions + +import ( + "fmt" + "strings" + + "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{} + +// VersionId is a struct representing the Resource ID for a Version +type VersionId struct { + SubscriptionId string + ResourceGroupName string + DevCenterName string + GalleryName string + ImageName string + VersionName string +} + +// NewVersionID returns a new VersionId struct +func NewVersionID(subscriptionId string, resourceGroupName string, devCenterName string, galleryName string, imageName string, versionName string) VersionId { + return VersionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + DevCenterName: devCenterName, + GalleryName: galleryName, + ImageName: imageName, + 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.DevCenterName, ok = input.Parsed["devCenterName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "devCenterName", input) + } + + if id.GalleryName, ok = input.Parsed["galleryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "galleryName", input) + } + + if id.ImageName, ok = input.Parsed["imageName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "imageName", 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.DevCenter/devCenters/%s/galleries/%s/images/%s/versions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.DevCenterName, id.GalleryName, id.ImageName, 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticDevCenters", "devCenters", "devCenters"), + resourceids.UserSpecifiedSegment("devCenterName", "devCenterValue"), + resourceids.StaticSegment("staticGalleries", "galleries", "galleries"), + resourceids.UserSpecifiedSegment("galleryName", "galleryValue"), + resourceids.StaticSegment("staticImages", "images", "images"), + resourceids.UserSpecifiedSegment("imageName", "imageValue"), + resourceids.StaticSegment("staticVersions", "versions", "versions"), + resourceids.UserSpecifiedSegment("versionName", "versionValue"), + } +} + +// 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("Dev Center Name: %q", id.DevCenterName), + fmt.Sprintf("Gallery Name: %q", id.GalleryName), + fmt.Sprintf("Image Name: %q", id.ImageName), + fmt.Sprintf("Version Name: %q", id.VersionName), + } + return fmt.Sprintf("Version (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/imageversions/id_version_test.go b/resource-manager/devcenter/2024-02-01/imageversions/id_version_test.go new file mode 100644 index 00000000000..82bf157ca2a --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/imageversions/id_version_test.go @@ -0,0 +1,417 @@ +package imageversions + +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", "devCenterValue", "galleryValue", "imageValue", "versionValue") + + 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.DevCenterName != "devCenterValue" { + t.Fatalf("Expected %q but got %q for Segment 'DevCenterName'", id.DevCenterName, "devCenterValue") + } + + if id.GalleryName != "galleryValue" { + t.Fatalf("Expected %q but got %q for Segment 'GalleryName'", id.GalleryName, "galleryValue") + } + + if id.ImageName != "imageValue" { + t.Fatalf("Expected %q but got %q for Segment 'ImageName'", id.ImageName, "imageValue") + } + + if id.VersionName != "versionValue" { + t.Fatalf("Expected %q but got %q for Segment 'VersionName'", id.VersionName, "versionValue") + } +} + +func TestFormatVersionID(t *testing.T) { + actual := NewVersionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "devCenterValue", "galleryValue", "imageValue", "versionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue/versions/versionValue" + 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue/versions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue/versions/versionValue", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + GalleryName: "galleryValue", + ImageName: "imageValue", + VersionName: "versionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue/versions/versionValue/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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.GalleryName != v.Expected.GalleryName { + t.Fatalf("Expected %q but got %q for GalleryName", v.Expected.GalleryName, actual.GalleryName) + } + + if actual.ImageName != v.Expected.ImageName { + t.Fatalf("Expected %q but got %q for ImageName", v.Expected.ImageName, actual.ImageName) + } + + 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE/iMaGeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE/iMaGeS/iMaGeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue/versions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE/iMaGeS/iMaGeVaLuE/vErSiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue/versions/versionValue", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + DevCenterName: "devCenterValue", + GalleryName: "galleryValue", + ImageName: "imageValue", + VersionName: "versionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/devCenters/devCenterValue/galleries/galleryValue/images/imageValue/versions/versionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE/iMaGeS/iMaGeVaLuE/vErSiOnS/vErSiOnVaLuE", + Expected: &VersionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DevCenterName: "dEvCeNtErVaLuE", + GalleryName: "gAlLeRyVaLuE", + ImageName: "iMaGeVaLuE", + VersionName: "vErSiOnVaLuE", + }, + }, + { + // 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.dEvCeNtEr/dEvCeNtErS/dEvCeNtErVaLuE/gAlLeRiEs/gAlLeRyVaLuE/iMaGeS/iMaGeVaLuE/vErSiOnS/vErSiOnVaLuE/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.DevCenterName != v.Expected.DevCenterName { + t.Fatalf("Expected %q but got %q for DevCenterName", v.Expected.DevCenterName, actual.DevCenterName) + } + + if actual.GalleryName != v.Expected.GalleryName { + t.Fatalf("Expected %q but got %q for GalleryName", v.Expected.GalleryName, actual.GalleryName) + } + + if actual.ImageName != v.Expected.ImageName { + t.Fatalf("Expected %q but got %q for ImageName", v.Expected.ImageName, actual.ImageName) + } + + 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/devcenter/2024-02-01/imageversions/method_get.go b/resource-manager/devcenter/2024-02-01/imageversions/method_get.go new file mode 100644 index 00000000000..4a32465bcd3 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/imageversions/method_get.go @@ -0,0 +1,54 @@ +package imageversions + +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 *ImageVersion +} + +// Get ... +func (c ImageVersionsClient) 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 ImageVersion + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/imageversions/method_listbyimage.go b/resource-manager/devcenter/2024-02-01/imageversions/method_listbyimage.go new file mode 100644 index 00000000000..c82b39de6af --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/imageversions/method_listbyimage.go @@ -0,0 +1,91 @@ +package imageversions + +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 ListByImageOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ImageVersion +} + +type ListByImageCompleteResult struct { + LatestHttpResponse *http.Response + Items []ImageVersion +} + +// ListByImage ... +func (c ImageVersionsClient) ListByImage(ctx context.Context, id ImageId) (result ListByImageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + 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 *[]ImageVersion `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByImageComplete retrieves all the results into a single object +func (c ImageVersionsClient) ListByImageComplete(ctx context.Context, id ImageId) (ListByImageCompleteResult, error) { + return c.ListByImageCompleteMatchingPredicate(ctx, id, ImageVersionOperationPredicate{}) +} + +// ListByImageCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ImageVersionsClient) ListByImageCompleteMatchingPredicate(ctx context.Context, id ImageId, predicate ImageVersionOperationPredicate) (result ListByImageCompleteResult, err error) { + items := make([]ImageVersion, 0) + + resp, err := c.ListByImage(ctx, id) + if err != nil { + 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 = ListByImageCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/imageversions/model_imageversion.go b/resource-manager/devcenter/2024-02-01/imageversions/model_imageversion.go new file mode 100644 index 00000000000..9080d66706e --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/imageversions/model_imageversion.go @@ -0,0 +1,16 @@ +package imageversions + +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 ImageVersion struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ImageVersionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/imageversions/model_imageversionproperties.go b/resource-manager/devcenter/2024-02-01/imageversions/model_imageversionproperties.go new file mode 100644 index 00000000000..6752a36cd1d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/imageversions/model_imageversionproperties.go @@ -0,0 +1,30 @@ +package imageversions + +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 ImageVersionProperties struct { + ExcludeFromLatest *bool `json:"excludeFromLatest,omitempty"` + Name *string `json:"name,omitempty"` + OsDiskImageSizeInGb *int64 `json:"osDiskImageSizeInGb,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + PublishedDate *string `json:"publishedDate,omitempty"` +} + +func (o *ImageVersionProperties) GetPublishedDateAsTime() (*time.Time, error) { + if o.PublishedDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.PublishedDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ImageVersionProperties) SetPublishedDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.PublishedDate = &formatted +} diff --git a/resource-manager/devcenter/2024-02-01/imageversions/predicates.go b/resource-manager/devcenter/2024-02-01/imageversions/predicates.go new file mode 100644 index 00000000000..4744837f5f3 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/imageversions/predicates.go @@ -0,0 +1,27 @@ +package imageversions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ImageVersionOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ImageVersionOperationPredicate) Matches(input ImageVersion) 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/devcenter/2024-02-01/imageversions/version.go b/resource-manager/devcenter/2024-02-01/imageversions/version.go new file mode 100644 index 00000000000..8d11cf53bb5 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/imageversions/version.go @@ -0,0 +1,12 @@ +package imageversions + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/imageversions/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnection/README.md b/resource-manager/devcenter/2024-02-01/networkconnection/README.md new file mode 100644 index 00000000000..22ef6d1242b --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnection/README.md @@ -0,0 +1,49 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/networkconnection` Documentation + +The `networkconnection` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/networkconnection" +``` + + +### Client Initialization + +```go +client := networkconnection.NewNetworkConnectionClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NetworkConnectionClient.ListOutboundNetworkDependenciesEndpoints` + +```go +ctx := context.TODO() +id := networkconnection.NewNetworkConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "networkConnectionValue") + +// alternatively `client.ListOutboundNetworkDependenciesEndpoints(ctx, id)` can be used to do batched pagination +items, err := client.ListOutboundNetworkDependenciesEndpointsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NetworkConnectionClient.RunHealthChecks` + +```go +ctx := context.TODO() +id := networkconnection.NewNetworkConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "networkConnectionValue") + +if err := client.RunHealthChecksThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/devcenter/2024-02-01/networkconnection/client.go b/resource-manager/devcenter/2024-02-01/networkconnection/client.go new file mode 100644 index 00000000000..c4b7f5032ee --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnection/client.go @@ -0,0 +1,26 @@ +package networkconnection + +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 NetworkConnectionClient struct { + Client *resourcemanager.Client +} + +func NewNetworkConnectionClientWithBaseURI(sdkApi sdkEnv.Api) (*NetworkConnectionClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "networkconnection", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NetworkConnectionClient: %+v", err) + } + + return &NetworkConnectionClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnection/id_networkconnection.go b/resource-manager/devcenter/2024-02-01/networkconnection/id_networkconnection.go new file mode 100644 index 00000000000..ce569626f16 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnection/id_networkconnection.go @@ -0,0 +1,125 @@ +package networkconnection + +import ( + "fmt" + "strings" + + "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 = &NetworkConnectionId{} + +// NetworkConnectionId is a struct representing the Resource ID for a Network Connection +type NetworkConnectionId struct { + SubscriptionId string + ResourceGroupName string + NetworkConnectionName string +} + +// NewNetworkConnectionID returns a new NetworkConnectionId struct +func NewNetworkConnectionID(subscriptionId string, resourceGroupName string, networkConnectionName string) NetworkConnectionId { + return NetworkConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NetworkConnectionName: networkConnectionName, + } +} + +// ParseNetworkConnectionID parses 'input' into a NetworkConnectionId +func ParseNetworkConnectionID(input string) (*NetworkConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&NetworkConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NetworkConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNetworkConnectionIDInsensitively parses 'input' case-insensitively into a NetworkConnectionId +// note: this method should only be used for API response data and not user input +func ParseNetworkConnectionIDInsensitively(input string) (*NetworkConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&NetworkConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NetworkConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NetworkConnectionId) 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.NetworkConnectionName, ok = input.Parsed["networkConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "networkConnectionName", input) + } + + return nil +} + +// ValidateNetworkConnectionID checks that 'input' can be parsed as a Network Connection ID +func ValidateNetworkConnectionID(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 := ParseNetworkConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Network Connection ID +func (id NetworkConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/networkConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NetworkConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Network Connection ID +func (id NetworkConnectionId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticNetworkConnections", "networkConnections", "networkConnections"), + resourceids.UserSpecifiedSegment("networkConnectionName", "networkConnectionValue"), + } +} + +// String returns a human-readable description of this Network Connection ID +func (id NetworkConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Network Connection Name: %q", id.NetworkConnectionName), + } + return fmt.Sprintf("Network Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnection/id_networkconnection_test.go b/resource-manager/devcenter/2024-02-01/networkconnection/id_networkconnection_test.go new file mode 100644 index 00000000000..801d51df2a2 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnection/id_networkconnection_test.go @@ -0,0 +1,282 @@ +package networkconnection + +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 = &NetworkConnectionId{} + +func TestNewNetworkConnectionID(t *testing.T) { + id := NewNetworkConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "networkConnectionValue") + + 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.NetworkConnectionName != "networkConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'NetworkConnectionName'", id.NetworkConnectionName, "networkConnectionValue") + } +} + +func TestFormatNetworkConnectionID(t *testing.T) { + actual := NewNetworkConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "networkConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections/networkConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNetworkConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NetworkConnectionId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections/networkConnectionValue", + Expected: &NetworkConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NetworkConnectionName: "networkConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections/networkConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNetworkConnectionID(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.NetworkConnectionName != v.Expected.NetworkConnectionName { + t.Fatalf("Expected %q but got %q for NetworkConnectionName", v.Expected.NetworkConnectionName, actual.NetworkConnectionName) + } + + } +} + +func TestParseNetworkConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NetworkConnectionId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/nEtWoRkCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections/networkConnectionValue", + Expected: &NetworkConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NetworkConnectionName: "networkConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections/networkConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/nEtWoRkCoNnEcTiOnS/nEtWoRkCoNnEcTiOnVaLuE", + Expected: &NetworkConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NetworkConnectionName: "nEtWoRkCoNnEcTiOnVaLuE", + }, + }, + { + // 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.dEvCeNtEr/nEtWoRkCoNnEcTiOnS/nEtWoRkCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNetworkConnectionIDInsensitively(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.NetworkConnectionName != v.Expected.NetworkConnectionName { + t.Fatalf("Expected %q but got %q for NetworkConnectionName", v.Expected.NetworkConnectionName, actual.NetworkConnectionName) + } + + } +} + +func TestSegmentsForNetworkConnectionId(t *testing.T) { + segments := NetworkConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NetworkConnectionId 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/devcenter/2024-02-01/networkconnection/method_listoutboundnetworkdependenciesendpoints.go b/resource-manager/devcenter/2024-02-01/networkconnection/method_listoutboundnetworkdependenciesendpoints.go new file mode 100644 index 00000000000..5fd69c8ac29 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnection/method_listoutboundnetworkdependenciesendpoints.go @@ -0,0 +1,91 @@ +package networkconnection + +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 ListOutboundNetworkDependenciesEndpointsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]OutboundEnvironmentEndpoint +} + +type ListOutboundNetworkDependenciesEndpointsCompleteResult struct { + LatestHttpResponse *http.Response + Items []OutboundEnvironmentEndpoint +} + +// ListOutboundNetworkDependenciesEndpoints ... +func (c NetworkConnectionClient) ListOutboundNetworkDependenciesEndpoints(ctx context.Context, id NetworkConnectionId) (result ListOutboundNetworkDependenciesEndpointsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/outboundNetworkDependenciesEndpoints", 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 *[]OutboundEnvironmentEndpoint `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListOutboundNetworkDependenciesEndpointsComplete retrieves all the results into a single object +func (c NetworkConnectionClient) ListOutboundNetworkDependenciesEndpointsComplete(ctx context.Context, id NetworkConnectionId) (ListOutboundNetworkDependenciesEndpointsCompleteResult, error) { + return c.ListOutboundNetworkDependenciesEndpointsCompleteMatchingPredicate(ctx, id, OutboundEnvironmentEndpointOperationPredicate{}) +} + +// ListOutboundNetworkDependenciesEndpointsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NetworkConnectionClient) ListOutboundNetworkDependenciesEndpointsCompleteMatchingPredicate(ctx context.Context, id NetworkConnectionId, predicate OutboundEnvironmentEndpointOperationPredicate) (result ListOutboundNetworkDependenciesEndpointsCompleteResult, err error) { + items := make([]OutboundEnvironmentEndpoint, 0) + + resp, err := c.ListOutboundNetworkDependenciesEndpoints(ctx, id) + if err != nil { + 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 = ListOutboundNetworkDependenciesEndpointsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnection/method_runhealthchecks.go b/resource-manager/devcenter/2024-02-01/networkconnection/method_runhealthchecks.go new file mode 100644 index 00000000000..c927fa5d16c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnection/method_runhealthchecks.go @@ -0,0 +1,69 @@ +package networkconnection + +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 RunHealthChecksOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// RunHealthChecks ... +func (c NetworkConnectionClient) RunHealthChecks(ctx context.Context, id NetworkConnectionId) (result RunHealthChecksOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/runHealthChecks", 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 +} + +// RunHealthChecksThenPoll performs RunHealthChecks then polls until it's completed +func (c NetworkConnectionClient) RunHealthChecksThenPoll(ctx context.Context, id NetworkConnectionId) error { + result, err := c.RunHealthChecks(ctx, id) + if err != nil { + return fmt.Errorf("performing RunHealthChecks: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RunHealthChecks: %+v", err) + } + + return nil +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnection/model_endpointdependency.go b/resource-manager/devcenter/2024-02-01/networkconnection/model_endpointdependency.go new file mode 100644 index 00000000000..f60209e4718 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnection/model_endpointdependency.go @@ -0,0 +1,10 @@ +package networkconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointDependency struct { + Description *string `json:"description,omitempty"` + DomainName *string `json:"domainName,omitempty"` + EndpointDetails *[]EndpointDetail `json:"endpointDetails,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnection/model_endpointdetail.go b/resource-manager/devcenter/2024-02-01/networkconnection/model_endpointdetail.go new file mode 100644 index 00000000000..4b11a7fd350 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnection/model_endpointdetail.go @@ -0,0 +1,8 @@ +package networkconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EndpointDetail struct { + Port *int64 `json:"port,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnection/model_outboundenvironmentendpoint.go b/resource-manager/devcenter/2024-02-01/networkconnection/model_outboundenvironmentendpoint.go new file mode 100644 index 00000000000..52168c3b8ab --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnection/model_outboundenvironmentendpoint.go @@ -0,0 +1,9 @@ +package networkconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OutboundEnvironmentEndpoint struct { + Category *string `json:"category,omitempty"` + Endpoints *[]EndpointDependency `json:"endpoints,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnection/predicates.go b/resource-manager/devcenter/2024-02-01/networkconnection/predicates.go new file mode 100644 index 00000000000..b72a6b0c0cb --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnection/predicates.go @@ -0,0 +1,17 @@ +package networkconnection + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OutboundEnvironmentEndpointOperationPredicate struct { + Category *string +} + +func (p OutboundEnvironmentEndpointOperationPredicate) Matches(input OutboundEnvironmentEndpoint) bool { + + if p.Category != nil && (input.Category == nil || *p.Category != *input.Category) { + return false + } + + return true +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnection/version.go b/resource-manager/devcenter/2024-02-01/networkconnection/version.go new file mode 100644 index 00000000000..a9a06fc471a --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnection/version.go @@ -0,0 +1,12 @@ +package networkconnection + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/networkconnection/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnections/README.md b/resource-manager/devcenter/2024-02-01/networkconnections/README.md new file mode 100644 index 00000000000..ec06f930313 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/README.md @@ -0,0 +1,150 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/networkconnections` Documentation + +The `networkconnections` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/networkconnections" +``` + + +### Client Initialization + +```go +client := networkconnections.NewNetworkConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `NetworkConnectionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := networkconnections.NewNetworkConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "networkConnectionValue") + +payload := networkconnections.NetworkConnection{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `NetworkConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := networkconnections.NewNetworkConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "networkConnectionValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `NetworkConnectionsClient.Get` + +```go +ctx := context.TODO() +id := networkconnections.NewNetworkConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "networkConnectionValue") + +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: `NetworkConnectionsClient.GetHealthDetails` + +```go +ctx := context.TODO() +id := networkconnections.NewNetworkConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "networkConnectionValue") + +read, err := client.GetHealthDetails(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `NetworkConnectionsClient.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: `NetworkConnectionsClient.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: `NetworkConnectionsClient.ListHealthDetails` + +```go +ctx := context.TODO() +id := networkconnections.NewNetworkConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "networkConnectionValue") + +// alternatively `client.ListHealthDetails(ctx, id)` can be used to do batched pagination +items, err := client.ListHealthDetailsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `NetworkConnectionsClient.Update` + +```go +ctx := context.TODO() +id := networkconnections.NewNetworkConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "networkConnectionValue") + +payload := networkconnections.NetworkConnectionUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/devcenter/2024-02-01/networkconnections/client.go b/resource-manager/devcenter/2024-02-01/networkconnections/client.go new file mode 100644 index 00000000000..b8ed056a338 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/client.go @@ -0,0 +1,26 @@ +package networkconnections + +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 NetworkConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewNetworkConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*NetworkConnectionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "networkconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating NetworkConnectionsClient: %+v", err) + } + + return &NetworkConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnections/constants.go b/resource-manager/devcenter/2024-02-01/networkconnections/constants.go new file mode 100644 index 00000000000..aac513c80db --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/constants.go @@ -0,0 +1,187 @@ +package networkconnections + +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 DomainJoinType string + +const ( + DomainJoinTypeAzureADJoin DomainJoinType = "AzureADJoin" + DomainJoinTypeHybridAzureADJoin DomainJoinType = "HybridAzureADJoin" +) + +func PossibleValuesForDomainJoinType() []string { + return []string{ + string(DomainJoinTypeAzureADJoin), + string(DomainJoinTypeHybridAzureADJoin), + } +} + +func (s *DomainJoinType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDomainJoinType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDomainJoinType(input string) (*DomainJoinType, error) { + vals := map[string]DomainJoinType{ + "azureadjoin": DomainJoinTypeAzureADJoin, + "hybridazureadjoin": DomainJoinTypeHybridAzureADJoin, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DomainJoinType(input) + return &out, nil +} + +type HealthCheckStatus string + +const ( + HealthCheckStatusFailed HealthCheckStatus = "Failed" + HealthCheckStatusPassed HealthCheckStatus = "Passed" + HealthCheckStatusPending HealthCheckStatus = "Pending" + HealthCheckStatusRunning HealthCheckStatus = "Running" + HealthCheckStatusUnknown HealthCheckStatus = "Unknown" + HealthCheckStatusWarning HealthCheckStatus = "Warning" +) + +func PossibleValuesForHealthCheckStatus() []string { + return []string{ + string(HealthCheckStatusFailed), + string(HealthCheckStatusPassed), + string(HealthCheckStatusPending), + string(HealthCheckStatusRunning), + string(HealthCheckStatusUnknown), + string(HealthCheckStatusWarning), + } +} + +func (s *HealthCheckStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHealthCheckStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHealthCheckStatus(input string) (*HealthCheckStatus, error) { + vals := map[string]HealthCheckStatus{ + "failed": HealthCheckStatusFailed, + "passed": HealthCheckStatusPassed, + "pending": HealthCheckStatusPending, + "running": HealthCheckStatusRunning, + "unknown": HealthCheckStatusUnknown, + "warning": HealthCheckStatusWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthCheckStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMovingResources ProvisioningState = "MovingResources" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateRolloutInProgress ProvisioningState = "RolloutInProgress" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateStorageProvisioningFailed ProvisioningState = "StorageProvisioningFailed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateTransientFailure ProvisioningState = "TransientFailure" + ProvisioningStateUpdated ProvisioningState = "Updated" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMovingResources), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateRolloutInProgress), + string(ProvisioningStateRunning), + string(ProvisioningStateStorageProvisioningFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateTransientFailure), + string(ProvisioningStateUpdated), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "movingresources": ProvisioningStateMovingResources, + "notspecified": ProvisioningStateNotSpecified, + "rolloutinprogress": ProvisioningStateRolloutInProgress, + "running": ProvisioningStateRunning, + "storageprovisioningfailed": ProvisioningStateStorageProvisioningFailed, + "succeeded": ProvisioningStateSucceeded, + "transientfailure": ProvisioningStateTransientFailure, + "updated": ProvisioningStateUpdated, + "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/devcenter/2024-02-01/networkconnections/id_networkconnection.go b/resource-manager/devcenter/2024-02-01/networkconnections/id_networkconnection.go new file mode 100644 index 00000000000..ecfd8303855 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/id_networkconnection.go @@ -0,0 +1,125 @@ +package networkconnections + +import ( + "fmt" + "strings" + + "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 = &NetworkConnectionId{} + +// NetworkConnectionId is a struct representing the Resource ID for a Network Connection +type NetworkConnectionId struct { + SubscriptionId string + ResourceGroupName string + NetworkConnectionName string +} + +// NewNetworkConnectionID returns a new NetworkConnectionId struct +func NewNetworkConnectionID(subscriptionId string, resourceGroupName string, networkConnectionName string) NetworkConnectionId { + return NetworkConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + NetworkConnectionName: networkConnectionName, + } +} + +// ParseNetworkConnectionID parses 'input' into a NetworkConnectionId +func ParseNetworkConnectionID(input string) (*NetworkConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&NetworkConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NetworkConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseNetworkConnectionIDInsensitively parses 'input' case-insensitively into a NetworkConnectionId +// note: this method should only be used for API response data and not user input +func ParseNetworkConnectionIDInsensitively(input string) (*NetworkConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&NetworkConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := NetworkConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *NetworkConnectionId) 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.NetworkConnectionName, ok = input.Parsed["networkConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "networkConnectionName", input) + } + + return nil +} + +// ValidateNetworkConnectionID checks that 'input' can be parsed as a Network Connection ID +func ValidateNetworkConnectionID(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 := ParseNetworkConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Network Connection ID +func (id NetworkConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/networkConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NetworkConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Network Connection ID +func (id NetworkConnectionId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticNetworkConnections", "networkConnections", "networkConnections"), + resourceids.UserSpecifiedSegment("networkConnectionName", "networkConnectionValue"), + } +} + +// String returns a human-readable description of this Network Connection ID +func (id NetworkConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Network Connection Name: %q", id.NetworkConnectionName), + } + return fmt.Sprintf("Network Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnections/id_networkconnection_test.go b/resource-manager/devcenter/2024-02-01/networkconnections/id_networkconnection_test.go new file mode 100644 index 00000000000..286c203ff13 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/id_networkconnection_test.go @@ -0,0 +1,282 @@ +package networkconnections + +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 = &NetworkConnectionId{} + +func TestNewNetworkConnectionID(t *testing.T) { + id := NewNetworkConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "networkConnectionValue") + + 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.NetworkConnectionName != "networkConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'NetworkConnectionName'", id.NetworkConnectionName, "networkConnectionValue") + } +} + +func TestFormatNetworkConnectionID(t *testing.T) { + actual := NewNetworkConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "networkConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections/networkConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseNetworkConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NetworkConnectionId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections/networkConnectionValue", + Expected: &NetworkConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NetworkConnectionName: "networkConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections/networkConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNetworkConnectionID(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.NetworkConnectionName != v.Expected.NetworkConnectionName { + t.Fatalf("Expected %q but got %q for NetworkConnectionName", v.Expected.NetworkConnectionName, actual.NetworkConnectionName) + } + + } +} + +func TestParseNetworkConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *NetworkConnectionId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/nEtWoRkCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections/networkConnectionValue", + Expected: &NetworkConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + NetworkConnectionName: "networkConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/networkConnections/networkConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/nEtWoRkCoNnEcTiOnS/nEtWoRkCoNnEcTiOnVaLuE", + Expected: &NetworkConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + NetworkConnectionName: "nEtWoRkCoNnEcTiOnVaLuE", + }, + }, + { + // 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.dEvCeNtEr/nEtWoRkCoNnEcTiOnS/nEtWoRkCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseNetworkConnectionIDInsensitively(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.NetworkConnectionName != v.Expected.NetworkConnectionName { + t.Fatalf("Expected %q but got %q for NetworkConnectionName", v.Expected.NetworkConnectionName, actual.NetworkConnectionName) + } + + } +} + +func TestSegmentsForNetworkConnectionId(t *testing.T) { + segments := NetworkConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("NetworkConnectionId 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/devcenter/2024-02-01/networkconnections/method_createorupdate.go b/resource-manager/devcenter/2024-02-01/networkconnections/method_createorupdate.go new file mode 100644 index 00000000000..976ca23e530 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/method_createorupdate.go @@ -0,0 +1,75 @@ +package networkconnections + +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 *NetworkConnection +} + +// CreateOrUpdate ... +func (c NetworkConnectionsClient) CreateOrUpdate(ctx context.Context, id NetworkConnectionId, input NetworkConnection) (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 NetworkConnectionsClient) CreateOrUpdateThenPoll(ctx context.Context, id NetworkConnectionId, input NetworkConnection) 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/devcenter/2024-02-01/networkconnections/method_delete.go b/resource-manager/devcenter/2024-02-01/networkconnections/method_delete.go new file mode 100644 index 00000000000..3cbed4b855c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/method_delete.go @@ -0,0 +1,70 @@ +package networkconnections + +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 NetworkConnectionsClient) Delete(ctx context.Context, id NetworkConnectionId) (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 NetworkConnectionsClient) DeleteThenPoll(ctx context.Context, id NetworkConnectionId) 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/devcenter/2024-02-01/networkconnections/method_get.go b/resource-manager/devcenter/2024-02-01/networkconnections/method_get.go new file mode 100644 index 00000000000..fbc2a39d16d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/method_get.go @@ -0,0 +1,54 @@ +package networkconnections + +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 *NetworkConnection +} + +// Get ... +func (c NetworkConnectionsClient) Get(ctx context.Context, id NetworkConnectionId) (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 NetworkConnection + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnections/method_gethealthdetails.go b/resource-manager/devcenter/2024-02-01/networkconnections/method_gethealthdetails.go new file mode 100644 index 00000000000..ae0a8f73ead --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/method_gethealthdetails.go @@ -0,0 +1,55 @@ +package networkconnections + +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 GetHealthDetailsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *HealthCheckStatusDetails +} + +// GetHealthDetails ... +func (c NetworkConnectionsClient) GetHealthDetails(ctx context.Context, id NetworkConnectionId) (result GetHealthDetailsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/healthChecks/latest", 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 HealthCheckStatusDetails + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnections/method_listbyresourcegroup.go b/resource-manager/devcenter/2024-02-01/networkconnections/method_listbyresourcegroup.go new file mode 100644 index 00000000000..8d1a69e7bcc --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/method_listbyresourcegroup.go @@ -0,0 +1,92 @@ +package networkconnections + +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 *[]NetworkConnection +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []NetworkConnection +} + +// ListByResourceGroup ... +func (c NetworkConnectionsClient) 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, + Path: fmt.Sprintf("%s/providers/Microsoft.DevCenter/networkConnections", 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 *[]NetworkConnection `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 NetworkConnectionsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, NetworkConnectionOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NetworkConnectionsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate NetworkConnectionOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]NetworkConnection, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + 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/devcenter/2024-02-01/networkconnections/method_listbysubscription.go b/resource-manager/devcenter/2024-02-01/networkconnections/method_listbysubscription.go new file mode 100644 index 00000000000..3d0e7a3602e --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/method_listbysubscription.go @@ -0,0 +1,92 @@ +package networkconnections + +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 *[]NetworkConnection +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []NetworkConnection +} + +// ListBySubscription ... +func (c NetworkConnectionsClient) 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, + Path: fmt.Sprintf("%s/providers/Microsoft.DevCenter/networkConnections", 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 *[]NetworkConnection `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 NetworkConnectionsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, NetworkConnectionOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NetworkConnectionsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate NetworkConnectionOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]NetworkConnection, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + 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/devcenter/2024-02-01/networkconnections/method_listhealthdetails.go b/resource-manager/devcenter/2024-02-01/networkconnections/method_listhealthdetails.go new file mode 100644 index 00000000000..0495523dc7a --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/method_listhealthdetails.go @@ -0,0 +1,91 @@ +package networkconnections + +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 ListHealthDetailsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]HealthCheckStatusDetails +} + +type ListHealthDetailsCompleteResult struct { + LatestHttpResponse *http.Response + Items []HealthCheckStatusDetails +} + +// ListHealthDetails ... +func (c NetworkConnectionsClient) ListHealthDetails(ctx context.Context, id NetworkConnectionId) (result ListHealthDetailsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/healthChecks", 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 *[]HealthCheckStatusDetails `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListHealthDetailsComplete retrieves all the results into a single object +func (c NetworkConnectionsClient) ListHealthDetailsComplete(ctx context.Context, id NetworkConnectionId) (ListHealthDetailsCompleteResult, error) { + return c.ListHealthDetailsCompleteMatchingPredicate(ctx, id, HealthCheckStatusDetailsOperationPredicate{}) +} + +// ListHealthDetailsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c NetworkConnectionsClient) ListHealthDetailsCompleteMatchingPredicate(ctx context.Context, id NetworkConnectionId, predicate HealthCheckStatusDetailsOperationPredicate) (result ListHealthDetailsCompleteResult, err error) { + items := make([]HealthCheckStatusDetails, 0) + + resp, err := c.ListHealthDetails(ctx, id) + if err != nil { + 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 = ListHealthDetailsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnections/method_update.go b/resource-manager/devcenter/2024-02-01/networkconnections/method_update.go new file mode 100644 index 00000000000..883c3582a1c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/method_update.go @@ -0,0 +1,75 @@ +package networkconnections + +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 *NetworkConnection +} + +// Update ... +func (c NetworkConnectionsClient) Update(ctx context.Context, id NetworkConnectionId, input NetworkConnectionUpdate) (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 NetworkConnectionsClient) UpdateThenPoll(ctx context.Context, id NetworkConnectionId, input NetworkConnectionUpdate) 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/devcenter/2024-02-01/networkconnections/model_healthcheck.go b/resource-manager/devcenter/2024-02-01/networkconnections/model_healthcheck.go new file mode 100644 index 00000000000..7fe9ec60b0d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/model_healthcheck.go @@ -0,0 +1,44 @@ +package networkconnections + +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 HealthCheck struct { + AdditionalDetails *string `json:"additionalDetails,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + EndDateTime *string `json:"endDateTime,omitempty"` + ErrorType *string `json:"errorType,omitempty"` + RecommendedAction *string `json:"recommendedAction,omitempty"` + StartDateTime *string `json:"startDateTime,omitempty"` + Status *HealthCheckStatus `json:"status,omitempty"` +} + +func (o *HealthCheck) GetEndDateTimeAsTime() (*time.Time, error) { + if o.EndDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthCheck) SetEndDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndDateTime = &formatted +} + +func (o *HealthCheck) GetStartDateTimeAsTime() (*time.Time, error) { + if o.StartDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthCheck) SetStartDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartDateTime = &formatted +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnections/model_healthcheckstatusdetails.go b/resource-manager/devcenter/2024-02-01/networkconnections/model_healthcheckstatusdetails.go new file mode 100644 index 00000000000..dc8309f777e --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/model_healthcheckstatusdetails.go @@ -0,0 +1,16 @@ +package networkconnections + +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 HealthCheckStatusDetails struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *HealthCheckStatusDetailsProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnections/model_healthcheckstatusdetailsproperties.go b/resource-manager/devcenter/2024-02-01/networkconnections/model_healthcheckstatusdetailsproperties.go new file mode 100644 index 00000000000..b6c545424b4 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/model_healthcheckstatusdetailsproperties.go @@ -0,0 +1,40 @@ +package networkconnections + +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 HealthCheckStatusDetailsProperties struct { + EndDateTime *string `json:"endDateTime,omitempty"` + HealthChecks *[]HealthCheck `json:"healthChecks,omitempty"` + StartDateTime *string `json:"startDateTime,omitempty"` +} + +func (o *HealthCheckStatusDetailsProperties) GetEndDateTimeAsTime() (*time.Time, error) { + if o.EndDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.EndDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthCheckStatusDetailsProperties) SetEndDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.EndDateTime = &formatted +} + +func (o *HealthCheckStatusDetailsProperties) GetStartDateTimeAsTime() (*time.Time, error) { + if o.StartDateTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.StartDateTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *HealthCheckStatusDetailsProperties) SetStartDateTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.StartDateTime = &formatted +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnections/model_networkconnection.go b/resource-manager/devcenter/2024-02-01/networkconnections/model_networkconnection.go new file mode 100644 index 00000000000..de015e14517 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/model_networkconnection.go @@ -0,0 +1,18 @@ +package networkconnections + +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 NetworkConnection struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *NetworkProperties `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/devcenter/2024-02-01/networkconnections/model_networkconnectionupdate.go b/resource-manager/devcenter/2024-02-01/networkconnections/model_networkconnectionupdate.go new file mode 100644 index 00000000000..b9c872e521a --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/model_networkconnectionupdate.go @@ -0,0 +1,10 @@ +package networkconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkConnectionUpdate struct { + Location *string `json:"location,omitempty"` + Properties *NetworkConnectionUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnections/model_networkconnectionupdateproperties.go b/resource-manager/devcenter/2024-02-01/networkconnections/model_networkconnectionupdateproperties.go new file mode 100644 index 00000000000..7e050fd3079 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/model_networkconnectionupdateproperties.go @@ -0,0 +1,12 @@ +package networkconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkConnectionUpdateProperties struct { + DomainName *string `json:"domainName,omitempty"` + DomainPassword *string `json:"domainPassword,omitempty"` + DomainUsername *string `json:"domainUsername,omitempty"` + OrganizationUnit *string `json:"organizationUnit,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnections/model_networkproperties.go b/resource-manager/devcenter/2024-02-01/networkconnections/model_networkproperties.go new file mode 100644 index 00000000000..af1a999bbfa --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/model_networkproperties.go @@ -0,0 +1,16 @@ +package networkconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkProperties struct { + DomainJoinType DomainJoinType `json:"domainJoinType"` + DomainName *string `json:"domainName,omitempty"` + DomainPassword *string `json:"domainPassword,omitempty"` + DomainUsername *string `json:"domainUsername,omitempty"` + HealthCheckStatus *HealthCheckStatus `json:"healthCheckStatus,omitempty"` + NetworkingResourceGroupName *string `json:"networkingResourceGroupName,omitempty"` + OrganizationUnit *string `json:"organizationUnit,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + SubnetId *string `json:"subnetId,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/networkconnections/predicates.go b/resource-manager/devcenter/2024-02-01/networkconnections/predicates.go new file mode 100644 index 00000000000..4e0b3bc9285 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/predicates.go @@ -0,0 +1,55 @@ +package networkconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthCheckStatusDetailsOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p HealthCheckStatusDetailsOperationPredicate) Matches(input HealthCheckStatusDetails) 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 NetworkConnectionOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p NetworkConnectionOperationPredicate) Matches(input NetworkConnection) 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/devcenter/2024-02-01/networkconnections/version.go b/resource-manager/devcenter/2024-02-01/networkconnections/version.go new file mode 100644 index 00000000000..2986e662bcf --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/networkconnections/version.go @@ -0,0 +1,12 @@ +package networkconnections + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/networkconnections/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/pools/README.md b/resource-manager/devcenter/2024-02-01/pools/README.md new file mode 100644 index 00000000000..e5ed29b3d05 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/pools` Documentation + +The `pools` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/pools" +``` + + +### Client Initialization + +```go +client := pools.NewPoolsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PoolsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := pools.NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue") + +payload := pools.Pool{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PoolsClient.Delete` + +```go +ctx := context.TODO() +id := pools.NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PoolsClient.Get` + +```go +ctx := context.TODO() +id := pools.NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue") + +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: `PoolsClient.ListByProject` + +```go +ctx := context.TODO() +id := pools.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + +// alternatively `client.ListByProject(ctx, id)` can be used to do batched pagination +items, err := client.ListByProjectComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PoolsClient.RunHealthChecks` + +```go +ctx := context.TODO() +id := pools.NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue") + +if err := client.RunHealthChecksThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PoolsClient.Update` + +```go +ctx := context.TODO() +id := pools.NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue") + +payload := pools.PoolUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/devcenter/2024-02-01/pools/client.go b/resource-manager/devcenter/2024-02-01/pools/client.go new file mode 100644 index 00000000000..ea65f5527d9 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/client.go @@ -0,0 +1,26 @@ +package pools + +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 PoolsClient struct { + Client *resourcemanager.Client +} + +func NewPoolsClientWithBaseURI(sdkApi sdkEnv.Api) (*PoolsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "pools", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PoolsClient: %+v", err) + } + + return &PoolsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/pools/constants.go b/resource-manager/devcenter/2024-02-01/pools/constants.go new file mode 100644 index 00000000000..ca02b5d74a2 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/constants.go @@ -0,0 +1,345 @@ +package pools + +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 HealthStatus string + +const ( + HealthStatusHealthy HealthStatus = "Healthy" + HealthStatusPending HealthStatus = "Pending" + HealthStatusUnhealthy HealthStatus = "Unhealthy" + HealthStatusUnknown HealthStatus = "Unknown" + HealthStatusWarning HealthStatus = "Warning" +) + +func PossibleValuesForHealthStatus() []string { + return []string{ + string(HealthStatusHealthy), + string(HealthStatusPending), + string(HealthStatusUnhealthy), + string(HealthStatusUnknown), + string(HealthStatusWarning), + } +} + +func (s *HealthStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHealthStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHealthStatus(input string) (*HealthStatus, error) { + vals := map[string]HealthStatus{ + "healthy": HealthStatusHealthy, + "pending": HealthStatusPending, + "unhealthy": HealthStatusUnhealthy, + "unknown": HealthStatusUnknown, + "warning": HealthStatusWarning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HealthStatus(input) + return &out, nil +} + +type LicenseType string + +const ( + LicenseTypeWindowsClient LicenseType = "Windows_Client" +) + +func PossibleValuesForLicenseType() []string { + return []string{ + string(LicenseTypeWindowsClient), + } +} + +func (s *LicenseType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLicenseType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLicenseType(input string) (*LicenseType, error) { + vals := map[string]LicenseType{ + "windows_client": LicenseTypeWindowsClient, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LicenseType(input) + return &out, nil +} + +type LocalAdminStatus string + +const ( + LocalAdminStatusDisabled LocalAdminStatus = "Disabled" + LocalAdminStatusEnabled LocalAdminStatus = "Enabled" +) + +func PossibleValuesForLocalAdminStatus() []string { + return []string{ + string(LocalAdminStatusDisabled), + string(LocalAdminStatusEnabled), + } +} + +func (s *LocalAdminStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLocalAdminStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLocalAdminStatus(input string) (*LocalAdminStatus, error) { + vals := map[string]LocalAdminStatus{ + "disabled": LocalAdminStatusDisabled, + "enabled": LocalAdminStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LocalAdminStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMovingResources ProvisioningState = "MovingResources" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateRolloutInProgress ProvisioningState = "RolloutInProgress" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateStorageProvisioningFailed ProvisioningState = "StorageProvisioningFailed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateTransientFailure ProvisioningState = "TransientFailure" + ProvisioningStateUpdated ProvisioningState = "Updated" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMovingResources), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateRolloutInProgress), + string(ProvisioningStateRunning), + string(ProvisioningStateStorageProvisioningFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateTransientFailure), + string(ProvisioningStateUpdated), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "movingresources": ProvisioningStateMovingResources, + "notspecified": ProvisioningStateNotSpecified, + "rolloutinprogress": ProvisioningStateRolloutInProgress, + "running": ProvisioningStateRunning, + "storageprovisioningfailed": ProvisioningStateStorageProvisioningFailed, + "succeeded": ProvisioningStateSucceeded, + "transientfailure": ProvisioningStateTransientFailure, + "updated": ProvisioningStateUpdated, + "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 SingleSignOnStatus string + +const ( + SingleSignOnStatusDisabled SingleSignOnStatus = "Disabled" + SingleSignOnStatusEnabled SingleSignOnStatus = "Enabled" +) + +func PossibleValuesForSingleSignOnStatus() []string { + return []string{ + string(SingleSignOnStatusDisabled), + string(SingleSignOnStatusEnabled), + } +} + +func (s *SingleSignOnStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSingleSignOnStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSingleSignOnStatus(input string) (*SingleSignOnStatus, error) { + vals := map[string]SingleSignOnStatus{ + "disabled": SingleSignOnStatusDisabled, + "enabled": SingleSignOnStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SingleSignOnStatus(input) + return &out, nil +} + +type StopOnDisconnectEnableStatus string + +const ( + StopOnDisconnectEnableStatusDisabled StopOnDisconnectEnableStatus = "Disabled" + StopOnDisconnectEnableStatusEnabled StopOnDisconnectEnableStatus = "Enabled" +) + +func PossibleValuesForStopOnDisconnectEnableStatus() []string { + return []string{ + string(StopOnDisconnectEnableStatusDisabled), + string(StopOnDisconnectEnableStatusEnabled), + } +} + +func (s *StopOnDisconnectEnableStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStopOnDisconnectEnableStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStopOnDisconnectEnableStatus(input string) (*StopOnDisconnectEnableStatus, error) { + vals := map[string]StopOnDisconnectEnableStatus{ + "disabled": StopOnDisconnectEnableStatusDisabled, + "enabled": StopOnDisconnectEnableStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := StopOnDisconnectEnableStatus(input) + return &out, nil +} + +type VirtualNetworkType string + +const ( + VirtualNetworkTypeManaged VirtualNetworkType = "Managed" + VirtualNetworkTypeUnmanaged VirtualNetworkType = "Unmanaged" +) + +func PossibleValuesForVirtualNetworkType() []string { + return []string{ + string(VirtualNetworkTypeManaged), + string(VirtualNetworkTypeUnmanaged), + } +} + +func (s *VirtualNetworkType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseVirtualNetworkType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseVirtualNetworkType(input string) (*VirtualNetworkType, error) { + vals := map[string]VirtualNetworkType{ + "managed": VirtualNetworkTypeManaged, + "unmanaged": VirtualNetworkTypeUnmanaged, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := VirtualNetworkType(input) + return &out, nil +} diff --git a/resource-manager/devcenter/2024-02-01/pools/id_pool.go b/resource-manager/devcenter/2024-02-01/pools/id_pool.go new file mode 100644 index 00000000000..d707d964d75 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/id_pool.go @@ -0,0 +1,134 @@ +package pools + +import ( + "fmt" + "strings" + + "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 = &PoolId{} + +// PoolId is a struct representing the Resource ID for a Pool +type PoolId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string + PoolName string +} + +// NewPoolID returns a new PoolId struct +func NewPoolID(subscriptionId string, resourceGroupName string, projectName string, poolName string) PoolId { + return PoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + PoolName: poolName, + } +} + +// ParsePoolID parses 'input' into a PoolId +func ParsePoolID(input string) (*PoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&PoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePoolIDInsensitively parses 'input' case-insensitively into a PoolId +// note: this method should only be used for API response data and not user input +func ParsePoolIDInsensitively(input string) (*PoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&PoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PoolId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + if id.PoolName, ok = input.Parsed["poolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "poolName", input) + } + + return nil +} + +// ValidatePoolID checks that 'input' can be parsed as a Pool ID +func ValidatePoolID(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 := ParsePoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Pool ID +func (id PoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s/pools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName, id.PoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Pool ID +func (id PoolId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + resourceids.StaticSegment("staticPools", "pools", "pools"), + resourceids.UserSpecifiedSegment("poolName", "poolValue"), + } +} + +// String returns a human-readable description of this Pool ID +func (id PoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + fmt.Sprintf("Pool Name: %q", id.PoolName), + } + return fmt.Sprintf("Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/pools/id_pool_test.go b/resource-manager/devcenter/2024-02-01/pools/id_pool_test.go new file mode 100644 index 00000000000..a8aebbd17e9 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/id_pool_test.go @@ -0,0 +1,327 @@ +package pools + +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 = &PoolId{} + +func TestNewPoolID(t *testing.T) { + id := NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } + + if id.PoolName != "poolValue" { + t.Fatalf("Expected %q but got %q for Segment 'PoolName'", id.PoolName, "poolValue") + } +} + +func TestFormatPoolID(t *testing.T) { + actual := NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PoolId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue", + Expected: &PoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + PoolName: "poolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePoolID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.PoolName != v.Expected.PoolName { + t.Fatalf("Expected %q but got %q for PoolName", v.Expected.PoolName, actual.PoolName) + } + + } +} + +func TestParsePoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PoolId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/pOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue", + Expected: &PoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + PoolName: "poolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/pOoLs/pOoLvAlUe", + Expected: &PoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + PoolName: "pOoLvAlUe", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/pOoLs/pOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePoolIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.PoolName != v.Expected.PoolName { + t.Fatalf("Expected %q but got %q for PoolName", v.Expected.PoolName, actual.PoolName) + } + + } +} + +func TestSegmentsForPoolId(t *testing.T) { + segments := PoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PoolId 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/devcenter/2024-02-01/pools/id_project.go b/resource-manager/devcenter/2024-02-01/pools/id_project.go new file mode 100644 index 00000000000..7860a2a06cc --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/id_project.go @@ -0,0 +1,125 @@ +package pools + +import ( + "fmt" + "strings" + + "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 = &ProjectId{} + +// ProjectId is a struct representing the Resource ID for a Project +type ProjectId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string +} + +// NewProjectID returns a new ProjectId struct +func NewProjectID(subscriptionId string, resourceGroupName string, projectName string) ProjectId { + return ProjectId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + } +} + +// ParseProjectID parses 'input' into a ProjectId +func ParseProjectID(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProjectIDInsensitively parses 'input' case-insensitively into a ProjectId +// note: this method should only be used for API response data and not user input +func ParseProjectIDInsensitively(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProjectId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + return nil +} + +// ValidateProjectID checks that 'input' can be parsed as a Project ID +func ValidateProjectID(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 := ParseProjectID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Project ID +func (id ProjectId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Project ID +func (id ProjectId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + } +} + +// String returns a human-readable description of this Project ID +func (id ProjectId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + } + return fmt.Sprintf("Project (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/pools/id_project_test.go b/resource-manager/devcenter/2024-02-01/pools/id_project_test.go new file mode 100644 index 00000000000..91f6c84122c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/id_project_test.go @@ -0,0 +1,282 @@ +package pools + +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 = &ProjectId{} + +func TestNewProjectID(t *testing.T) { + id := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } +} + +func TestFormatProjectID(t *testing.T) { + actual := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProjectID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestParseProjectIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestSegmentsForProjectId(t *testing.T) { + segments := ProjectId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProjectId 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/devcenter/2024-02-01/pools/method_createorupdate.go b/resource-manager/devcenter/2024-02-01/pools/method_createorupdate.go new file mode 100644 index 00000000000..6017e9f5eab --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/method_createorupdate.go @@ -0,0 +1,75 @@ +package pools + +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 *Pool +} + +// CreateOrUpdate ... +func (c PoolsClient) CreateOrUpdate(ctx context.Context, id PoolId, input Pool) (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 PoolsClient) CreateOrUpdateThenPoll(ctx context.Context, id PoolId, input Pool) 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/devcenter/2024-02-01/pools/method_delete.go b/resource-manager/devcenter/2024-02-01/pools/method_delete.go new file mode 100644 index 00000000000..deed72618de --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/method_delete.go @@ -0,0 +1,70 @@ +package pools + +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 PoolsClient) Delete(ctx context.Context, id PoolId) (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 PoolsClient) DeleteThenPoll(ctx context.Context, id PoolId) 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/devcenter/2024-02-01/pools/method_get.go b/resource-manager/devcenter/2024-02-01/pools/method_get.go new file mode 100644 index 00000000000..f74c4fdbca9 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/method_get.go @@ -0,0 +1,54 @@ +package pools + +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 *Pool +} + +// Get ... +func (c PoolsClient) Get(ctx context.Context, id PoolId) (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 Pool + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/pools/method_listbyproject.go b/resource-manager/devcenter/2024-02-01/pools/method_listbyproject.go new file mode 100644 index 00000000000..d5b7784a758 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/method_listbyproject.go @@ -0,0 +1,91 @@ +package pools + +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 ListByProjectOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Pool +} + +type ListByProjectCompleteResult struct { + LatestHttpResponse *http.Response + Items []Pool +} + +// ListByProject ... +func (c PoolsClient) ListByProject(ctx context.Context, id ProjectId) (result ListByProjectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/pools", 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 *[]Pool `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProjectComplete retrieves all the results into a single object +func (c PoolsClient) ListByProjectComplete(ctx context.Context, id ProjectId) (ListByProjectCompleteResult, error) { + return c.ListByProjectCompleteMatchingPredicate(ctx, id, PoolOperationPredicate{}) +} + +// ListByProjectCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PoolsClient) ListByProjectCompleteMatchingPredicate(ctx context.Context, id ProjectId, predicate PoolOperationPredicate) (result ListByProjectCompleteResult, err error) { + items := make([]Pool, 0) + + resp, err := c.ListByProject(ctx, id) + if err != nil { + 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 = ListByProjectCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/pools/method_runhealthchecks.go b/resource-manager/devcenter/2024-02-01/pools/method_runhealthchecks.go new file mode 100644 index 00000000000..ca9316d605b --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/method_runhealthchecks.go @@ -0,0 +1,69 @@ +package pools + +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 RunHealthChecksOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// RunHealthChecks ... +func (c PoolsClient) RunHealthChecks(ctx context.Context, id PoolId) (result RunHealthChecksOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/runHealthChecks", 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 +} + +// RunHealthChecksThenPoll performs RunHealthChecks then polls until it's completed +func (c PoolsClient) RunHealthChecksThenPoll(ctx context.Context, id PoolId) error { + result, err := c.RunHealthChecks(ctx, id) + if err != nil { + return fmt.Errorf("performing RunHealthChecks: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RunHealthChecks: %+v", err) + } + + return nil +} diff --git a/resource-manager/devcenter/2024-02-01/pools/method_update.go b/resource-manager/devcenter/2024-02-01/pools/method_update.go new file mode 100644 index 00000000000..3bec7d745bc --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/method_update.go @@ -0,0 +1,75 @@ +package pools + +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 *Pool +} + +// Update ... +func (c PoolsClient) Update(ctx context.Context, id PoolId, input PoolUpdate) (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 PoolsClient) UpdateThenPoll(ctx context.Context, id PoolId, input PoolUpdate) 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/devcenter/2024-02-01/pools/model_healthstatusdetail.go b/resource-manager/devcenter/2024-02-01/pools/model_healthstatusdetail.go new file mode 100644 index 00000000000..6e725a5e71d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/model_healthstatusdetail.go @@ -0,0 +1,9 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HealthStatusDetail struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/pools/model_pool.go b/resource-manager/devcenter/2024-02-01/pools/model_pool.go new file mode 100644 index 00000000000..1359bdb0304 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/model_pool.go @@ -0,0 +1,18 @@ +package pools + +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 Pool struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *PoolProperties `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/devcenter/2024-02-01/pools/model_poolproperties.go b/resource-manager/devcenter/2024-02-01/pools/model_poolproperties.go new file mode 100644 index 00000000000..e7f9c486d00 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/model_poolproperties.go @@ -0,0 +1,20 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PoolProperties struct { + DevBoxCount *int64 `json:"devBoxCount,omitempty"` + DevBoxDefinitionName *string `json:"devBoxDefinitionName,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + HealthStatus *HealthStatus `json:"healthStatus,omitempty"` + HealthStatusDetails *[]HealthStatusDetail `json:"healthStatusDetails,omitempty"` + LicenseType *LicenseType `json:"licenseType,omitempty"` + LocalAdministrator *LocalAdminStatus `json:"localAdministrator,omitempty"` + ManagedVirtualNetworkRegions *[]string `json:"managedVirtualNetworkRegions,omitempty"` + NetworkConnectionName *string `json:"networkConnectionName,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + SingleSignOnStatus *SingleSignOnStatus `json:"singleSignOnStatus,omitempty"` + StopOnDisconnect *StopOnDisconnectConfiguration `json:"stopOnDisconnect,omitempty"` + VirtualNetworkType *VirtualNetworkType `json:"virtualNetworkType,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/pools/model_poolupdate.go b/resource-manager/devcenter/2024-02-01/pools/model_poolupdate.go new file mode 100644 index 00000000000..54ece365c4d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/model_poolupdate.go @@ -0,0 +1,10 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PoolUpdate struct { + Location *string `json:"location,omitempty"` + Properties *PoolUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/pools/model_poolupdateproperties.go b/resource-manager/devcenter/2024-02-01/pools/model_poolupdateproperties.go new file mode 100644 index 00000000000..8df7e996493 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/model_poolupdateproperties.go @@ -0,0 +1,16 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PoolUpdateProperties struct { + DevBoxDefinitionName *string `json:"devBoxDefinitionName,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + LicenseType *LicenseType `json:"licenseType,omitempty"` + LocalAdministrator *LocalAdminStatus `json:"localAdministrator,omitempty"` + ManagedVirtualNetworkRegions *[]string `json:"managedVirtualNetworkRegions,omitempty"` + NetworkConnectionName *string `json:"networkConnectionName,omitempty"` + SingleSignOnStatus *SingleSignOnStatus `json:"singleSignOnStatus,omitempty"` + StopOnDisconnect *StopOnDisconnectConfiguration `json:"stopOnDisconnect,omitempty"` + VirtualNetworkType *VirtualNetworkType `json:"virtualNetworkType,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/pools/model_stopondisconnectconfiguration.go b/resource-manager/devcenter/2024-02-01/pools/model_stopondisconnectconfiguration.go new file mode 100644 index 00000000000..522f5ea3eb4 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/model_stopondisconnectconfiguration.go @@ -0,0 +1,9 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type StopOnDisconnectConfiguration struct { + GracePeriodMinutes *int64 `json:"gracePeriodMinutes,omitempty"` + Status *StopOnDisconnectEnableStatus `json:"status,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/pools/predicates.go b/resource-manager/devcenter/2024-02-01/pools/predicates.go new file mode 100644 index 00000000000..3db83e0643e --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/predicates.go @@ -0,0 +1,32 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PoolOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p PoolOperationPredicate) Matches(input Pool) 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/devcenter/2024-02-01/pools/version.go b/resource-manager/devcenter/2024-02-01/pools/version.go new file mode 100644 index 00000000000..5f740c0a043 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/pools/version.go @@ -0,0 +1,12 @@ +package pools + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/pools/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/README.md b/resource-manager/devcenter/2024-02-01/projectcatalogs/README.md new file mode 100644 index 00000000000..ff6f1458576 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/README.md @@ -0,0 +1,139 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/projectcatalogs` Documentation + +The `projectcatalogs` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/projectcatalogs" +``` + + +### Client Initialization + +```go +client := projectcatalogs.NewProjectCatalogsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProjectCatalogsClient.Connect` + +```go +ctx := context.TODO() +id := projectcatalogs.NewCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue") + +if err := client.ConnectThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProjectCatalogsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := projectcatalogs.NewCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue") + +payload := projectcatalogs.Catalog{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProjectCatalogsClient.Delete` + +```go +ctx := context.TODO() +id := projectcatalogs.NewCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProjectCatalogsClient.Get` + +```go +ctx := context.TODO() +id := projectcatalogs.NewCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue") + +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: `ProjectCatalogsClient.GetSyncErrorDetails` + +```go +ctx := context.TODO() +id := projectcatalogs.NewCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue") + +read, err := client.GetSyncErrorDetails(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProjectCatalogsClient.List` + +```go +ctx := context.TODO() +id := projectcatalogs.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + +// alternatively `client.List(ctx, id, projectcatalogs.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, projectcatalogs.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProjectCatalogsClient.Patch` + +```go +ctx := context.TODO() +id := projectcatalogs.NewCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue") + +payload := projectcatalogs.CatalogUpdate{ + // ... +} + + +if err := client.PatchThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProjectCatalogsClient.Sync` + +```go +ctx := context.TODO() +id := projectcatalogs.NewCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue") + +if err := client.SyncThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/client.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/client.go new file mode 100644 index 00000000000..565db81ad49 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/client.go @@ -0,0 +1,26 @@ +package projectcatalogs + +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 ProjectCatalogsClient struct { + Client *resourcemanager.Client +} + +func NewProjectCatalogsClientWithBaseURI(sdkApi sdkEnv.Api) (*ProjectCatalogsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "projectcatalogs", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProjectCatalogsClient: %+v", err) + } + + return &ProjectCatalogsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/constants.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/constants.go new file mode 100644 index 00000000000..3b5acb52000 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/constants.go @@ -0,0 +1,260 @@ +package projectcatalogs + +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 CatalogConnectionState string + +const ( + CatalogConnectionStateConnected CatalogConnectionState = "Connected" + CatalogConnectionStateDisconnected CatalogConnectionState = "Disconnected" +) + +func PossibleValuesForCatalogConnectionState() []string { + return []string{ + string(CatalogConnectionStateConnected), + string(CatalogConnectionStateDisconnected), + } +} + +func (s *CatalogConnectionState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogConnectionState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogConnectionState(input string) (*CatalogConnectionState, error) { + vals := map[string]CatalogConnectionState{ + "connected": CatalogConnectionStateConnected, + "disconnected": CatalogConnectionStateDisconnected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogConnectionState(input) + return &out, nil +} + +type CatalogItemType string + +const ( + CatalogItemTypeEnvironmentDefinition CatalogItemType = "EnvironmentDefinition" +) + +func PossibleValuesForCatalogItemType() []string { + return []string{ + string(CatalogItemTypeEnvironmentDefinition), + } +} + +func (s *CatalogItemType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogItemType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogItemType(input string) (*CatalogItemType, error) { + vals := map[string]CatalogItemType{ + "environmentdefinition": CatalogItemTypeEnvironmentDefinition, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogItemType(input) + return &out, nil +} + +type CatalogSyncState string + +const ( + CatalogSyncStateCanceled CatalogSyncState = "Canceled" + CatalogSyncStateFailed CatalogSyncState = "Failed" + CatalogSyncStateInProgress CatalogSyncState = "InProgress" + CatalogSyncStateSucceeded CatalogSyncState = "Succeeded" +) + +func PossibleValuesForCatalogSyncState() []string { + return []string{ + string(CatalogSyncStateCanceled), + string(CatalogSyncStateFailed), + string(CatalogSyncStateInProgress), + string(CatalogSyncStateSucceeded), + } +} + +func (s *CatalogSyncState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogSyncState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogSyncState(input string) (*CatalogSyncState, error) { + vals := map[string]CatalogSyncState{ + "canceled": CatalogSyncStateCanceled, + "failed": CatalogSyncStateFailed, + "inprogress": CatalogSyncStateInProgress, + "succeeded": CatalogSyncStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogSyncState(input) + return &out, nil +} + +type CatalogSyncType string + +const ( + CatalogSyncTypeManual CatalogSyncType = "Manual" + CatalogSyncTypeScheduled CatalogSyncType = "Scheduled" +) + +func PossibleValuesForCatalogSyncType() []string { + return []string{ + string(CatalogSyncTypeManual), + string(CatalogSyncTypeScheduled), + } +} + +func (s *CatalogSyncType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogSyncType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogSyncType(input string) (*CatalogSyncType, error) { + vals := map[string]CatalogSyncType{ + "manual": CatalogSyncTypeManual, + "scheduled": CatalogSyncTypeScheduled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogSyncType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMovingResources ProvisioningState = "MovingResources" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateRolloutInProgress ProvisioningState = "RolloutInProgress" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateStorageProvisioningFailed ProvisioningState = "StorageProvisioningFailed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateTransientFailure ProvisioningState = "TransientFailure" + ProvisioningStateUpdated ProvisioningState = "Updated" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMovingResources), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateRolloutInProgress), + string(ProvisioningStateRunning), + string(ProvisioningStateStorageProvisioningFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateTransientFailure), + string(ProvisioningStateUpdated), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "movingresources": ProvisioningStateMovingResources, + "notspecified": ProvisioningStateNotSpecified, + "rolloutinprogress": ProvisioningStateRolloutInProgress, + "running": ProvisioningStateRunning, + "storageprovisioningfailed": ProvisioningStateStorageProvisioningFailed, + "succeeded": ProvisioningStateSucceeded, + "transientfailure": ProvisioningStateTransientFailure, + "updated": ProvisioningStateUpdated, + "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/devcenter/2024-02-01/projectcatalogs/id_catalog.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/id_catalog.go new file mode 100644 index 00000000000..7068c0b0eb5 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/id_catalog.go @@ -0,0 +1,134 @@ +package projectcatalogs + +import ( + "fmt" + "strings" + + "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 = &CatalogId{} + +// CatalogId is a struct representing the Resource ID for a Catalog +type CatalogId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string + CatalogName string +} + +// NewCatalogID returns a new CatalogId struct +func NewCatalogID(subscriptionId string, resourceGroupName string, projectName string, catalogName string) CatalogId { + return CatalogId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + CatalogName: catalogName, + } +} + +// ParseCatalogID parses 'input' into a CatalogId +func ParseCatalogID(input string) (*CatalogId, error) { + parser := resourceids.NewParserFromResourceIdType(&CatalogId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CatalogId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCatalogIDInsensitively parses 'input' case-insensitively into a CatalogId +// note: this method should only be used for API response data and not user input +func ParseCatalogIDInsensitively(input string) (*CatalogId, error) { + parser := resourceids.NewParserFromResourceIdType(&CatalogId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CatalogId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CatalogId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + if id.CatalogName, ok = input.Parsed["catalogName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "catalogName", input) + } + + return nil +} + +// ValidateCatalogID checks that 'input' can be parsed as a Catalog ID +func ValidateCatalogID(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 := ParseCatalogID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Catalog ID +func (id CatalogId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s/catalogs/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName, id.CatalogName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Catalog ID +func (id CatalogId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + resourceids.StaticSegment("staticCatalogs", "catalogs", "catalogs"), + resourceids.UserSpecifiedSegment("catalogName", "catalogValue"), + } +} + +// String returns a human-readable description of this Catalog ID +func (id CatalogId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + fmt.Sprintf("Catalog Name: %q", id.CatalogName), + } + return fmt.Sprintf("Catalog (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/id_catalog_test.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/id_catalog_test.go new file mode 100644 index 00000000000..90ab2eb7d84 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/id_catalog_test.go @@ -0,0 +1,327 @@ +package projectcatalogs + +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 = &CatalogId{} + +func TestNewCatalogID(t *testing.T) { + id := NewCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } + + if id.CatalogName != "catalogValue" { + t.Fatalf("Expected %q but got %q for Segment 'CatalogName'", id.CatalogName, "catalogValue") + } +} + +func TestFormatCatalogID(t *testing.T) { + actual := NewCatalogID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "catalogValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCatalogID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CatalogId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue", + Expected: &CatalogId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + CatalogName: "catalogValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCatalogID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.CatalogName != v.Expected.CatalogName { + t.Fatalf("Expected %q but got %q for CatalogName", v.Expected.CatalogName, actual.CatalogName) + } + + } +} + +func TestParseCatalogIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CatalogId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/cAtAlOgS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue", + Expected: &CatalogId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + CatalogName: "catalogValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/catalogs/catalogValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/cAtAlOgS/cAtAlOgVaLuE", + Expected: &CatalogId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + CatalogName: "cAtAlOgVaLuE", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/cAtAlOgS/cAtAlOgVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCatalogIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.CatalogName != v.Expected.CatalogName { + t.Fatalf("Expected %q but got %q for CatalogName", v.Expected.CatalogName, actual.CatalogName) + } + + } +} + +func TestSegmentsForCatalogId(t *testing.T) { + segments := CatalogId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CatalogId 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/devcenter/2024-02-01/projectcatalogs/id_project.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/id_project.go new file mode 100644 index 00000000000..0d894b78371 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/id_project.go @@ -0,0 +1,125 @@ +package projectcatalogs + +import ( + "fmt" + "strings" + + "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 = &ProjectId{} + +// ProjectId is a struct representing the Resource ID for a Project +type ProjectId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string +} + +// NewProjectID returns a new ProjectId struct +func NewProjectID(subscriptionId string, resourceGroupName string, projectName string) ProjectId { + return ProjectId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + } +} + +// ParseProjectID parses 'input' into a ProjectId +func ParseProjectID(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProjectIDInsensitively parses 'input' case-insensitively into a ProjectId +// note: this method should only be used for API response data and not user input +func ParseProjectIDInsensitively(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProjectId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + return nil +} + +// ValidateProjectID checks that 'input' can be parsed as a Project ID +func ValidateProjectID(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 := ParseProjectID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Project ID +func (id ProjectId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Project ID +func (id ProjectId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + } +} + +// String returns a human-readable description of this Project ID +func (id ProjectId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + } + return fmt.Sprintf("Project (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/id_project_test.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/id_project_test.go new file mode 100644 index 00000000000..d2f2b812c75 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/id_project_test.go @@ -0,0 +1,282 @@ +package projectcatalogs + +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 = &ProjectId{} + +func TestNewProjectID(t *testing.T) { + id := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } +} + +func TestFormatProjectID(t *testing.T) { + actual := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProjectID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestParseProjectIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestSegmentsForProjectId(t *testing.T) { + segments := ProjectId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProjectId 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/devcenter/2024-02-01/projectcatalogs/method_connect.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_connect.go new file mode 100644 index 00000000000..c61243c6fc0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_connect.go @@ -0,0 +1,69 @@ +package projectcatalogs + +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 ConnectOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Connect ... +func (c ProjectCatalogsClient) Connect(ctx context.Context, id CatalogId) (result ConnectOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/connect", 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 +} + +// ConnectThenPoll performs Connect then polls until it's completed +func (c ProjectCatalogsClient) ConnectThenPoll(ctx context.Context, id CatalogId) error { + result, err := c.Connect(ctx, id) + if err != nil { + return fmt.Errorf("performing Connect: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Connect: %+v", err) + } + + return nil +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/method_createorupdate.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_createorupdate.go new file mode 100644 index 00000000000..5d66222a725 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_createorupdate.go @@ -0,0 +1,75 @@ +package projectcatalogs + +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 *Catalog +} + +// CreateOrUpdate ... +func (c ProjectCatalogsClient) CreateOrUpdate(ctx context.Context, id CatalogId, input Catalog) (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 ProjectCatalogsClient) CreateOrUpdateThenPoll(ctx context.Context, id CatalogId, input Catalog) 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/devcenter/2024-02-01/projectcatalogs/method_delete.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_delete.go new file mode 100644 index 00000000000..31f24fed41d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_delete.go @@ -0,0 +1,70 @@ +package projectcatalogs + +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 ProjectCatalogsClient) Delete(ctx context.Context, id CatalogId) (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 ProjectCatalogsClient) DeleteThenPoll(ctx context.Context, id CatalogId) 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/devcenter/2024-02-01/projectcatalogs/method_get.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_get.go new file mode 100644 index 00000000000..58e3bef78b1 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_get.go @@ -0,0 +1,54 @@ +package projectcatalogs + +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 *Catalog +} + +// Get ... +func (c ProjectCatalogsClient) Get(ctx context.Context, id CatalogId) (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 Catalog + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/method_getsyncerrordetails.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_getsyncerrordetails.go new file mode 100644 index 00000000000..1202fdf37c4 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_getsyncerrordetails.go @@ -0,0 +1,55 @@ +package projectcatalogs + +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 GetSyncErrorDetailsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SyncErrorDetails +} + +// GetSyncErrorDetails ... +func (c ProjectCatalogsClient) GetSyncErrorDetails(ctx context.Context, id CatalogId) (result GetSyncErrorDetailsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getSyncErrorDetails", 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 SyncErrorDetails + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/method_list.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_list.go new file mode 100644 index 00000000000..536eeb6a829 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_list.go @@ -0,0 +1,119 @@ +package projectcatalogs + +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 *[]Catalog +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Catalog +} + +type ListOperationOptions struct { + Top *int64 +} + +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.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// List ... +func (c ProjectCatalogsClient) List(ctx context.Context, id ProjectId, options ListOperationOptions) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/catalogs", id.ID()), + OptionsObject: options, + } + + 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 *[]Catalog `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 ProjectCatalogsClient) ListComplete(ctx context.Context, id ProjectId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, CatalogOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProjectCatalogsClient) ListCompleteMatchingPredicate(ctx context.Context, id ProjectId, options ListOperationOptions, predicate CatalogOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Catalog, 0) + + resp, err := c.List(ctx, id, options) + if err != nil { + 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/devcenter/2024-02-01/projectcatalogs/method_patch.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_patch.go new file mode 100644 index 00000000000..bfd2041b5c0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_patch.go @@ -0,0 +1,75 @@ +package projectcatalogs + +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 PatchOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Catalog +} + +// Patch ... +func (c ProjectCatalogsClient) Patch(ctx context.Context, id CatalogId, input CatalogUpdate) (result PatchOperationResponse, 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 +} + +// PatchThenPoll performs Patch then polls until it's completed +func (c ProjectCatalogsClient) PatchThenPoll(ctx context.Context, id CatalogId, input CatalogUpdate) error { + result, err := c.Patch(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Patch: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Patch: %+v", err) + } + + return nil +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/method_sync.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_sync.go new file mode 100644 index 00000000000..64543b1b735 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/method_sync.go @@ -0,0 +1,69 @@ +package projectcatalogs + +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 SyncOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Sync ... +func (c ProjectCatalogsClient) Sync(ctx context.Context, id CatalogId) (result SyncOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/sync", 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 +} + +// SyncThenPoll performs Sync then polls until it's completed +func (c ProjectCatalogsClient) SyncThenPoll(ctx context.Context, id CatalogId) error { + result, err := c.Sync(ctx, id) + if err != nil { + return fmt.Errorf("performing Sync: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Sync: %+v", err) + } + + return nil +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalog.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalog.go new file mode 100644 index 00000000000..7a4ef118ef4 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalog.go @@ -0,0 +1,16 @@ +package projectcatalogs + +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 Catalog struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CatalogProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogconflicterror.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogconflicterror.go new file mode 100644 index 00000000000..ec3e895d09c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogconflicterror.go @@ -0,0 +1,9 @@ +package projectcatalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogConflictError struct { + Name *string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogerrordetails.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogerrordetails.go new file mode 100644 index 00000000000..89d249631b2 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogerrordetails.go @@ -0,0 +1,9 @@ +package projectcatalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogErrorDetails struct { + Code *string `json:"code,omitempty"` + Message *string `json:"message,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogproperties.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogproperties.go new file mode 100644 index 00000000000..a91b7765ed3 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogproperties.go @@ -0,0 +1,47 @@ +package projectcatalogs + +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 CatalogProperties struct { + AdoGit *GitCatalog `json:"adoGit,omitempty"` + ConnectionState *CatalogConnectionState `json:"connectionState,omitempty"` + GitHub *GitCatalog `json:"gitHub,omitempty"` + LastConnectionTime *string `json:"lastConnectionTime,omitempty"` + LastSyncStats *SyncStats `json:"lastSyncStats,omitempty"` + LastSyncTime *string `json:"lastSyncTime,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + SyncState *CatalogSyncState `json:"syncState,omitempty"` + SyncType *CatalogSyncType `json:"syncType,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} + +func (o *CatalogProperties) GetLastConnectionTimeAsTime() (*time.Time, error) { + if o.LastConnectionTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastConnectionTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *CatalogProperties) SetLastConnectionTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastConnectionTime = &formatted +} + +func (o *CatalogProperties) GetLastSyncTimeAsTime() (*time.Time, error) { + if o.LastSyncTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastSyncTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *CatalogProperties) SetLastSyncTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastSyncTime = &formatted +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogsyncerror.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogsyncerror.go new file mode 100644 index 00000000000..c6bc7a56f72 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogsyncerror.go @@ -0,0 +1,9 @@ +package projectcatalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogSyncError struct { + ErrorDetails *[]CatalogErrorDetails `json:"errorDetails,omitempty"` + Path *string `json:"path,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogupdate.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogupdate.go new file mode 100644 index 00000000000..757541e207d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogupdate.go @@ -0,0 +1,8 @@ +package projectcatalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogUpdate struct { + Properties *CatalogUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogupdateproperties.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogupdateproperties.go new file mode 100644 index 00000000000..eefc0d6b31f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_catalogupdateproperties.go @@ -0,0 +1,11 @@ +package projectcatalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogUpdateProperties struct { + AdoGit *GitCatalog `json:"adoGit,omitempty"` + GitHub *GitCatalog `json:"gitHub,omitempty"` + SyncType *CatalogSyncType `json:"syncType,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/model_gitcatalog.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_gitcatalog.go new file mode 100644 index 00000000000..5aca1f37099 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_gitcatalog.go @@ -0,0 +1,11 @@ +package projectcatalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GitCatalog struct { + Branch *string `json:"branch,omitempty"` + Path *string `json:"path,omitempty"` + SecretIdentifier *string `json:"secretIdentifier,omitempty"` + Uri *string `json:"uri,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/model_syncerrordetails.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_syncerrordetails.go new file mode 100644 index 00000000000..68151f893b3 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_syncerrordetails.go @@ -0,0 +1,10 @@ +package projectcatalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncErrorDetails struct { + Conflicts *[]CatalogConflictError `json:"conflicts,omitempty"` + Errors *[]CatalogSyncError `json:"errors,omitempty"` + OperationError *CatalogErrorDetails `json:"operationError,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/model_syncstats.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_syncstats.go new file mode 100644 index 00000000000..d8b4ee2141f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/model_syncstats.go @@ -0,0 +1,14 @@ +package projectcatalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyncStats struct { + Added *int64 `json:"added,omitempty"` + Removed *int64 `json:"removed,omitempty"` + SyncedCatalogItemTypes *[]CatalogItemType `json:"syncedCatalogItemTypes,omitempty"` + SynchronizationErrors *int64 `json:"synchronizationErrors,omitempty"` + Unchanged *int64 `json:"unchanged,omitempty"` + Updated *int64 `json:"updated,omitempty"` + ValidationErrors *int64 `json:"validationErrors,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/projectcatalogs/predicates.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/predicates.go new file mode 100644 index 00000000000..8340f3b496d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/predicates.go @@ -0,0 +1,27 @@ +package projectcatalogs + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CatalogOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p CatalogOperationPredicate) Matches(input Catalog) 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/devcenter/2024-02-01/projectcatalogs/version.go b/resource-manager/devcenter/2024-02-01/projectcatalogs/version.go new file mode 100644 index 00000000000..303148140aa --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projectcatalogs/version.go @@ -0,0 +1,12 @@ +package projectcatalogs + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/projectcatalogs/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/projects/README.md b/resource-manager/devcenter/2024-02-01/projects/README.md new file mode 100644 index 00000000000..903273a5da3 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/projects` Documentation + +The `projects` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/projects" +``` + + +### Client Initialization + +```go +client := projects.NewProjectsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProjectsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := projects.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + +payload := projects.Project{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProjectsClient.Delete` + +```go +ctx := context.TODO() +id := projects.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProjectsClient.Get` + +```go +ctx := context.TODO() +id := projects.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + +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: `ProjectsClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id, projects.DefaultListByResourceGroupOperationOptions())` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id, projects.DefaultListByResourceGroupOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProjectsClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id, projects.DefaultListBySubscriptionOperationOptions())` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id, projects.DefaultListBySubscriptionOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProjectsClient.Update` + +```go +ctx := context.TODO() +id := projects.NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + +payload := projects.ProjectUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/devcenter/2024-02-01/projects/client.go b/resource-manager/devcenter/2024-02-01/projects/client.go new file mode 100644 index 00000000000..f862a93697c --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/client.go @@ -0,0 +1,26 @@ +package projects + +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 ProjectsClient struct { + Client *resourcemanager.Client +} + +func NewProjectsClientWithBaseURI(sdkApi sdkEnv.Api) (*ProjectsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "projects", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProjectsClient: %+v", err) + } + + return &ProjectsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/projects/constants.go b/resource-manager/devcenter/2024-02-01/projects/constants.go new file mode 100644 index 00000000000..663107972a0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/constants.go @@ -0,0 +1,131 @@ +package projects + +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 CatalogItemType string + +const ( + CatalogItemTypeEnvironmentDefinition CatalogItemType = "EnvironmentDefinition" +) + +func PossibleValuesForCatalogItemType() []string { + return []string{ + string(CatalogItemTypeEnvironmentDefinition), + } +} + +func (s *CatalogItemType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCatalogItemType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCatalogItemType(input string) (*CatalogItemType, error) { + vals := map[string]CatalogItemType{ + "environmentdefinition": CatalogItemTypeEnvironmentDefinition, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CatalogItemType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMovingResources ProvisioningState = "MovingResources" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateRolloutInProgress ProvisioningState = "RolloutInProgress" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateStorageProvisioningFailed ProvisioningState = "StorageProvisioningFailed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateTransientFailure ProvisioningState = "TransientFailure" + ProvisioningStateUpdated ProvisioningState = "Updated" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMovingResources), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateRolloutInProgress), + string(ProvisioningStateRunning), + string(ProvisioningStateStorageProvisioningFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateTransientFailure), + string(ProvisioningStateUpdated), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "movingresources": ProvisioningStateMovingResources, + "notspecified": ProvisioningStateNotSpecified, + "rolloutinprogress": ProvisioningStateRolloutInProgress, + "running": ProvisioningStateRunning, + "storageprovisioningfailed": ProvisioningStateStorageProvisioningFailed, + "succeeded": ProvisioningStateSucceeded, + "transientfailure": ProvisioningStateTransientFailure, + "updated": ProvisioningStateUpdated, + "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/devcenter/2024-02-01/projects/id_project.go b/resource-manager/devcenter/2024-02-01/projects/id_project.go new file mode 100644 index 00000000000..28757f07b99 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/id_project.go @@ -0,0 +1,125 @@ +package projects + +import ( + "fmt" + "strings" + + "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 = &ProjectId{} + +// ProjectId is a struct representing the Resource ID for a Project +type ProjectId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string +} + +// NewProjectID returns a new ProjectId struct +func NewProjectID(subscriptionId string, resourceGroupName string, projectName string) ProjectId { + return ProjectId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + } +} + +// ParseProjectID parses 'input' into a ProjectId +func ParseProjectID(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProjectIDInsensitively parses 'input' case-insensitively into a ProjectId +// note: this method should only be used for API response data and not user input +func ParseProjectIDInsensitively(input string) (*ProjectId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProjectId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProjectId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProjectId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + return nil +} + +// ValidateProjectID checks that 'input' can be parsed as a Project ID +func ValidateProjectID(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 := ParseProjectID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Project ID +func (id ProjectId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Project ID +func (id ProjectId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + } +} + +// String returns a human-readable description of this Project ID +func (id ProjectId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + } + return fmt.Sprintf("Project (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/projects/id_project_test.go b/resource-manager/devcenter/2024-02-01/projects/id_project_test.go new file mode 100644 index 00000000000..2410f06fb10 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/id_project_test.go @@ -0,0 +1,282 @@ +package projects + +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 = &ProjectId{} + +func TestNewProjectID(t *testing.T) { + id := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } +} + +func TestFormatProjectID(t *testing.T) { + actual := NewProjectID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProjectID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestParseProjectIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProjectId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Expected: &ProjectId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProjectIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + } +} + +func TestSegmentsForProjectId(t *testing.T) { + segments := ProjectId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProjectId 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/devcenter/2024-02-01/projects/method_createorupdate.go b/resource-manager/devcenter/2024-02-01/projects/method_createorupdate.go new file mode 100644 index 00000000000..20a1bb1d7c1 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/method_createorupdate.go @@ -0,0 +1,75 @@ +package projects + +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 *Project +} + +// CreateOrUpdate ... +func (c ProjectsClient) CreateOrUpdate(ctx context.Context, id ProjectId, input Project) (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 ProjectsClient) CreateOrUpdateThenPoll(ctx context.Context, id ProjectId, input Project) 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/devcenter/2024-02-01/projects/method_delete.go b/resource-manager/devcenter/2024-02-01/projects/method_delete.go new file mode 100644 index 00000000000..602b30c14d9 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/method_delete.go @@ -0,0 +1,70 @@ +package projects + +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 ProjectsClient) Delete(ctx context.Context, id ProjectId) (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 ProjectsClient) DeleteThenPoll(ctx context.Context, id ProjectId) 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/devcenter/2024-02-01/projects/method_get.go b/resource-manager/devcenter/2024-02-01/projects/method_get.go new file mode 100644 index 00000000000..b37e667ef3d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/method_get.go @@ -0,0 +1,54 @@ +package projects + +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 *Project +} + +// Get ... +func (c ProjectsClient) Get(ctx context.Context, id ProjectId) (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 Project + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/projects/method_listbyresourcegroup.go b/resource-manager/devcenter/2024-02-01/projects/method_listbyresourcegroup.go new file mode 100644 index 00000000000..eb068384c8e --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/method_listbyresourcegroup.go @@ -0,0 +1,120 @@ +package projects + +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 *[]Project +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Project +} + +type ListByResourceGroupOperationOptions struct { + Top *int64 +} + +func DefaultListByResourceGroupOperationOptions() ListByResourceGroupOperationOptions { + return ListByResourceGroupOperationOptions{} +} + +func (o ListByResourceGroupOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByResourceGroupOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListByResourceGroupOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListByResourceGroup ... +func (c ProjectsClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.DevCenter/projects", id.ID()), + OptionsObject: options, + } + + 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 *[]Project `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 ProjectsClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, options, ProjectOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProjectsClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, options ListByResourceGroupOperationOptions, predicate ProjectOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Project, 0) + + resp, err := c.ListByResourceGroup(ctx, id, options) + if err != nil { + 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/devcenter/2024-02-01/projects/method_listbysubscription.go b/resource-manager/devcenter/2024-02-01/projects/method_listbysubscription.go new file mode 100644 index 00000000000..ae325483986 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/method_listbysubscription.go @@ -0,0 +1,120 @@ +package projects + +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 *[]Project +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []Project +} + +type ListBySubscriptionOperationOptions struct { + Top *int64 +} + +func DefaultListBySubscriptionOperationOptions() ListBySubscriptionOperationOptions { + return ListBySubscriptionOperationOptions{} +} + +func (o ListBySubscriptionOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListBySubscriptionOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListBySubscriptionOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +// ListBySubscription ... +func (c ProjectsClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.DevCenter/projects", id.ID()), + OptionsObject: options, + } + + 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 *[]Project `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 ProjectsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, options, ProjectOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProjectsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options ListBySubscriptionOperationOptions, predicate ProjectOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]Project, 0) + + resp, err := c.ListBySubscription(ctx, id, options) + if err != nil { + 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/devcenter/2024-02-01/projects/method_update.go b/resource-manager/devcenter/2024-02-01/projects/method_update.go new file mode 100644 index 00000000000..0b6a48bd29e --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/method_update.go @@ -0,0 +1,75 @@ +package projects + +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 *Project +} + +// Update ... +func (c ProjectsClient) Update(ctx context.Context, id ProjectId, input ProjectUpdate) (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 ProjectsClient) UpdateThenPoll(ctx context.Context, id ProjectId, input ProjectUpdate) 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/devcenter/2024-02-01/projects/model_project.go b/resource-manager/devcenter/2024-02-01/projects/model_project.go new file mode 100644 index 00000000000..cff5e262f1b --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/model_project.go @@ -0,0 +1,20 @@ +package projects + +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 Project struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ProjectProperties `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/devcenter/2024-02-01/projects/model_projectcatalogsettings.go b/resource-manager/devcenter/2024-02-01/projects/model_projectcatalogsettings.go new file mode 100644 index 00000000000..9bcf5b39f72 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/model_projectcatalogsettings.go @@ -0,0 +1,8 @@ +package projects + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProjectCatalogSettings struct { + CatalogItemSyncTypes *[]CatalogItemType `json:"catalogItemSyncTypes,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/projects/model_projectproperties.go b/resource-manager/devcenter/2024-02-01/projects/model_projectproperties.go new file mode 100644 index 00000000000..31e04b637b5 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/model_projectproperties.go @@ -0,0 +1,14 @@ +package projects + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProjectProperties struct { + CatalogSettings *ProjectCatalogSettings `json:"catalogSettings,omitempty"` + Description *string `json:"description,omitempty"` + DevCenterId *string `json:"devCenterId,omitempty"` + DevCenterUri *string `json:"devCenterUri,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + MaxDevBoxesPerUser *int64 `json:"maxDevBoxesPerUser,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/projects/model_projectupdate.go b/resource-manager/devcenter/2024-02-01/projects/model_projectupdate.go new file mode 100644 index 00000000000..25153e77746 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/model_projectupdate.go @@ -0,0 +1,15 @@ +package projects + +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 ProjectUpdate struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Location *string `json:"location,omitempty"` + Properties *ProjectUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/projects/model_projectupdateproperties.go b/resource-manager/devcenter/2024-02-01/projects/model_projectupdateproperties.go new file mode 100644 index 00000000000..954ed83166e --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/model_projectupdateproperties.go @@ -0,0 +1,12 @@ +package projects + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProjectUpdateProperties struct { + CatalogSettings *ProjectCatalogSettings `json:"catalogSettings,omitempty"` + Description *string `json:"description,omitempty"` + DevCenterId *string `json:"devCenterId,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + MaxDevBoxesPerUser *int64 `json:"maxDevBoxesPerUser,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/projects/predicates.go b/resource-manager/devcenter/2024-02-01/projects/predicates.go new file mode 100644 index 00000000000..7e309d69f45 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/predicates.go @@ -0,0 +1,32 @@ +package projects + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProjectOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ProjectOperationPredicate) Matches(input Project) 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/devcenter/2024-02-01/projects/version.go b/resource-manager/devcenter/2024-02-01/projects/version.go new file mode 100644 index 00000000000..dd4a06a9413 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/projects/version.go @@ -0,0 +1,12 @@ +package projects + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/projects/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/schedules/README.md b/resource-manager/devcenter/2024-02-01/schedules/README.md new file mode 100644 index 00000000000..757d58c7721 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/schedules` Documentation + +The `schedules` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/schedules" +``` + + +### Client Initialization + +```go +client := schedules.NewSchedulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SchedulesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := schedules.NewScheduleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue", "scheduleValue") + +payload := schedules.Schedule{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SchedulesClient.Delete` + +```go +ctx := context.TODO() +id := schedules.NewScheduleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue", "scheduleValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SchedulesClient.Get` + +```go +ctx := context.TODO() +id := schedules.NewScheduleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue", "scheduleValue") + +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: `SchedulesClient.ListByPool` + +```go +ctx := context.TODO() +id := schedules.NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue") + +// alternatively `client.ListByPool(ctx, id)` can be used to do batched pagination +items, err := client.ListByPoolComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SchedulesClient.Update` + +```go +ctx := context.TODO() +id := schedules.NewScheduleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue", "scheduleValue") + +payload := schedules.ScheduleUpdate{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/devcenter/2024-02-01/schedules/client.go b/resource-manager/devcenter/2024-02-01/schedules/client.go new file mode 100644 index 00000000000..36a9b3c9f6f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/client.go @@ -0,0 +1,26 @@ +package schedules + +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 SchedulesClient struct { + Client *resourcemanager.Client +} + +func NewSchedulesClientWithBaseURI(sdkApi sdkEnv.Api) (*SchedulesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "schedules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SchedulesClient: %+v", err) + } + + return &SchedulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/schedules/constants.go b/resource-manager/devcenter/2024-02-01/schedules/constants.go new file mode 100644 index 00000000000..4ab1ffeec4b --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/constants.go @@ -0,0 +1,210 @@ +package schedules + +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 ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreated ProvisioningState = "Created" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMovingResources ProvisioningState = "MovingResources" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateRolloutInProgress ProvisioningState = "RolloutInProgress" + ProvisioningStateRunning ProvisioningState = "Running" + ProvisioningStateStorageProvisioningFailed ProvisioningState = "StorageProvisioningFailed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateTransientFailure ProvisioningState = "TransientFailure" + ProvisioningStateUpdated ProvisioningState = "Updated" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreated), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMovingResources), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateRolloutInProgress), + string(ProvisioningStateRunning), + string(ProvisioningStateStorageProvisioningFailed), + string(ProvisioningStateSucceeded), + string(ProvisioningStateTransientFailure), + string(ProvisioningStateUpdated), + 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{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "created": ProvisioningStateCreated, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "movingresources": ProvisioningStateMovingResources, + "notspecified": ProvisioningStateNotSpecified, + "rolloutinprogress": ProvisioningStateRolloutInProgress, + "running": ProvisioningStateRunning, + "storageprovisioningfailed": ProvisioningStateStorageProvisioningFailed, + "succeeded": ProvisioningStateSucceeded, + "transientfailure": ProvisioningStateTransientFailure, + "updated": ProvisioningStateUpdated, + "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 ScheduleEnableStatus string + +const ( + ScheduleEnableStatusDisabled ScheduleEnableStatus = "Disabled" + ScheduleEnableStatusEnabled ScheduleEnableStatus = "Enabled" +) + +func PossibleValuesForScheduleEnableStatus() []string { + return []string{ + string(ScheduleEnableStatusDisabled), + string(ScheduleEnableStatusEnabled), + } +} + +func (s *ScheduleEnableStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScheduleEnableStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScheduleEnableStatus(input string) (*ScheduleEnableStatus, error) { + vals := map[string]ScheduleEnableStatus{ + "disabled": ScheduleEnableStatusDisabled, + "enabled": ScheduleEnableStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScheduleEnableStatus(input) + return &out, nil +} + +type ScheduledFrequency string + +const ( + ScheduledFrequencyDaily ScheduledFrequency = "Daily" +) + +func PossibleValuesForScheduledFrequency() []string { + return []string{ + string(ScheduledFrequencyDaily), + } +} + +func (s *ScheduledFrequency) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScheduledFrequency(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScheduledFrequency(input string) (*ScheduledFrequency, error) { + vals := map[string]ScheduledFrequency{ + "daily": ScheduledFrequencyDaily, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScheduledFrequency(input) + return &out, nil +} + +type ScheduledType string + +const ( + ScheduledTypeStopDevBox ScheduledType = "StopDevBox" +) + +func PossibleValuesForScheduledType() []string { + return []string{ + string(ScheduledTypeStopDevBox), + } +} + +func (s *ScheduledType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScheduledType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScheduledType(input string) (*ScheduledType, error) { + vals := map[string]ScheduledType{ + "stopdevbox": ScheduledTypeStopDevBox, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScheduledType(input) + return &out, nil +} diff --git a/resource-manager/devcenter/2024-02-01/schedules/id_pool.go b/resource-manager/devcenter/2024-02-01/schedules/id_pool.go new file mode 100644 index 00000000000..0aa739708cc --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/id_pool.go @@ -0,0 +1,134 @@ +package schedules + +import ( + "fmt" + "strings" + + "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 = &PoolId{} + +// PoolId is a struct representing the Resource ID for a Pool +type PoolId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string + PoolName string +} + +// NewPoolID returns a new PoolId struct +func NewPoolID(subscriptionId string, resourceGroupName string, projectName string, poolName string) PoolId { + return PoolId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + PoolName: poolName, + } +} + +// ParsePoolID parses 'input' into a PoolId +func ParsePoolID(input string) (*PoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&PoolId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePoolIDInsensitively parses 'input' case-insensitively into a PoolId +// note: this method should only be used for API response data and not user input +func ParsePoolIDInsensitively(input string) (*PoolId, error) { + parser := resourceids.NewParserFromResourceIdType(&PoolId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PoolId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PoolId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + if id.PoolName, ok = input.Parsed["poolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "poolName", input) + } + + return nil +} + +// ValidatePoolID checks that 'input' can be parsed as a Pool ID +func ValidatePoolID(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 := ParsePoolID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Pool ID +func (id PoolId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s/pools/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName, id.PoolName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Pool ID +func (id PoolId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + resourceids.StaticSegment("staticPools", "pools", "pools"), + resourceids.UserSpecifiedSegment("poolName", "poolValue"), + } +} + +// String returns a human-readable description of this Pool ID +func (id PoolId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + fmt.Sprintf("Pool Name: %q", id.PoolName), + } + return fmt.Sprintf("Pool (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/schedules/id_pool_test.go b/resource-manager/devcenter/2024-02-01/schedules/id_pool_test.go new file mode 100644 index 00000000000..ff7570a2024 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/id_pool_test.go @@ -0,0 +1,327 @@ +package schedules + +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 = &PoolId{} + +func TestNewPoolID(t *testing.T) { + id := NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } + + if id.PoolName != "poolValue" { + t.Fatalf("Expected %q but got %q for Segment 'PoolName'", id.PoolName, "poolValue") + } +} + +func TestFormatPoolID(t *testing.T) { + actual := NewPoolID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePoolID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PoolId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue", + Expected: &PoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + PoolName: "poolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePoolID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.PoolName != v.Expected.PoolName { + t.Fatalf("Expected %q but got %q for PoolName", v.Expected.PoolName, actual.PoolName) + } + + } +} + +func TestParsePoolIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PoolId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/pOoLs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue", + Expected: &PoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + PoolName: "poolValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/pOoLs/pOoLvAlUe", + Expected: &PoolId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + PoolName: "pOoLvAlUe", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/pOoLs/pOoLvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePoolIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.PoolName != v.Expected.PoolName { + t.Fatalf("Expected %q but got %q for PoolName", v.Expected.PoolName, actual.PoolName) + } + + } +} + +func TestSegmentsForPoolId(t *testing.T) { + segments := PoolId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PoolId 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/devcenter/2024-02-01/schedules/id_schedule.go b/resource-manager/devcenter/2024-02-01/schedules/id_schedule.go new file mode 100644 index 00000000000..b91608bb90f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/id_schedule.go @@ -0,0 +1,143 @@ +package schedules + +import ( + "fmt" + "strings" + + "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 = &ScheduleId{} + +// ScheduleId is a struct representing the Resource ID for a Schedule +type ScheduleId struct { + SubscriptionId string + ResourceGroupName string + ProjectName string + PoolName string + ScheduleName string +} + +// NewScheduleID returns a new ScheduleId struct +func NewScheduleID(subscriptionId string, resourceGroupName string, projectName string, poolName string, scheduleName string) ScheduleId { + return ScheduleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProjectName: projectName, + PoolName: poolName, + ScheduleName: scheduleName, + } +} + +// ParseScheduleID parses 'input' into a ScheduleId +func ParseScheduleID(input string) (*ScheduleId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScheduleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScheduleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseScheduleIDInsensitively parses 'input' case-insensitively into a ScheduleId +// note: this method should only be used for API response data and not user input +func ParseScheduleIDInsensitively(input string) (*ScheduleId, error) { + parser := resourceids.NewParserFromResourceIdType(&ScheduleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ScheduleId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ScheduleId) 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.ProjectName, ok = input.Parsed["projectName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "projectName", input) + } + + if id.PoolName, ok = input.Parsed["poolName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "poolName", input) + } + + if id.ScheduleName, ok = input.Parsed["scheduleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "scheduleName", input) + } + + return nil +} + +// ValidateScheduleID checks that 'input' can be parsed as a Schedule ID +func ValidateScheduleID(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 := ParseScheduleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Schedule ID +func (id ScheduleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DevCenter/projects/%s/pools/%s/schedules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProjectName, id.PoolName, id.ScheduleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Schedule ID +func (id ScheduleId) 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("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticProjects", "projects", "projects"), + resourceids.UserSpecifiedSegment("projectName", "projectValue"), + resourceids.StaticSegment("staticPools", "pools", "pools"), + resourceids.UserSpecifiedSegment("poolName", "poolValue"), + resourceids.StaticSegment("staticSchedules", "schedules", "schedules"), + resourceids.UserSpecifiedSegment("scheduleName", "scheduleValue"), + } +} + +// String returns a human-readable description of this Schedule ID +func (id ScheduleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Project Name: %q", id.ProjectName), + fmt.Sprintf("Pool Name: %q", id.PoolName), + fmt.Sprintf("Schedule Name: %q", id.ScheduleName), + } + return fmt.Sprintf("Schedule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/schedules/id_schedule_test.go b/resource-manager/devcenter/2024-02-01/schedules/id_schedule_test.go new file mode 100644 index 00000000000..57ad1341904 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/id_schedule_test.go @@ -0,0 +1,372 @@ +package schedules + +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 = &ScheduleId{} + +func TestNewScheduleID(t *testing.T) { + id := NewScheduleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue", "scheduleValue") + + 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.ProjectName != "projectValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProjectName'", id.ProjectName, "projectValue") + } + + if id.PoolName != "poolValue" { + t.Fatalf("Expected %q but got %q for Segment 'PoolName'", id.PoolName, "poolValue") + } + + if id.ScheduleName != "scheduleValue" { + t.Fatalf("Expected %q but got %q for Segment 'ScheduleName'", id.ScheduleName, "scheduleValue") + } +} + +func TestFormatScheduleID(t *testing.T) { + actual := NewScheduleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "projectValue", "poolValue", "scheduleValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue/schedules/scheduleValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseScheduleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScheduleId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue/schedules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue/schedules/scheduleValue", + Expected: &ScheduleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + PoolName: "poolValue", + ScheduleName: "scheduleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue/schedules/scheduleValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScheduleID(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.PoolName != v.Expected.PoolName { + t.Fatalf("Expected %q but got %q for PoolName", v.Expected.PoolName, actual.PoolName) + } + + if actual.ScheduleName != v.Expected.ScheduleName { + t.Fatalf("Expected %q but got %q for ScheduleName", v.Expected.ScheduleName, actual.ScheduleName) + } + + } +} + +func TestParseScheduleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ScheduleId + }{ + { + // 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.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/pOoLs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/pOoLs/pOoLvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue/schedules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/pOoLs/pOoLvAlUe/sChEdUlEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue/schedules/scheduleValue", + Expected: &ScheduleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProjectName: "projectValue", + PoolName: "poolValue", + ScheduleName: "scheduleValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.DevCenter/projects/projectValue/pools/poolValue/schedules/scheduleValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/pOoLs/pOoLvAlUe/sChEdUlEs/sChEdUlEvAlUe", + Expected: &ScheduleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProjectName: "pRoJeCtVaLuE", + PoolName: "pOoLvAlUe", + ScheduleName: "sChEdUlEvAlUe", + }, + }, + { + // 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.dEvCeNtEr/pRoJeCtS/pRoJeCtVaLuE/pOoLs/pOoLvAlUe/sChEdUlEs/sChEdUlEvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseScheduleIDInsensitively(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.ProjectName != v.Expected.ProjectName { + t.Fatalf("Expected %q but got %q for ProjectName", v.Expected.ProjectName, actual.ProjectName) + } + + if actual.PoolName != v.Expected.PoolName { + t.Fatalf("Expected %q but got %q for PoolName", v.Expected.PoolName, actual.PoolName) + } + + if actual.ScheduleName != v.Expected.ScheduleName { + t.Fatalf("Expected %q but got %q for ScheduleName", v.Expected.ScheduleName, actual.ScheduleName) + } + + } +} + +func TestSegmentsForScheduleId(t *testing.T) { + segments := ScheduleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ScheduleId 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/devcenter/2024-02-01/schedules/method_createorupdate.go b/resource-manager/devcenter/2024-02-01/schedules/method_createorupdate.go new file mode 100644 index 00000000000..342b8b34fbc --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/method_createorupdate.go @@ -0,0 +1,75 @@ +package schedules + +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 *Schedule +} + +// CreateOrUpdate ... +func (c SchedulesClient) CreateOrUpdate(ctx context.Context, id ScheduleId, input Schedule) (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 SchedulesClient) CreateOrUpdateThenPoll(ctx context.Context, id ScheduleId, input Schedule) 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/devcenter/2024-02-01/schedules/method_delete.go b/resource-manager/devcenter/2024-02-01/schedules/method_delete.go new file mode 100644 index 00000000000..b589d790778 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/method_delete.go @@ -0,0 +1,70 @@ +package schedules + +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 SchedulesClient) Delete(ctx context.Context, id ScheduleId) (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 SchedulesClient) DeleteThenPoll(ctx context.Context, id ScheduleId) 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/devcenter/2024-02-01/schedules/method_get.go b/resource-manager/devcenter/2024-02-01/schedules/method_get.go new file mode 100644 index 00000000000..c92229c96c5 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/method_get.go @@ -0,0 +1,54 @@ +package schedules + +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 *Schedule +} + +// Get ... +func (c SchedulesClient) Get(ctx context.Context, id ScheduleId) (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 Schedule + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devcenter/2024-02-01/schedules/method_listbypool.go b/resource-manager/devcenter/2024-02-01/schedules/method_listbypool.go new file mode 100644 index 00000000000..e614c869fa7 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/method_listbypool.go @@ -0,0 +1,91 @@ +package schedules + +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 ListByPoolOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Schedule +} + +type ListByPoolCompleteResult struct { + LatestHttpResponse *http.Response + Items []Schedule +} + +// ListByPool ... +func (c SchedulesClient) ListByPool(ctx context.Context, id PoolId) (result ListByPoolOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/schedules", 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 *[]Schedule `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByPoolComplete retrieves all the results into a single object +func (c SchedulesClient) ListByPoolComplete(ctx context.Context, id PoolId) (ListByPoolCompleteResult, error) { + return c.ListByPoolCompleteMatchingPredicate(ctx, id, ScheduleOperationPredicate{}) +} + +// ListByPoolCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SchedulesClient) ListByPoolCompleteMatchingPredicate(ctx context.Context, id PoolId, predicate ScheduleOperationPredicate) (result ListByPoolCompleteResult, err error) { + items := make([]Schedule, 0) + + resp, err := c.ListByPool(ctx, id) + if err != nil { + 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 = ListByPoolCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/schedules/method_update.go b/resource-manager/devcenter/2024-02-01/schedules/method_update.go new file mode 100644 index 00000000000..8138cf2e3da --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/method_update.go @@ -0,0 +1,75 @@ +package schedules + +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 *Schedule +} + +// Update ... +func (c SchedulesClient) Update(ctx context.Context, id ScheduleId, input ScheduleUpdate) (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 SchedulesClient) UpdateThenPoll(ctx context.Context, id ScheduleId, input ScheduleUpdate) 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/devcenter/2024-02-01/schedules/model_schedule.go b/resource-manager/devcenter/2024-02-01/schedules/model_schedule.go new file mode 100644 index 00000000000..1cf8912c96f --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/model_schedule.go @@ -0,0 +1,16 @@ +package schedules + +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 Schedule struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *ScheduleProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/schedules/model_scheduleproperties.go b/resource-manager/devcenter/2024-02-01/schedules/model_scheduleproperties.go new file mode 100644 index 00000000000..ddd8316bdc5 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/model_scheduleproperties.go @@ -0,0 +1,15 @@ +package schedules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduleProperties struct { + Frequency *ScheduledFrequency `json:"frequency,omitempty"` + Location *string `json:"location,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + State *ScheduleEnableStatus `json:"state,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Time *string `json:"time,omitempty"` + TimeZone *string `json:"timeZone,omitempty"` + Type *ScheduledType `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/schedules/model_scheduleupdate.go b/resource-manager/devcenter/2024-02-01/schedules/model_scheduleupdate.go new file mode 100644 index 00000000000..ce6eb595cd3 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/model_scheduleupdate.go @@ -0,0 +1,8 @@ +package schedules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduleUpdate struct { + Properties *ScheduleUpdateProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/schedules/model_scheduleupdateproperties.go b/resource-manager/devcenter/2024-02-01/schedules/model_scheduleupdateproperties.go new file mode 100644 index 00000000000..8864b7886b4 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/model_scheduleupdateproperties.go @@ -0,0 +1,14 @@ +package schedules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduleUpdateProperties struct { + Frequency *ScheduledFrequency `json:"frequency,omitempty"` + Location *string `json:"location,omitempty"` + State *ScheduleEnableStatus `json:"state,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Time *string `json:"time,omitempty"` + TimeZone *string `json:"timeZone,omitempty"` + Type *ScheduledType `json:"type,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/schedules/predicates.go b/resource-manager/devcenter/2024-02-01/schedules/predicates.go new file mode 100644 index 00000000000..d36444031de --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/predicates.go @@ -0,0 +1,27 @@ +package schedules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ScheduleOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ScheduleOperationPredicate) Matches(input Schedule) 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/devcenter/2024-02-01/schedules/version.go b/resource-manager/devcenter/2024-02-01/schedules/version.go new file mode 100644 index 00000000000..d58932230cb --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/schedules/version.go @@ -0,0 +1,12 @@ +package schedules + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/schedules/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/skus/README.md b/resource-manager/devcenter/2024-02-01/skus/README.md new file mode 100644 index 00000000000..543b48c2b60 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/skus/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/skus` Documentation + +The `skus` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/skus" +``` + + +### Client Initialization + +```go +client := skus.NewSKUsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SKUsClient.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 +} +``` diff --git a/resource-manager/devcenter/2024-02-01/skus/client.go b/resource-manager/devcenter/2024-02-01/skus/client.go new file mode 100644 index 00000000000..d2fbc1d3af0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/skus/client.go @@ -0,0 +1,26 @@ +package skus + +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 SKUsClient struct { + Client *resourcemanager.Client +} + +func NewSKUsClientWithBaseURI(sdkApi sdkEnv.Api) (*SKUsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "skus", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SKUsClient: %+v", err) + } + + return &SKUsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/skus/constants.go b/resource-manager/devcenter/2024-02-01/skus/constants.go new file mode 100644 index 00000000000..78bcd9d93f1 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/skus/constants.go @@ -0,0 +1,57 @@ +package skus + +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 SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierFree), + 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, + "free": SkuTierFree, + "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 +} diff --git a/resource-manager/devcenter/2024-02-01/skus/method_listbysubscription.go b/resource-manager/devcenter/2024-02-01/skus/method_listbysubscription.go new file mode 100644 index 00000000000..44aff1127d0 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/skus/method_listbysubscription.go @@ -0,0 +1,92 @@ +package skus + +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 *[]DevCenterSku +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []DevCenterSku +} + +// ListBySubscription ... +func (c SKUsClient) 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, + Path: fmt.Sprintf("%s/providers/Microsoft.DevCenter/skus", 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 *[]DevCenterSku `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 SKUsClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, DevCenterSkuOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SKUsClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate DevCenterSkuOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]DevCenterSku, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + 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/devcenter/2024-02-01/skus/model_capability.go b/resource-manager/devcenter/2024-02-01/skus/model_capability.go new file mode 100644 index 00000000000..22ca5e12de4 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/skus/model_capability.go @@ -0,0 +1,9 @@ +package skus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Capability struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/skus/model_devcentersku.go b/resource-manager/devcenter/2024-02-01/skus/model_devcentersku.go new file mode 100644 index 00000000000..460baf73840 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/skus/model_devcentersku.go @@ -0,0 +1,15 @@ +package skus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DevCenterSku struct { + Capabilities *[]Capability `json:"capabilities,omitempty"` + Capacity *int64 `json:"capacity,omitempty"` + Family *string `json:"family,omitempty"` + Locations *[]string `json:"locations,omitempty"` + Name string `json:"name"` + ResourceType *string `json:"resourceType,omitempty"` + Size *string `json:"size,omitempty"` + Tier *SkuTier `json:"tier,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/skus/predicates.go b/resource-manager/devcenter/2024-02-01/skus/predicates.go new file mode 100644 index 00000000000..9495f53bfef --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/skus/predicates.go @@ -0,0 +1,37 @@ +package skus + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DevCenterSkuOperationPredicate struct { + Capacity *int64 + Family *string + Name *string + ResourceType *string + Size *string +} + +func (p DevCenterSkuOperationPredicate) Matches(input DevCenterSku) bool { + + if p.Capacity != nil && (input.Capacity == nil || *p.Capacity != *input.Capacity) { + return false + } + + if p.Family != nil && (input.Family == nil || *p.Family != *input.Family) { + return false + } + + if p.Name != nil && *p.Name != input.Name { + return false + } + + if p.ResourceType != nil && (input.ResourceType == nil || *p.ResourceType != *input.ResourceType) { + return false + } + + if p.Size != nil && (input.Size == nil || *p.Size != *input.Size) { + return false + } + + return true +} diff --git a/resource-manager/devcenter/2024-02-01/skus/version.go b/resource-manager/devcenter/2024-02-01/skus/version.go new file mode 100644 index 00000000000..c5301cf59e9 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/skus/version.go @@ -0,0 +1,12 @@ +package skus + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/skus/%s", defaultApiVersion) +} diff --git a/resource-manager/devcenter/2024-02-01/usages/README.md b/resource-manager/devcenter/2024-02-01/usages/README.md new file mode 100644 index 00000000000..b068273bd06 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/usages/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2024-02-01/usages` Documentation + +The `usages` SDK allows for interaction with the Azure Resource Manager Service `devcenter` (API Version `2024-02-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/devcenter/2024-02-01/usages" +``` + + +### Client Initialization + +```go +client := usages.NewUsagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UsagesClient.ListByLocation` + +```go +ctx := context.TODO() +id := usages.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +// alternatively `client.ListByLocation(ctx, id)` can be used to do batched pagination +items, err := client.ListByLocationComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/devcenter/2024-02-01/usages/client.go b/resource-manager/devcenter/2024-02-01/usages/client.go new file mode 100644 index 00000000000..772d6a5be35 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/usages/client.go @@ -0,0 +1,26 @@ +package usages + +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 UsagesClient struct { + Client *resourcemanager.Client +} + +func NewUsagesClientWithBaseURI(sdkApi sdkEnv.Api) (*UsagesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "usages", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating UsagesClient: %+v", err) + } + + return &UsagesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/devcenter/2024-02-01/usages/constants.go b/resource-manager/devcenter/2024-02-01/usages/constants.go new file mode 100644 index 00000000000..0d8916ba5aa --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/usages/constants.go @@ -0,0 +1,48 @@ +package usages + +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 UsageUnit string + +const ( + UsageUnitCount UsageUnit = "Count" +) + +func PossibleValuesForUsageUnit() []string { + return []string{ + string(UsageUnitCount), + } +} + +func (s *UsageUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUsageUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUsageUnit(input string) (*UsageUnit, error) { + vals := map[string]UsageUnit{ + "count": UsageUnitCount, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UsageUnit(input) + return &out, nil +} diff --git a/resource-manager/devcenter/2024-02-01/usages/id_location.go b/resource-manager/devcenter/2024-02-01/usages/id_location.go new file mode 100644 index 00000000000..5ff407e7169 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/usages/id_location.go @@ -0,0 +1,116 @@ +package usages + +import ( + "fmt" + "strings" + + "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 = &LocationId{} + +// LocationId is a struct representing the Resource ID for a Location +type LocationId struct { + SubscriptionId string + LocationName string +} + +// NewLocationID returns a new LocationId struct +func NewLocationID(subscriptionId string, locationName string) LocationId { + return LocationId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + } +} + +// ParseLocationID parses 'input' into a LocationId +func ParseLocationID(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseLocationIDInsensitively parses 'input' case-insensitively into a LocationId +// note: this method should only be used for API response data and not user input +func ParseLocationIDInsensitively(input string) (*LocationId, error) { + parser := resourceids.NewParserFromResourceIdType(&LocationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := LocationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *LocationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.LocationName, ok = input.Parsed["locationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "locationName", input) + } + + return nil +} + +// ValidateLocationID checks that 'input' can be parsed as a Location ID +func ValidateLocationID(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 := ParseLocationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Location ID +func (id LocationId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.DevCenter/locations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Location ID +func (id LocationId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDevCenter", "Microsoft.DevCenter", "Microsoft.DevCenter"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationValue"), + } +} + +// String returns a human-readable description of this Location ID +func (id LocationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + } + return fmt.Sprintf("Location (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/devcenter/2024-02-01/usages/id_location_test.go b/resource-manager/devcenter/2024-02-01/usages/id_location_test.go new file mode 100644 index 00000000000..6d432fef79d --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/usages/id_location_test.go @@ -0,0 +1,237 @@ +package usages + +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 = &LocationId{} + +func TestNewLocationID(t *testing.T) { + id := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + + 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.LocationName != "locationValue" { + t.Fatalf("Expected %q but got %q for Segment 'LocationName'", id.LocationName, "locationValue") + } +} + +func TestFormatLocationID(t *testing.T) { + actual := NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevCenter/locations/locationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseLocationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // 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/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevCenter", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevCenter/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevCenter/locations/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevCenter/locations/locationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationID(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestParseLocationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *LocationId + }{ + { + // 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/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevCenter", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dEvCeNtEr", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevCenter/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevCenter/locations/locationValue", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.DevCenter/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/lOcAtIoNs/lOcAtIoNvAlUe", + Expected: &LocationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.dEvCeNtEr/lOcAtIoNs/lOcAtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseLocationIDInsensitively(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.LocationName != v.Expected.LocationName { + t.Fatalf("Expected %q but got %q for LocationName", v.Expected.LocationName, actual.LocationName) + } + + } +} + +func TestSegmentsForLocationId(t *testing.T) { + segments := LocationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("LocationId 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/devcenter/2024-02-01/usages/method_listbylocation.go b/resource-manager/devcenter/2024-02-01/usages/method_listbylocation.go new file mode 100644 index 00000000000..bb853588f06 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/usages/method_listbylocation.go @@ -0,0 +1,91 @@ +package usages + +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 ListByLocationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Usage +} + +type ListByLocationCompleteResult struct { + LatestHttpResponse *http.Response + Items []Usage +} + +// ListByLocation ... +func (c UsagesClient) ListByLocation(ctx context.Context, id LocationId) (result ListByLocationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/usages", 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 *[]Usage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByLocationComplete retrieves all the results into a single object +func (c UsagesClient) ListByLocationComplete(ctx context.Context, id LocationId) (ListByLocationCompleteResult, error) { + return c.ListByLocationCompleteMatchingPredicate(ctx, id, UsageOperationPredicate{}) +} + +// ListByLocationCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c UsagesClient) ListByLocationCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate UsageOperationPredicate) (result ListByLocationCompleteResult, err error) { + items := make([]Usage, 0) + + resp, err := c.ListByLocation(ctx, id) + if err != nil { + 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 = ListByLocationCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/devcenter/2024-02-01/usages/model_usage.go b/resource-manager/devcenter/2024-02-01/usages/model_usage.go new file mode 100644 index 00000000000..f7455c958f4 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/usages/model_usage.go @@ -0,0 +1,12 @@ +package usages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Usage struct { + CurrentValue *int64 `json:"currentValue,omitempty"` + Id *string `json:"id,omitempty"` + Limit *int64 `json:"limit,omitempty"` + Name *UsageName `json:"name,omitempty"` + Unit *UsageUnit `json:"unit,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/usages/model_usagename.go b/resource-manager/devcenter/2024-02-01/usages/model_usagename.go new file mode 100644 index 00000000000..ff2d9cbdd3e --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/usages/model_usagename.go @@ -0,0 +1,9 @@ +package usages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/devcenter/2024-02-01/usages/predicates.go b/resource-manager/devcenter/2024-02-01/usages/predicates.go new file mode 100644 index 00000000000..902c6beeb85 --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/usages/predicates.go @@ -0,0 +1,27 @@ +package usages + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageOperationPredicate struct { + CurrentValue *int64 + Id *string + Limit *int64 +} + +func (p UsageOperationPredicate) Matches(input Usage) bool { + + if p.CurrentValue != nil && (input.CurrentValue == nil || *p.CurrentValue != *input.CurrentValue) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Limit != nil && (input.Limit == nil || *p.Limit != *input.Limit) { + return false + } + + return true +} diff --git a/resource-manager/devcenter/2024-02-01/usages/version.go b/resource-manager/devcenter/2024-02-01/usages/version.go new file mode 100644 index 00000000000..8ab46f7e22b --- /dev/null +++ b/resource-manager/devcenter/2024-02-01/usages/version.go @@ -0,0 +1,12 @@ +package usages + +import "fmt" + +// 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-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/usages/%s", defaultApiVersion) +}