From 508c441975279a7a576f13e389add1361c456471 Mon Sep 17 00:00:00 2001 From: hc-github-team-tf-azure <> Date: Mon, 25 Mar 2024 13:32:05 +0000 Subject: [PATCH] Updating based on bdcce287 --- .../cognitive/2023-10-01-preview/client.go | 145 ++++ .../cognitiveservicesaccounts/README.md | 308 ++++++++ .../cognitiveservicesaccounts/client.go | 26 + .../cognitiveservicesaccounts/constants.go | 723 ++++++++++++++++++ .../cognitiveservicesaccounts/id_account.go | 125 +++ .../id_account_test.go | 282 +++++++ .../id_deletedaccount.go | 134 ++++ .../id_deletedaccount_test.go | 327 ++++++++ .../cognitiveservicesaccounts/id_location.go | 116 +++ .../id_location_test.go | 237 ++++++ .../method_accountscreate.go | 76 ++ .../method_accountsdelete.go | 71 ++ .../method_accountsget.go | 54 ++ .../method_accountslist.go | 92 +++ .../method_accountslistbyresourcegroup.go | 92 +++ .../method_accountslistkeys.go | 55 ++ .../method_accountslistmodels.go | 91 +++ .../method_accountslistskus.go | 55 ++ .../method_accountslistusages.go | 119 +++ .../method_accountsregeneratekey.go | 59 ++ .../method_accountsupdate.go | 75 ++ .../method_checkdomainavailability.go | 60 ++ .../method_checkskuavailability.go | 59 ++ .../method_deletedaccountsget.go | 54 ++ .../method_deletedaccountslist.go | 92 +++ .../method_deletedaccountspurge.go | 71 ++ .../method_resourceskuslist.go | 92 +++ .../model_abusepenalty.go | 28 + .../model_account.go | 23 + .../model_accountmodel.go | 25 + .../model_accountproperties.go | 36 + .../model_accountsku.go | 9 + .../model_accountskulistresult.go | 8 + .../model_apikeys.go | 9 + .../model_apiproperties.go | 17 + .../model_callratelimit.go | 10 + .../model_capacityconfig.go | 12 + .../model_checkdomainavailabilityparameter.go | 10 + .../model_checkskuavailabilityparameter.go | 10 + .../model_commitmentplanassociation.go | 9 + .../model_deploymentmodel.go | 12 + .../model_domainavailability.go | 12 + .../model_encryption.go | 9 + .../cognitiveservicesaccounts/model_iprule.go | 8 + .../model_keyvaultproperties.go | 11 + .../model_metricname.go | 9 + .../model_modeldeprecationinfo.go | 9 + .../model_modelsku.go | 30 + .../model_multiregionsettings.go | 9 + .../model_networkruleset.go | 11 + .../model_privateendpoint.go | 8 + .../model_privateendpointconnection.go | 18 + ...del_privateendpointconnectionproperties.go | 11 + ...model_privatelinkserviceconnectionstate.go | 10 + .../model_quotalimit.go | 10 + .../model_regeneratekeyparameters.go | 8 + .../model_regionsetting.go | 10 + .../model_requestmatchpattern.go | 9 + .../model_resourcesku.go | 13 + .../model_resourceskurestrictioninfo.go | 13 + .../model_resourceskurestrictions.go | 11 + .../cognitiveservicesaccounts/model_sku.go | 12 + .../model_skuavailability.go | 13 + .../model_skuavailabilitylistresult.go | 8 + .../model_skucapability.go | 9 + .../model_skuchangeinfo.go | 10 + .../model_throttlingrule.go | 13 + .../cognitiveservicesaccounts/model_usage.go | 14 + .../model_userownedamlworkspace.go | 9 + .../model_userownedstorage.go | 9 + .../model_virtualnetworkrule.go | 10 + .../cognitiveservicesaccounts/predicates.go | 136 ++++ .../cognitiveservicesaccounts/version.go | 12 + .../README.md | 117 +++ .../client.go | 26 + .../constants.go | 163 ++++ .../id_commitmentplan.go | 125 +++ .../id_commitmentplan_test.go | 282 +++++++ ...ethod_commitmentplanscreateorupdateplan.go | 75 ++ .../method_commitmentplansdeleteplan.go | 71 ++ .../method_commitmentplansgetplan.go | 54 ++ ...commitmentplanslistplansbyresourcegroup.go | 92 +++ ..._commitmentplanslistplansbysubscription.go | 92 +++ .../method_commitmentplansupdateplan.go | 75 ++ .../model_commitmentperiod.go | 12 + .../model_commitmentplan.go | 21 + .../model_commitmentplanproperties.go | 16 + .../model_commitmentquota.go | 9 + .../model_patchresourcetagsandsku.go | 9 + .../model_sku.go | 12 + .../predicates.go | 42 + .../version.go | 12 + .../commitmentplans/README.md | 148 ++++ .../commitmentplans/client.go | 26 + .../commitmentplans/constants.go | 163 ++++ .../commitmentplans/id_account.go | 125 +++ .../commitmentplans/id_account_test.go | 282 +++++++ .../commitmentplans/id_accountassociation.go | 134 ++++ .../id_accountassociation_test.go | 327 ++++++++ .../id_accountcommitmentplan.go | 134 ++++ .../id_accountcommitmentplan_test.go | 327 ++++++++ .../commitmentplans/id_commitmentplan.go | 125 +++ .../commitmentplans/id_commitmentplan_test.go | 282 +++++++ .../commitmentplans/method_createorupdate.go | 59 ++ .../method_createorupdateassociation.go | 75 ++ .../commitmentplans/method_delete.go | 71 ++ .../method_deleteassociation.go | 71 ++ .../commitmentplans/method_get.go | 54 ++ .../commitmentplans/method_getassociation.go | 54 ++ .../commitmentplans/method_list.go | 91 +++ .../method_listassociations.go | 91 +++ .../commitmentplans/model_commitmentperiod.go | 12 + .../commitmentplans/model_commitmentplan.go | 21 + .../model_commitmentplanaccountassociation.go | 18 + ...mitmentplanaccountassociationproperties.go | 8 + .../model_commitmentplanproperties.go | 16 + .../commitmentplans/model_commitmentquota.go | 9 + .../commitmentplans/model_sku.go | 12 + .../commitmentplans/predicates.go | 70 ++ .../commitmentplans/version.go | 12 + .../commitmenttiers/README.md | 37 + .../commitmenttiers/client.go | 26 + .../commitmenttiers/constants.go | 57 ++ .../commitmenttiers/id_location.go | 116 +++ .../commitmenttiers/id_location_test.go | 237 ++++++ .../commitmenttiers/method_list.go | 91 +++ .../commitmenttiers/model_commitmentcost.go | 9 + .../commitmenttiers/model_commitmentquota.go | 9 + .../commitmenttiers/model_commitmenttier.go | 15 + .../commitmenttiers/predicates.go | 37 + .../commitmenttiers/version.go | 12 + .../2023-10-01-preview/deployments/README.md | 116 +++ .../2023-10-01-preview/deployments/client.go | 26 + .../deployments/constants.go | 204 +++++ .../deployments/id_account.go | 125 +++ .../deployments/id_account_test.go | 282 +++++++ .../deployments/id_deployment.go | 134 ++++ .../deployments/id_deployment_test.go | 327 ++++++++ .../deployments/method_createorupdate.go | 75 ++ .../deployments/method_delete.go | 71 ++ .../deployments/method_get.go | 54 ++ .../deployments/method_list.go | 91 +++ .../deployments/method_listskus.go | 91 +++ .../deployments/method_update.go | 75 ++ .../deployments/model_callratelimit.go | 10 + .../deployments/model_capacityconfig.go | 12 + .../deployments/model_deployment.go | 19 + .../model_deploymentcapacitysettings.go | 9 + .../deployments/model_deploymentmodel.go | 12 + .../deployments/model_deploymentproperties.go | 18 + .../model_deploymentscalesettings.go | 10 + .../model_patchresourcetagsandsku.go | 9 + .../deployments/model_requestmatchpattern.go | 9 + .../deployments/model_sku.go | 12 + .../deployments/model_skuresource.go | 10 + .../deployments/model_throttlingrule.go | 13 + .../deployments/predicates.go | 45 ++ .../2023-10-01-preview/deployments/version.go | 12 + .../encryptionscopes/README.md | 86 +++ .../encryptionscopes/client.go | 26 + .../encryptionscopes/constants.go | 148 ++++ .../encryptionscopes/id_account.go | 125 +++ .../encryptionscopes/id_account_test.go | 282 +++++++ .../encryptionscopes/id_encryptionscope.go | 134 ++++ .../id_encryptionscope_test.go | 327 ++++++++ .../encryptionscopes/method_createorupdate.go | 59 ++ .../encryptionscopes/method_delete.go | 70 ++ .../encryptionscopes/method_get.go | 54 ++ .../encryptionscopes/method_list.go | 91 +++ .../encryptionscopes/model_encryptionscope.go | 18 + .../model_encryptionscopeproperties.go | 11 + .../model_keyvaultproperties.go | 11 + .../encryptionscopes/predicates.go | 32 + .../encryptionscopes/version.go | 12 + .../2023-10-01-preview/models/README.md | 37 + .../2023-10-01-preview/models/client.go | 26 + .../2023-10-01-preview/models/constants.go | 51 ++ .../2023-10-01-preview/models/id_location.go | 116 +++ .../models/id_location_test.go | 237 ++++++ .../2023-10-01-preview/models/method_list.go | 91 +++ .../models/model_accountmodel.go | 25 + .../models/model_callratelimit.go | 10 + .../models/model_capacityconfig.go | 12 + .../models/model_deploymentmodel.go | 12 + .../2023-10-01-preview/models/model_model.go | 10 + .../models/model_modeldeprecationinfo.go | 9 + .../models/model_modelsku.go | 30 + .../models/model_requestmatchpattern.go | 9 + .../models/model_throttlingrule.go | 13 + .../2023-10-01-preview/models/predicates.go | 22 + .../2023-10-01-preview/models/version.go | 12 + .../privateendpointconnections/README.md | 81 ++ .../privateendpointconnections/client.go | 26 + .../privateendpointconnections/constants.go | 101 +++ .../privateendpointconnections/id_account.go | 125 +++ .../id_account_test.go | 282 +++++++ .../id_privateendpointconnection.go | 134 ++++ .../id_privateendpointconnection_test.go | 327 ++++++++ .../method_createorupdate.go | 75 ++ .../method_delete.go | 71 ++ .../privateendpointconnections/method_get.go | 54 ++ .../privateendpointconnections/method_list.go | 55 ++ .../model_privateendpoint.go | 8 + .../model_privateendpointconnection.go | 18 + ...del_privateendpointconnectionlistresult.go | 8 + ...del_privateendpointconnectionproperties.go | 11 + ...model_privatelinkserviceconnectionstate.go | 10 + .../privateendpointconnections/version.go | 12 + .../privatelinkresources/README.md | 36 + .../privatelinkresources/client.go | 26 + .../privatelinkresources/id_account.go | 125 +++ .../privatelinkresources/id_account_test.go | 282 +++++++ .../privatelinkresources/method_list.go | 55 ++ .../model_privatelinkresource.go | 11 + .../model_privatelinkresourcelistresult.go | 8 + .../model_privatelinkresourceproperties.go | 11 + .../privatelinkresources/version.go | 12 + .../raiblocklists/README.md | 152 ++++ .../raiblocklists/client.go | 26 + .../raiblocklists/id_account.go | 125 +++ .../raiblocklists/id_account_test.go | 282 +++++++ .../raiblocklists/id_raiblocklist.go | 134 ++++ .../raiblocklists/id_raiblocklist_test.go | 327 ++++++++ .../raiblocklists/id_raiblocklistitem.go | 143 ++++ .../raiblocklists/id_raiblocklistitem_test.go | 372 +++++++++ .../raiblocklists/method_createorupdate.go | 59 ++ .../raiblocklists/method_delete.go | 70 ++ .../raiblocklists/method_get.go | 54 ++ .../raiblocklists/method_list.go | 91 +++ .../method_raiblocklistitemscreateorupdate.go | 59 ++ .../method_raiblocklistitemsdelete.go | 70 ++ .../method_raiblocklistitemsget.go | 54 ++ .../method_raiblocklistitemslist.go | 91 +++ .../raiblocklists/model_raiblocklist.go | 18 + .../raiblocklists/model_raiblocklistitem.go | 18 + .../model_raiblocklistitemproperties.go | 9 + .../model_raiblocklistproperties.go | 8 + .../raiblocklists/predicates.go | 60 ++ .../raiblocklists/version.go | 12 + .../raicontentfilters/README.md | 37 + .../raicontentfilters/client.go | 26 + .../raicontentfilters/constants.go | 51 ++ .../raicontentfilters/id_location.go | 116 +++ .../raicontentfilters/id_location_test.go | 237 ++++++ .../raicontentfilters/method_list.go | 91 +++ .../model_raicontentfilter.go | 10 + .../raicontentfilters/predicates.go | 22 + .../raicontentfilters/version.go | 12 + .../2023-10-01-preview/raipolicies/README.md | 86 +++ .../2023-10-01-preview/raipolicies/client.go | 26 + .../raipolicies/constants.go | 180 +++++ .../raipolicies/id_account.go | 125 +++ .../raipolicies/id_account_test.go | 282 +++++++ .../raipolicies/id_raipolicy.go | 134 ++++ .../raipolicies/id_raipolicy_test.go | 327 ++++++++ .../raipolicies/method_createorupdate.go | 59 ++ .../raipolicies/method_delete.go | 70 ++ .../raipolicies/method_get.go | 54 ++ .../raipolicies/method_list.go | 91 +++ .../raipolicies/model_raiblocklistconfig.go | 9 + .../raipolicies/model_raipolicy.go | 18 + .../model_raipolicycontentfilter.go | 12 + .../raipolicies/model_raipolicyproperties.go | 13 + .../raipolicies/predicates.go | 32 + .../2023-10-01-preview/raipolicies/version.go | 12 + .../2023-10-01-preview/skus/README.md | 38 + .../2023-10-01-preview/skus/client.go | 26 + .../2023-10-01-preview/skus/constants.go | 92 +++ .../skus/method_resourceskuslist.go | 92 +++ .../skus/model_resourcesku.go | 13 + .../skus/model_resourceskurestrictioninfo.go | 13 + .../skus/model_resourceskurestrictions.go | 11 + .../2023-10-01-preview/skus/predicates.go | 32 + .../2023-10-01-preview/skus/version.go | 12 + .../2023-10-01-preview/usages/README.md | 37 + .../2023-10-01-preview/usages/client.go | 26 + .../2023-10-01-preview/usages/constants.go | 113 +++ .../2023-10-01-preview/usages/id_location.go | 116 +++ .../usages/id_location_test.go | 237 ++++++ .../2023-10-01-preview/usages/method_list.go | 119 +++ .../usages/model_metricname.go | 9 + .../2023-10-01-preview/usages/model_usage.go | 14 + .../2023-10-01-preview/usages/predicates.go | 32 + .../2023-10-01-preview/usages/version.go | 12 + 284 files changed, 20613 insertions(+) create mode 100644 resource-manager/cognitive/2023-10-01-preview/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/constants.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_account.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_account_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_deletedaccount.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_deletedaccount_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_location.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_location_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountscreate.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsdelete.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsget.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslist.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistbyresourcegroup.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistkeys.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistmodels.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistskus.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistusages.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsregeneratekey.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsupdate.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_checkdomainavailability.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_checkskuavailability.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_deletedaccountsget.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_deletedaccountslist.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_deletedaccountspurge.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_resourceskuslist.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_abusepenalty.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_account.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountmodel.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountsku.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountskulistresult.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_apikeys.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_apiproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_callratelimit.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_capacityconfig.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_checkdomainavailabilityparameter.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_checkskuavailabilityparameter.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_commitmentplanassociation.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_deploymentmodel.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_domainavailability.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_encryption.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_iprule.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_keyvaultproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_metricname.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_modeldeprecationinfo.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_modelsku.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_multiregionsettings.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_networkruleset.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privateendpoint.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privateendpointconnection.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_quotalimit.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_regeneratekeyparameters.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_regionsetting.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_requestmatchpattern.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_resourcesku.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_resourceskurestrictioninfo.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_resourceskurestrictions.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_sku.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skuavailability.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skuavailabilitylistresult.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skucapability.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skuchangeinfo.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_throttlingrule.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_usage.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_userownedamlworkspace.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_userownedstorage.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_virtualnetworkrule.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/predicates.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/version.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/constants.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/id_commitmentplan.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/id_commitmentplan_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplanscreateorupdateplan.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplansdeleteplan.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplansgetplan.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplanslistplansbyresourcegroup.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplanslistplansbysubscription.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplansupdateplan.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentperiod.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentplan.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentplanproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentquota.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_patchresourcetagsandsku.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_sku.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/predicates.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/version.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/constants.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_account.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_account_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountassociation.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountassociation_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountcommitmentplan.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountcommitmentplan_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_commitmentplan.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_commitmentplan_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_createorupdate.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_createorupdateassociation.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_delete.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_deleteassociation.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_get.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_getassociation.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_list.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_listassociations.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentperiod.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplan.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplanaccountassociation.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplanaccountassociationproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplanproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentquota.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_sku.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/predicates.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmentplans/version.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmenttiers/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmenttiers/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmenttiers/constants.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmenttiers/id_location.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmenttiers/id_location_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmenttiers/method_list.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmenttiers/model_commitmentcost.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmenttiers/model_commitmentquota.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmenttiers/model_commitmenttier.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmenttiers/predicates.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/commitmenttiers/version.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/constants.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/id_account.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/id_account_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/id_deployment.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/id_deployment_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/method_createorupdate.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/method_delete.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/method_get.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/method_list.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/method_listskus.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/method_update.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/model_callratelimit.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/model_capacityconfig.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/model_deployment.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentcapacitysettings.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentmodel.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentscalesettings.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/model_patchresourcetagsandsku.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/model_requestmatchpattern.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/model_sku.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/model_skuresource.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/model_throttlingrule.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/predicates.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/deployments/version.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/constants.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_account.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_account_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_encryptionscope.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_encryptionscope_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_createorupdate.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_delete.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_get.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_list.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/model_encryptionscope.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/model_encryptionscopeproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/model_keyvaultproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/predicates.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/encryptionscopes/version.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/constants.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/id_location.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/id_location_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/method_list.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/model_accountmodel.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/model_callratelimit.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/model_capacityconfig.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/model_deploymentmodel.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/model_model.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/model_modeldeprecationinfo.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/model_modelsku.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/model_requestmatchpattern.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/model_throttlingrule.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/predicates.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/models/version.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/constants.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_account.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_account_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_privateendpointconnection.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_privateendpointconnection_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_createorupdate.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_delete.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_get.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_list.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpoint.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpointconnection.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpointconnectionlistresult.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstate.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/version.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privatelinkresources/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/privatelinkresources/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privatelinkresources/id_account.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privatelinkresources/id_account_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privatelinkresources/method_list.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privatelinkresources/model_privatelinkresource.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privatelinkresources/model_privatelinkresourcelistresult.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privatelinkresources/model_privatelinkresourceproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/privatelinkresources/version.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_account.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_account_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklist.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklist_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklistitem.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklistitem_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_createorupdate.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_delete.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_get.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_list.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemscreateorupdate.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemsdelete.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemsget.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemslist.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklist.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklistitem.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklistitemproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklistproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/predicates.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raiblocklists/version.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raicontentfilters/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/raicontentfilters/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raicontentfilters/constants.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raicontentfilters/id_location.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raicontentfilters/id_location_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raicontentfilters/method_list.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raicontentfilters/model_raicontentfilter.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raicontentfilters/predicates.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raicontentfilters/version.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/constants.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/id_account.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/id_account_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/id_raipolicy.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/id_raipolicy_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/method_createorupdate.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/method_delete.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/method_get.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/method_list.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raiblocklistconfig.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raipolicy.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raipolicycontentfilter.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raipolicyproperties.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/predicates.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/raipolicies/version.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/skus/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/skus/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/skus/constants.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/skus/method_resourceskuslist.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/skus/model_resourcesku.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/skus/model_resourceskurestrictioninfo.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/skus/model_resourceskurestrictions.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/skus/predicates.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/skus/version.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/usages/README.md create mode 100644 resource-manager/cognitive/2023-10-01-preview/usages/client.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/usages/constants.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/usages/id_location.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/usages/id_location_test.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/usages/method_list.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/usages/model_metricname.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/usages/model_usage.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/usages/predicates.go create mode 100644 resource-manager/cognitive/2023-10-01-preview/usages/version.go diff --git a/resource-manager/cognitive/2023-10-01-preview/client.go b/resource-manager/cognitive/2023-10-01-preview/client.go new file mode 100644 index 00000000000..1ee312be174 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/client.go @@ -0,0 +1,145 @@ +package v2023_10_01_preview + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/commitmentplans" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/commitmenttiers" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/deployments" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/encryptionscopes" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/models" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/privatelinkresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/raiblocklists" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/raicontentfilters" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/raipolicies" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/skus" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/usages" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + CognitiveServicesAccounts *cognitiveservicesaccounts.CognitiveServicesAccountsClient + CognitiveServicesCommitmentPlans *cognitiveservicescommitmentplans.CognitiveServicesCommitmentPlansClient + CommitmentPlans *commitmentplans.CommitmentPlansClient + CommitmentTiers *commitmenttiers.CommitmentTiersClient + Deployments *deployments.DeploymentsClient + EncryptionScopes *encryptionscopes.EncryptionScopesClient + Models *models.ModelsClient + PrivateEndpointConnections *privateendpointconnections.PrivateEndpointConnectionsClient + PrivateLinkResources *privatelinkresources.PrivateLinkResourcesClient + RaiBlocklists *raiblocklists.RaiBlocklistsClient + RaiContentFilters *raicontentfilters.RaiContentFiltersClient + RaiPolicies *raipolicies.RaiPoliciesClient + Skus *skus.SkusClient + Usages *usages.UsagesClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + cognitiveServicesAccountsClient, err := cognitiveservicesaccounts.NewCognitiveServicesAccountsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CognitiveServicesAccounts client: %+v", err) + } + configureFunc(cognitiveServicesAccountsClient.Client) + + cognitiveServicesCommitmentPlansClient, err := cognitiveservicescommitmentplans.NewCognitiveServicesCommitmentPlansClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CognitiveServicesCommitmentPlans client: %+v", err) + } + configureFunc(cognitiveServicesCommitmentPlansClient.Client) + + commitmentPlansClient, err := commitmentplans.NewCommitmentPlansClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CommitmentPlans client: %+v", err) + } + configureFunc(commitmentPlansClient.Client) + + commitmentTiersClient, err := commitmenttiers.NewCommitmentTiersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CommitmentTiers client: %+v", err) + } + configureFunc(commitmentTiersClient.Client) + + deploymentsClient, err := deployments.NewDeploymentsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Deployments client: %+v", err) + } + configureFunc(deploymentsClient.Client) + + encryptionScopesClient, err := encryptionscopes.NewEncryptionScopesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building EncryptionScopes client: %+v", err) + } + configureFunc(encryptionScopesClient.Client) + + modelsClient, err := models.NewModelsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Models client: %+v", err) + } + configureFunc(modelsClient.Client) + + privateEndpointConnectionsClient, err := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateEndpointConnections client: %+v", err) + } + configureFunc(privateEndpointConnectionsClient.Client) + + privateLinkResourcesClient, err := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building PrivateLinkResources client: %+v", err) + } + configureFunc(privateLinkResourcesClient.Client) + + raiBlocklistsClient, err := raiblocklists.NewRaiBlocklistsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RaiBlocklists client: %+v", err) + } + configureFunc(raiBlocklistsClient.Client) + + raiContentFiltersClient, err := raicontentfilters.NewRaiContentFiltersClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RaiContentFilters client: %+v", err) + } + configureFunc(raiContentFiltersClient.Client) + + raiPoliciesClient, err := raipolicies.NewRaiPoliciesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RaiPolicies client: %+v", err) + } + configureFunc(raiPoliciesClient.Client) + + skusClient, err := skus.NewSkusClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Skus client: %+v", err) + } + configureFunc(skusClient.Client) + + usagesClient, err := usages.NewUsagesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Usages client: %+v", err) + } + configureFunc(usagesClient.Client) + + return &Client{ + CognitiveServicesAccounts: cognitiveServicesAccountsClient, + CognitiveServicesCommitmentPlans: cognitiveServicesCommitmentPlansClient, + CommitmentPlans: commitmentPlansClient, + CommitmentTiers: commitmentTiersClient, + Deployments: deploymentsClient, + EncryptionScopes: encryptionScopesClient, + Models: modelsClient, + PrivateEndpointConnections: privateEndpointConnectionsClient, + PrivateLinkResources: privateLinkResourcesClient, + RaiBlocklists: raiBlocklistsClient, + RaiContentFilters: raiContentFiltersClient, + RaiPolicies: raiPoliciesClient, + Skus: skusClient, + Usages: usagesClient, + }, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/README.md b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/README.md new file mode 100644 index 00000000000..172d870e0db --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/README.md @@ -0,0 +1,308 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts` Documentation + +The `cognitiveservicesaccounts` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts" +``` + + +### Client Initialization + +```go +client := cognitiveservicesaccounts.NewCognitiveServicesAccountsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CognitiveServicesAccountsClient.AccountsCreate` + +```go +ctx := context.TODO() +id := cognitiveservicesaccounts.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +payload := cognitiveservicesaccounts.Account{ + // ... +} + + +if err := client.AccountsCreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.AccountsDelete` + +```go +ctx := context.TODO() +id := cognitiveservicesaccounts.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +if err := client.AccountsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.AccountsGet` + +```go +ctx := context.TODO() +id := cognitiveservicesaccounts.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +read, err := client.AccountsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.AccountsList` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.AccountsList(ctx, id)` can be used to do batched pagination +items, err := client.AccountsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.AccountsListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.AccountsListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.AccountsListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.AccountsListKeys` + +```go +ctx := context.TODO() +id := cognitiveservicesaccounts.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +read, err := client.AccountsListKeys(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.AccountsListModels` + +```go +ctx := context.TODO() +id := cognitiveservicesaccounts.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +// alternatively `client.AccountsListModels(ctx, id)` can be used to do batched pagination +items, err := client.AccountsListModelsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.AccountsListSkus` + +```go +ctx := context.TODO() +id := cognitiveservicesaccounts.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +read, err := client.AccountsListSkus(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.AccountsListUsages` + +```go +ctx := context.TODO() +id := cognitiveservicesaccounts.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +// alternatively `client.AccountsListUsages(ctx, id, cognitiveservicesaccounts.DefaultAccountsListUsagesOperationOptions())` can be used to do batched pagination +items, err := client.AccountsListUsagesComplete(ctx, id, cognitiveservicesaccounts.DefaultAccountsListUsagesOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.AccountsRegenerateKey` + +```go +ctx := context.TODO() +id := cognitiveservicesaccounts.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +payload := cognitiveservicesaccounts.RegenerateKeyParameters{ + // ... +} + + +read, err := client.AccountsRegenerateKey(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.AccountsUpdate` + +```go +ctx := context.TODO() +id := cognitiveservicesaccounts.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +payload := cognitiveservicesaccounts.Account{ + // ... +} + + +if err := client.AccountsUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.CheckDomainAvailability` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := cognitiveservicesaccounts.CheckDomainAvailabilityParameter{ + // ... +} + + +read, err := client.CheckDomainAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.CheckSkuAvailability` + +```go +ctx := context.TODO() +id := cognitiveservicesaccounts.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +payload := cognitiveservicesaccounts.CheckSkuAvailabilityParameter{ + // ... +} + + +read, err := client.CheckSkuAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.DeletedAccountsGet` + +```go +ctx := context.TODO() +id := cognitiveservicesaccounts.NewDeletedAccountID("12345678-1234-9876-4563-123456789012", "locationValue", "example-resource-group", "deletedAccountValue") + +read, err := client.DeletedAccountsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.DeletedAccountsList` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.DeletedAccountsList(ctx, id)` can be used to do batched pagination +items, err := client.DeletedAccountsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.DeletedAccountsPurge` + +```go +ctx := context.TODO() +id := cognitiveservicesaccounts.NewDeletedAccountID("12345678-1234-9876-4563-123456789012", "locationValue", "example-resource-group", "deletedAccountValue") + +if err := client.DeletedAccountsPurgeThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `CognitiveServicesAccountsClient.ResourceSkusList` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ResourceSkusList(ctx, id)` can be used to do batched pagination +items, err := client.ResourceSkusListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/client.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/client.go new file mode 100644 index 00000000000..574dcc192d1 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/client.go @@ -0,0 +1,26 @@ +package cognitiveservicesaccounts + +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 CognitiveServicesAccountsClient struct { + Client *resourcemanager.Client +} + +func NewCognitiveServicesAccountsClientWithBaseURI(sdkApi sdkEnv.Api) (*CognitiveServicesAccountsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "cognitiveservicesaccounts", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CognitiveServicesAccountsClient: %+v", err) + } + + return &CognitiveServicesAccountsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/constants.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/constants.go new file mode 100644 index 00000000000..ac1be80592a --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/constants.go @@ -0,0 +1,723 @@ +package cognitiveservicesaccounts + +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 AbusePenaltyAction string + +const ( + AbusePenaltyActionBlock AbusePenaltyAction = "Block" + AbusePenaltyActionThrottle AbusePenaltyAction = "Throttle" +) + +func PossibleValuesForAbusePenaltyAction() []string { + return []string{ + string(AbusePenaltyActionBlock), + string(AbusePenaltyActionThrottle), + } +} + +func (s *AbusePenaltyAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAbusePenaltyAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAbusePenaltyAction(input string) (*AbusePenaltyAction, error) { + vals := map[string]AbusePenaltyAction{ + "block": AbusePenaltyActionBlock, + "throttle": AbusePenaltyActionThrottle, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AbusePenaltyAction(input) + return &out, nil +} + +type ByPassSelection string + +const ( + ByPassSelectionAzureServices ByPassSelection = "AzureServices" + ByPassSelectionNone ByPassSelection = "None" +) + +func PossibleValuesForByPassSelection() []string { + return []string{ + string(ByPassSelectionAzureServices), + string(ByPassSelectionNone), + } +} + +func (s *ByPassSelection) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseByPassSelection(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseByPassSelection(input string) (*ByPassSelection, error) { + vals := map[string]ByPassSelection{ + "azureservices": ByPassSelectionAzureServices, + "none": ByPassSelectionNone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ByPassSelection(input) + return &out, nil +} + +type KeyName string + +const ( + KeyNameKeyOne KeyName = "Key1" + KeyNameKeyTwo KeyName = "Key2" +) + +func PossibleValuesForKeyName() []string { + return []string{ + string(KeyNameKeyOne), + string(KeyNameKeyTwo), + } +} + +func (s *KeyName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKeyName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKeyName(input string) (*KeyName, error) { + vals := map[string]KeyName{ + "key1": KeyNameKeyOne, + "key2": KeyNameKeyTwo, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KeyName(input) + return &out, nil +} + +type KeySource string + +const ( + KeySourceMicrosoftPointCognitiveServices KeySource = "Microsoft.CognitiveServices" + KeySourceMicrosoftPointKeyVault KeySource = "Microsoft.KeyVault" +) + +func PossibleValuesForKeySource() []string { + return []string{ + string(KeySourceMicrosoftPointCognitiveServices), + string(KeySourceMicrosoftPointKeyVault), + } +} + +func (s *KeySource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKeySource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKeySource(input string) (*KeySource, error) { + vals := map[string]KeySource{ + "microsoft.cognitiveservices": KeySourceMicrosoftPointCognitiveServices, + "microsoft.keyvault": KeySourceMicrosoftPointKeyVault, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KeySource(input) + return &out, nil +} + +type ModelLifecycleStatus string + +const ( + ModelLifecycleStatusGenerallyAvailable ModelLifecycleStatus = "GenerallyAvailable" + ModelLifecycleStatusPreview ModelLifecycleStatus = "Preview" +) + +func PossibleValuesForModelLifecycleStatus() []string { + return []string{ + string(ModelLifecycleStatusGenerallyAvailable), + string(ModelLifecycleStatusPreview), + } +} + +func (s *ModelLifecycleStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseModelLifecycleStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseModelLifecycleStatus(input string) (*ModelLifecycleStatus, error) { + vals := map[string]ModelLifecycleStatus{ + "generallyavailable": ModelLifecycleStatusGenerallyAvailable, + "preview": ModelLifecycleStatusPreview, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ModelLifecycleStatus(input) + return &out, nil +} + +type NetworkRuleAction string + +const ( + NetworkRuleActionAllow NetworkRuleAction = "Allow" + NetworkRuleActionDeny NetworkRuleAction = "Deny" +) + +func PossibleValuesForNetworkRuleAction() []string { + return []string{ + string(NetworkRuleActionAllow), + string(NetworkRuleActionDeny), + } +} + +func (s *NetworkRuleAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseNetworkRuleAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseNetworkRuleAction(input string) (*NetworkRuleAction, error) { + vals := map[string]NetworkRuleAction{ + "allow": NetworkRuleActionAllow, + "deny": NetworkRuleActionDeny, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NetworkRuleAction(input) + return &out, nil +} + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateMoving ProvisioningState = "Moving" + ProvisioningStateResolvingDNS ProvisioningState = "ResolvingDNS" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateMoving), + string(ProvisioningStateResolvingDNS), + string(ProvisioningStateSucceeded), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "creating": ProvisioningStateCreating, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "moving": ProvisioningStateMoving, + "resolvingdns": ProvisioningStateResolvingDNS, + "succeeded": ProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func (s *PublicNetworkAccess) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePublicNetworkAccess(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": PublicNetworkAccessDisabled, + "enabled": PublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccess(input) + return &out, nil +} + +type QuotaUsageStatus string + +const ( + QuotaUsageStatusBlocked QuotaUsageStatus = "Blocked" + QuotaUsageStatusInOverage QuotaUsageStatus = "InOverage" + QuotaUsageStatusIncluded QuotaUsageStatus = "Included" + QuotaUsageStatusUnknown QuotaUsageStatus = "Unknown" +) + +func PossibleValuesForQuotaUsageStatus() []string { + return []string{ + string(QuotaUsageStatusBlocked), + string(QuotaUsageStatusInOverage), + string(QuotaUsageStatusIncluded), + string(QuotaUsageStatusUnknown), + } +} + +func (s *QuotaUsageStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQuotaUsageStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQuotaUsageStatus(input string) (*QuotaUsageStatus, error) { + vals := map[string]QuotaUsageStatus{ + "blocked": QuotaUsageStatusBlocked, + "inoverage": QuotaUsageStatusInOverage, + "included": QuotaUsageStatusIncluded, + "unknown": QuotaUsageStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QuotaUsageStatus(input) + return &out, nil +} + +type ResourceSkuRestrictionsReasonCode string + +const ( + ResourceSkuRestrictionsReasonCodeNotAvailableForSubscription ResourceSkuRestrictionsReasonCode = "NotAvailableForSubscription" + ResourceSkuRestrictionsReasonCodeQuotaId ResourceSkuRestrictionsReasonCode = "QuotaId" +) + +func PossibleValuesForResourceSkuRestrictionsReasonCode() []string { + return []string{ + string(ResourceSkuRestrictionsReasonCodeNotAvailableForSubscription), + string(ResourceSkuRestrictionsReasonCodeQuotaId), + } +} + +func (s *ResourceSkuRestrictionsReasonCode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceSkuRestrictionsReasonCode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceSkuRestrictionsReasonCode(input string) (*ResourceSkuRestrictionsReasonCode, error) { + vals := map[string]ResourceSkuRestrictionsReasonCode{ + "notavailableforsubscription": ResourceSkuRestrictionsReasonCodeNotAvailableForSubscription, + "quotaid": ResourceSkuRestrictionsReasonCodeQuotaId, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceSkuRestrictionsReasonCode(input) + return &out, nil +} + +type ResourceSkuRestrictionsType string + +const ( + ResourceSkuRestrictionsTypeLocation ResourceSkuRestrictionsType = "Location" + ResourceSkuRestrictionsTypeZone ResourceSkuRestrictionsType = "Zone" +) + +func PossibleValuesForResourceSkuRestrictionsType() []string { + return []string{ + string(ResourceSkuRestrictionsTypeLocation), + string(ResourceSkuRestrictionsTypeZone), + } +} + +func (s *ResourceSkuRestrictionsType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceSkuRestrictionsType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceSkuRestrictionsType(input string) (*ResourceSkuRestrictionsType, error) { + vals := map[string]ResourceSkuRestrictionsType{ + "location": ResourceSkuRestrictionsTypeLocation, + "zone": ResourceSkuRestrictionsTypeZone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceSkuRestrictionsType(input) + return &out, nil +} + +type RoutingMethods string + +const ( + RoutingMethodsPerformance RoutingMethods = "Performance" + RoutingMethodsPriority RoutingMethods = "Priority" + RoutingMethodsWeighted RoutingMethods = "Weighted" +) + +func PossibleValuesForRoutingMethods() []string { + return []string{ + string(RoutingMethodsPerformance), + string(RoutingMethodsPriority), + string(RoutingMethodsWeighted), + } +} + +func (s *RoutingMethods) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRoutingMethods(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRoutingMethods(input string) (*RoutingMethods, error) { + vals := map[string]RoutingMethods{ + "performance": RoutingMethodsPerformance, + "priority": RoutingMethodsPriority, + "weighted": RoutingMethodsWeighted, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RoutingMethods(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierEnterprise SkuTier = "Enterprise" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierEnterprise), + 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, + "enterprise": SkuTierEnterprise, + "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 +} + +type UnitType string + +const ( + UnitTypeBytes UnitType = "Bytes" + UnitTypeBytesPerSecond UnitType = "BytesPerSecond" + UnitTypeCount UnitType = "Count" + UnitTypeCountPerSecond UnitType = "CountPerSecond" + UnitTypeMilliseconds UnitType = "Milliseconds" + UnitTypePercent UnitType = "Percent" + UnitTypeSeconds UnitType = "Seconds" +) + +func PossibleValuesForUnitType() []string { + return []string{ + string(UnitTypeBytes), + string(UnitTypeBytesPerSecond), + string(UnitTypeCount), + string(UnitTypeCountPerSecond), + string(UnitTypeMilliseconds), + string(UnitTypePercent), + string(UnitTypeSeconds), + } +} + +func (s *UnitType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUnitType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUnitType(input string) (*UnitType, error) { + vals := map[string]UnitType{ + "bytes": UnitTypeBytes, + "bytespersecond": UnitTypeBytesPerSecond, + "count": UnitTypeCount, + "countpersecond": UnitTypeCountPerSecond, + "milliseconds": UnitTypeMilliseconds, + "percent": UnitTypePercent, + "seconds": UnitTypeSeconds, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UnitType(input) + return &out, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_account.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_account.go new file mode 100644 index 00000000000..9c86f4885eb --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_account.go @@ -0,0 +1,125 @@ +package cognitiveservicesaccounts + +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 = &AccountId{} + +// AccountId is a struct representing the Resource ID for a Account +type AccountId struct { + SubscriptionId string + ResourceGroupName string + AccountName string +} + +// NewAccountID returns a new AccountId struct +func NewAccountID(subscriptionId string, resourceGroupName string, accountName string) AccountId { + return AccountId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + } +} + +// ParseAccountID parses 'input' into a AccountId +func ParseAccountID(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccountIDInsensitively parses 'input' case-insensitively into a AccountId +// note: this method should only be used for API response data and not user input +func ParseAccountIDInsensitively(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccountId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + return nil +} + +// ValidateAccountID checks that 'input' can be parsed as a Account ID +func ValidateAccountID(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 := ParseAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Account ID +func (id AccountId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Account ID +func (id AccountId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + } +} + +// String returns a human-readable description of this Account ID +func (id AccountId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + } + return fmt.Sprintf("Account (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_account_test.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_account_test.go new file mode 100644 index 00000000000..ca5467e4c18 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_account_test.go @@ -0,0 +1,282 @@ +package cognitiveservicesaccounts + +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 = &AccountId{} + +func TestNewAccountID(t *testing.T) { + id := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } +} + +func TestFormatAccountID(t *testing.T) { + actual := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccountID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestParseAccountIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestSegmentsForAccountId(t *testing.T) { + segments := AccountId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccountId 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/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_deletedaccount.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_deletedaccount.go new file mode 100644 index 00000000000..ac0ca92407e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_deletedaccount.go @@ -0,0 +1,134 @@ +package cognitiveservicesaccounts + +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 = &DeletedAccountId{} + +// DeletedAccountId is a struct representing the Resource ID for a Deleted Account +type DeletedAccountId struct { + SubscriptionId string + LocationName string + ResourceGroupName string + DeletedAccountName string +} + +// NewDeletedAccountID returns a new DeletedAccountId struct +func NewDeletedAccountID(subscriptionId string, locationName string, resourceGroupName string, deletedAccountName string) DeletedAccountId { + return DeletedAccountId{ + SubscriptionId: subscriptionId, + LocationName: locationName, + ResourceGroupName: resourceGroupName, + DeletedAccountName: deletedAccountName, + } +} + +// ParseDeletedAccountID parses 'input' into a DeletedAccountId +func ParseDeletedAccountID(input string) (*DeletedAccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeletedAccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedAccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeletedAccountIDInsensitively parses 'input' case-insensitively into a DeletedAccountId +// note: this method should only be used for API response data and not user input +func ParseDeletedAccountIDInsensitively(input string) (*DeletedAccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeletedAccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeletedAccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeletedAccountId) 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) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.DeletedAccountName, ok = input.Parsed["deletedAccountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deletedAccountName", input) + } + + return nil +} + +// ValidateDeletedAccountID checks that 'input' can be parsed as a Deleted Account ID +func ValidateDeletedAccountID(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 := ParseDeletedAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Deleted Account ID +func (id DeletedAccountId) ID() string { + fmtString := "/subscriptions/%s/providers/Microsoft.CognitiveServices/locations/%s/resourceGroups/%s/deletedAccounts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.LocationName, id.ResourceGroupName, id.DeletedAccountName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Deleted Account ID +func (id DeletedAccountId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticLocations", "locations", "locations"), + resourceids.UserSpecifiedSegment("locationName", "locationValue"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticDeletedAccounts", "deletedAccounts", "deletedAccounts"), + resourceids.UserSpecifiedSegment("deletedAccountName", "deletedAccountValue"), + } +} + +// String returns a human-readable description of this Deleted Account ID +func (id DeletedAccountId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Location Name: %q", id.LocationName), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Deleted Account Name: %q", id.DeletedAccountName), + } + return fmt.Sprintf("Deleted Account (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_deletedaccount_test.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_deletedaccount_test.go new file mode 100644 index 00000000000..387cb9908ee --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_deletedaccount_test.go @@ -0,0 +1,327 @@ +package cognitiveservicesaccounts + +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 = &DeletedAccountId{} + +func TestNewDeletedAccountID(t *testing.T) { + id := NewDeletedAccountID("12345678-1234-9876-4563-123456789012", "locationValue", "example-resource-group", "deletedAccountValue") + + 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") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.DeletedAccountName != "deletedAccountValue" { + t.Fatalf("Expected %q but got %q for Segment 'DeletedAccountName'", id.DeletedAccountName, "deletedAccountValue") + } +} + +func TestFormatDeletedAccountID(t *testing.T) { + actual := NewDeletedAccountID("12345678-1234-9876-4563-123456789012", "locationValue", "example-resource-group", "deletedAccountValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations/locationValue/resourceGroups/example-resource-group/deletedAccounts/deletedAccountValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeletedAccountID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedAccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations/locationValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations/locationValue/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations/locationValue/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations/locationValue/resourceGroups/example-resource-group/deletedAccounts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations/locationValue/resourceGroups/example-resource-group/deletedAccounts/deletedAccountValue", + Expected: &DeletedAccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + ResourceGroupName: "example-resource-group", + DeletedAccountName: "deletedAccountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations/locationValue/resourceGroups/example-resource-group/deletedAccounts/deletedAccountValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedAccountID(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) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DeletedAccountName != v.Expected.DeletedAccountName { + t.Fatalf("Expected %q but got %q for DeletedAccountName", v.Expected.DeletedAccountName, actual.DeletedAccountName) + } + + } +} + +func TestParseDeletedAccountIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeletedAccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/lOcAtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations/locationValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/lOcAtIoNs/lOcAtIoNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations/locationValue/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/lOcAtIoNs/lOcAtIoNvAlUe/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations/locationValue/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/lOcAtIoNs/lOcAtIoNvAlUe/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations/locationValue/resourceGroups/example-resource-group/deletedAccounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/lOcAtIoNs/lOcAtIoNvAlUe/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dElEtEdAcCoUnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations/locationValue/resourceGroups/example-resource-group/deletedAccounts/deletedAccountValue", + Expected: &DeletedAccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "locationValue", + ResourceGroupName: "example-resource-group", + DeletedAccountName: "deletedAccountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations/locationValue/resourceGroups/example-resource-group/deletedAccounts/deletedAccountValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/lOcAtIoNs/lOcAtIoNvAlUe/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dElEtEdAcCoUnTs/dElEtEdAcCoUnTvAlUe", + Expected: &DeletedAccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + LocationName: "lOcAtIoNvAlUe", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + DeletedAccountName: "dElEtEdAcCoUnTvAlUe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/lOcAtIoNs/lOcAtIoNvAlUe/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/dElEtEdAcCoUnTs/dElEtEdAcCoUnTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeletedAccountIDInsensitively(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) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.DeletedAccountName != v.Expected.DeletedAccountName { + t.Fatalf("Expected %q but got %q for DeletedAccountName", v.Expected.DeletedAccountName, actual.DeletedAccountName) + } + + } +} + +func TestSegmentsForDeletedAccountId(t *testing.T) { + segments := DeletedAccountId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeletedAccountId 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/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_location.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_location.go new file mode 100644 index 00000000000..7e6e81e51e0 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_location.go @@ -0,0 +1,116 @@ +package cognitiveservicesaccounts + +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.CognitiveServices/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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + 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/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_location_test.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_location_test.go new file mode 100644 index 00000000000..96367661f99 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/id_location_test.go @@ -0,0 +1,237 @@ +package cognitiveservicesaccounts + +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.CognitiveServices/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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/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.CognitiveServices/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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/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.CognitiveServices/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/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.cOgNiTiVeSeRvIcEs/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/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountscreate.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountscreate.go new file mode 100644 index 00000000000..ab8448db740 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountscreate.go @@ -0,0 +1,76 @@ +package cognitiveservicesaccounts + +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 AccountsCreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Account +} + +// AccountsCreate ... +func (c CognitiveServicesAccountsClient) AccountsCreate(ctx context.Context, id AccountId, input Account) (result AccountsCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + 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 +} + +// AccountsCreateThenPoll performs AccountsCreate then polls until it's completed +func (c CognitiveServicesAccountsClient) AccountsCreateThenPoll(ctx context.Context, id AccountId, input Account) error { + result, err := c.AccountsCreate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AccountsCreate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccountsCreate: %+v", err) + } + + return nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsdelete.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsdelete.go new file mode 100644 index 00000000000..8b625caab27 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsdelete.go @@ -0,0 +1,71 @@ +package cognitiveservicesaccounts + +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 AccountsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// AccountsDelete ... +func (c CognitiveServicesAccountsClient) AccountsDelete(ctx context.Context, id AccountId) (result AccountsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// AccountsDeleteThenPoll performs AccountsDelete then polls until it's completed +func (c CognitiveServicesAccountsClient) AccountsDeleteThenPoll(ctx context.Context, id AccountId) error { + result, err := c.AccountsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing AccountsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccountsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsget.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsget.go new file mode 100644 index 00000000000..c6a3eb2a3e8 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsget.go @@ -0,0 +1,54 @@ +package cognitiveservicesaccounts + +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 AccountsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Account +} + +// AccountsGet ... +func (c CognitiveServicesAccountsClient) AccountsGet(ctx context.Context, id AccountId) (result AccountsGetOperationResponse, 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 Account + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslist.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslist.go new file mode 100644 index 00000000000..2126d71bf70 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslist.go @@ -0,0 +1,92 @@ +package cognitiveservicesaccounts + +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 AccountsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Account +} + +type AccountsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Account +} + +// AccountsList ... +func (c CognitiveServicesAccountsClient) AccountsList(ctx context.Context, id commonids.SubscriptionId) (result AccountsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.CognitiveServices/accounts", 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 *[]Account `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AccountsListComplete retrieves all the results into a single object +func (c CognitiveServicesAccountsClient) AccountsListComplete(ctx context.Context, id commonids.SubscriptionId) (AccountsListCompleteResult, error) { + return c.AccountsListCompleteMatchingPredicate(ctx, id, AccountOperationPredicate{}) +} + +// AccountsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CognitiveServicesAccountsClient) AccountsListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate AccountOperationPredicate) (result AccountsListCompleteResult, err error) { + items := make([]Account, 0) + + resp, err := c.AccountsList(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 = AccountsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistbyresourcegroup.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistbyresourcegroup.go new file mode 100644 index 00000000000..a45944cfe01 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistbyresourcegroup.go @@ -0,0 +1,92 @@ +package cognitiveservicesaccounts + +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 AccountsListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Account +} + +type AccountsListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Account +} + +// AccountsListByResourceGroup ... +func (c CognitiveServicesAccountsClient) AccountsListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result AccountsListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.CognitiveServices/accounts", 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 *[]Account `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AccountsListByResourceGroupComplete retrieves all the results into a single object +func (c CognitiveServicesAccountsClient) AccountsListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (AccountsListByResourceGroupCompleteResult, error) { + return c.AccountsListByResourceGroupCompleteMatchingPredicate(ctx, id, AccountOperationPredicate{}) +} + +// AccountsListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CognitiveServicesAccountsClient) AccountsListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate AccountOperationPredicate) (result AccountsListByResourceGroupCompleteResult, err error) { + items := make([]Account, 0) + + resp, err := c.AccountsListByResourceGroup(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 = AccountsListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistkeys.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistkeys.go new file mode 100644 index 00000000000..3e59222efbf --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistkeys.go @@ -0,0 +1,55 @@ +package cognitiveservicesaccounts + +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 AccountsListKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiKeys +} + +// AccountsListKeys ... +func (c CognitiveServicesAccountsClient) AccountsListKeys(ctx context.Context, id AccountId) (result AccountsListKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/listKeys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ApiKeys + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistmodels.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistmodels.go new file mode 100644 index 00000000000..0bcf11cee2e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistmodels.go @@ -0,0 +1,91 @@ +package cognitiveservicesaccounts + +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 AccountsListModelsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AccountModel +} + +type AccountsListModelsCompleteResult struct { + LatestHttpResponse *http.Response + Items []AccountModel +} + +// AccountsListModels ... +func (c CognitiveServicesAccountsClient) AccountsListModels(ctx context.Context, id AccountId) (result AccountsListModelsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/models", 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 *[]AccountModel `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AccountsListModelsComplete retrieves all the results into a single object +func (c CognitiveServicesAccountsClient) AccountsListModelsComplete(ctx context.Context, id AccountId) (AccountsListModelsCompleteResult, error) { + return c.AccountsListModelsCompleteMatchingPredicate(ctx, id, AccountModelOperationPredicate{}) +} + +// AccountsListModelsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CognitiveServicesAccountsClient) AccountsListModelsCompleteMatchingPredicate(ctx context.Context, id AccountId, predicate AccountModelOperationPredicate) (result AccountsListModelsCompleteResult, err error) { + items := make([]AccountModel, 0) + + resp, err := c.AccountsListModels(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 = AccountsListModelsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistskus.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistskus.go new file mode 100644 index 00000000000..d6ff403fa1e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistskus.go @@ -0,0 +1,55 @@ +package cognitiveservicesaccounts + +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 AccountsListSkusOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AccountSkuListResult +} + +// AccountsListSkus ... +func (c CognitiveServicesAccountsClient) AccountsListSkus(ctx context.Context, id AccountId) (result AccountsListSkusOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/skus", 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 AccountSkuListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistusages.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistusages.go new file mode 100644 index 00000000000..5d5f5fad7ae --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountslistusages.go @@ -0,0 +1,119 @@ +package cognitiveservicesaccounts + +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 AccountsListUsagesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Usage +} + +type AccountsListUsagesCompleteResult struct { + LatestHttpResponse *http.Response + Items []Usage +} + +type AccountsListUsagesOperationOptions struct { + Filter *string +} + +func DefaultAccountsListUsagesOperationOptions() AccountsListUsagesOperationOptions { + return AccountsListUsagesOperationOptions{} +} + +func (o AccountsListUsagesOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o AccountsListUsagesOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o AccountsListUsagesOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// AccountsListUsages ... +func (c CognitiveServicesAccountsClient) AccountsListUsages(ctx context.Context, id AccountId, options AccountsListUsagesOperationOptions) (result AccountsListUsagesOperationResponse, 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()), + 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 *[]Usage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// AccountsListUsagesComplete retrieves all the results into a single object +func (c CognitiveServicesAccountsClient) AccountsListUsagesComplete(ctx context.Context, id AccountId, options AccountsListUsagesOperationOptions) (AccountsListUsagesCompleteResult, error) { + return c.AccountsListUsagesCompleteMatchingPredicate(ctx, id, options, UsageOperationPredicate{}) +} + +// AccountsListUsagesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CognitiveServicesAccountsClient) AccountsListUsagesCompleteMatchingPredicate(ctx context.Context, id AccountId, options AccountsListUsagesOperationOptions, predicate UsageOperationPredicate) (result AccountsListUsagesCompleteResult, err error) { + items := make([]Usage, 0) + + resp, err := c.AccountsListUsages(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 = AccountsListUsagesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsregeneratekey.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsregeneratekey.go new file mode 100644 index 00000000000..80ab81ec7a8 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsregeneratekey.go @@ -0,0 +1,59 @@ +package cognitiveservicesaccounts + +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 AccountsRegenerateKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ApiKeys +} + +// AccountsRegenerateKey ... +func (c CognitiveServicesAccountsClient) AccountsRegenerateKey(ctx context.Context, id AccountId, input RegenerateKeyParameters) (result AccountsRegenerateKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/regenerateKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model ApiKeys + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsupdate.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsupdate.go new file mode 100644 index 00000000000..745a8c0dd07 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_accountsupdate.go @@ -0,0 +1,75 @@ +package cognitiveservicesaccounts + +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 AccountsUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Account +} + +// AccountsUpdate ... +func (c CognitiveServicesAccountsClient) AccountsUpdate(ctx context.Context, id AccountId, input Account) (result AccountsUpdateOperationResponse, 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 +} + +// AccountsUpdateThenPoll performs AccountsUpdate then polls until it's completed +func (c CognitiveServicesAccountsClient) AccountsUpdateThenPoll(ctx context.Context, id AccountId, input Account) error { + result, err := c.AccountsUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing AccountsUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after AccountsUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_checkdomainavailability.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_checkdomainavailability.go new file mode 100644 index 00000000000..a116ebb69af --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_checkdomainavailability.go @@ -0,0 +1,60 @@ +package cognitiveservicesaccounts + +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 CheckDomainAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DomainAvailability +} + +// CheckDomainAvailability ... +func (c CognitiveServicesAccountsClient) CheckDomainAvailability(ctx context.Context, id commonids.SubscriptionId, input CheckDomainAvailabilityParameter) (result CheckDomainAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CognitiveServices/checkDomainAvailability", 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 DomainAvailability + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_checkskuavailability.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_checkskuavailability.go new file mode 100644 index 00000000000..17b1e327996 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_checkskuavailability.go @@ -0,0 +1,59 @@ +package cognitiveservicesaccounts + +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 CheckSkuAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SkuAvailabilityListResult +} + +// CheckSkuAvailability ... +func (c CognitiveServicesAccountsClient) CheckSkuAvailability(ctx context.Context, id LocationId, input CheckSkuAvailabilityParameter) (result CheckSkuAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/checkSkuAvailability", 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 SkuAvailabilityListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_deletedaccountsget.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_deletedaccountsget.go new file mode 100644 index 00000000000..5518f33375d --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_deletedaccountsget.go @@ -0,0 +1,54 @@ +package cognitiveservicesaccounts + +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 DeletedAccountsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Account +} + +// DeletedAccountsGet ... +func (c CognitiveServicesAccountsClient) DeletedAccountsGet(ctx context.Context, id DeletedAccountId) (result DeletedAccountsGetOperationResponse, 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 Account + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_deletedaccountslist.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_deletedaccountslist.go new file mode 100644 index 00000000000..de3c6d7807b --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_deletedaccountslist.go @@ -0,0 +1,92 @@ +package cognitiveservicesaccounts + +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 DeletedAccountsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Account +} + +type DeletedAccountsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Account +} + +// DeletedAccountsList ... +func (c CognitiveServicesAccountsClient) DeletedAccountsList(ctx context.Context, id commonids.SubscriptionId) (result DeletedAccountsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.CognitiveServices/deletedAccounts", 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 *[]Account `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// DeletedAccountsListComplete retrieves all the results into a single object +func (c CognitiveServicesAccountsClient) DeletedAccountsListComplete(ctx context.Context, id commonids.SubscriptionId) (DeletedAccountsListCompleteResult, error) { + return c.DeletedAccountsListCompleteMatchingPredicate(ctx, id, AccountOperationPredicate{}) +} + +// DeletedAccountsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CognitiveServicesAccountsClient) DeletedAccountsListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate AccountOperationPredicate) (result DeletedAccountsListCompleteResult, err error) { + items := make([]Account, 0) + + resp, err := c.DeletedAccountsList(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 = DeletedAccountsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_deletedaccountspurge.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_deletedaccountspurge.go new file mode 100644 index 00000000000..fe36c4c4f37 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_deletedaccountspurge.go @@ -0,0 +1,71 @@ +package cognitiveservicesaccounts + +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 DeletedAccountsPurgeOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DeletedAccountsPurge ... +func (c CognitiveServicesAccountsClient) DeletedAccountsPurge(ctx context.Context, id DeletedAccountId) (result DeletedAccountsPurgeOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeletedAccountsPurgeThenPoll performs DeletedAccountsPurge then polls until it's completed +func (c CognitiveServicesAccountsClient) DeletedAccountsPurgeThenPoll(ctx context.Context, id DeletedAccountId) error { + result, err := c.DeletedAccountsPurge(ctx, id) + if err != nil { + return fmt.Errorf("performing DeletedAccountsPurge: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DeletedAccountsPurge: %+v", err) + } + + return nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_resourceskuslist.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_resourceskuslist.go new file mode 100644 index 00000000000..4a1fe3bcead --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/method_resourceskuslist.go @@ -0,0 +1,92 @@ +package cognitiveservicesaccounts + +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 ResourceSkusListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceSku +} + +type ResourceSkusListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceSku +} + +// ResourceSkusList ... +func (c CognitiveServicesAccountsClient) ResourceSkusList(ctx context.Context, id commonids.SubscriptionId) (result ResourceSkusListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.CognitiveServices/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 *[]ResourceSku `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ResourceSkusListComplete retrieves all the results into a single object +func (c CognitiveServicesAccountsClient) ResourceSkusListComplete(ctx context.Context, id commonids.SubscriptionId) (ResourceSkusListCompleteResult, error) { + return c.ResourceSkusListCompleteMatchingPredicate(ctx, id, ResourceSkuOperationPredicate{}) +} + +// ResourceSkusListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CognitiveServicesAccountsClient) ResourceSkusListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ResourceSkuOperationPredicate) (result ResourceSkusListCompleteResult, err error) { + items := make([]ResourceSku, 0) + + resp, err := c.ResourceSkusList(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 = ResourceSkusListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_abusepenalty.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_abusepenalty.go new file mode 100644 index 00000000000..ce2bd33b05f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_abusepenalty.go @@ -0,0 +1,28 @@ +package cognitiveservicesaccounts + +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 AbusePenalty struct { + Action *AbusePenaltyAction `json:"action,omitempty"` + Expiration *string `json:"expiration,omitempty"` + RateLimitPercentage *float64 `json:"rateLimitPercentage,omitempty"` +} + +func (o *AbusePenalty) GetExpirationAsTime() (*time.Time, error) { + if o.Expiration == nil { + return nil, nil + } + return dates.ParseAsFormat(o.Expiration, "2006-01-02T15:04:05Z07:00") +} + +func (o *AbusePenalty) SetExpirationAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.Expiration = &formatted +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_account.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_account.go new file mode 100644 index 00000000000..d36d155cc48 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_account.go @@ -0,0 +1,23 @@ +package cognitiveservicesaccounts + +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 Account struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *AccountProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountmodel.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountmodel.go new file mode 100644 index 00000000000..45438b90dda --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountmodel.go @@ -0,0 +1,25 @@ +package cognitiveservicesaccounts + +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 AccountModel struct { + BaseModel *DeploymentModel `json:"baseModel,omitempty"` + CallRateLimit *CallRateLimit `json:"callRateLimit,omitempty"` + Capabilities *map[string]string `json:"capabilities,omitempty"` + Deprecation *ModelDeprecationInfo `json:"deprecation,omitempty"` + FinetuneCapabilities *map[string]string `json:"finetuneCapabilities,omitempty"` + Format *string `json:"format,omitempty"` + IsDefaultVersion *bool `json:"isDefaultVersion,omitempty"` + LifecycleStatus *ModelLifecycleStatus `json:"lifecycleStatus,omitempty"` + MaxCapacity *int64 `json:"maxCapacity,omitempty"` + Name *string `json:"name,omitempty"` + Skus *[]ModelSku `json:"skus,omitempty"` + Source *string `json:"source,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountproperties.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountproperties.go new file mode 100644 index 00000000000..3da97b0febb --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountproperties.go @@ -0,0 +1,36 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccountProperties struct { + AbusePenalty *AbusePenalty `json:"abusePenalty,omitempty"` + AllowedFqdnList *[]string `json:"allowedFqdnList,omitempty"` + AmlWorkspace *UserOwnedAmlWorkspace `json:"amlWorkspace,omitempty"` + ApiProperties *ApiProperties `json:"apiProperties,omitempty"` + CallRateLimit *CallRateLimit `json:"callRateLimit,omitempty"` + Capabilities *[]SkuCapability `json:"capabilities,omitempty"` + CommitmentPlanAssociations *[]CommitmentPlanAssociation `json:"commitmentPlanAssociations,omitempty"` + CustomSubDomainName *string `json:"customSubDomainName,omitempty"` + DateCreated *string `json:"dateCreated,omitempty"` + DeletionDate *string `json:"deletionDate,omitempty"` + DisableLocalAuth *bool `json:"disableLocalAuth,omitempty"` + DynamicThrottlingEnabled *bool `json:"dynamicThrottlingEnabled,omitempty"` + Encryption *Encryption `json:"encryption,omitempty"` + Endpoint *string `json:"endpoint,omitempty"` + Endpoints *map[string]string `json:"endpoints,omitempty"` + InternalId *string `json:"internalId,omitempty"` + IsMigrated *bool `json:"isMigrated,omitempty"` + Locations *MultiRegionSettings `json:"locations,omitempty"` + MigrationToken *string `json:"migrationToken,omitempty"` + NetworkAcls *NetworkRuleSet `json:"networkAcls,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + QuotaLimit *QuotaLimit `json:"quotaLimit,omitempty"` + Restore *bool `json:"restore,omitempty"` + RestrictOutboundNetworkAccess *bool `json:"restrictOutboundNetworkAccess,omitempty"` + ScheduledPurgeDate *string `json:"scheduledPurgeDate,omitempty"` + SkuChangeInfo *SkuChangeInfo `json:"skuChangeInfo,omitempty"` + UserOwnedStorage *[]UserOwnedStorage `json:"userOwnedStorage,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountsku.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountsku.go new file mode 100644 index 00000000000..5f0de7f2e8e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountsku.go @@ -0,0 +1,9 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccountSku struct { + ResourceType *string `json:"resourceType,omitempty"` + Sku *Sku `json:"sku,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountskulistresult.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountskulistresult.go new file mode 100644 index 00000000000..736a0040367 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_accountskulistresult.go @@ -0,0 +1,8 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccountSkuListResult struct { + Value *[]AccountSku `json:"value,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_apikeys.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_apikeys.go new file mode 100644 index 00000000000..3c540b9caf5 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_apikeys.go @@ -0,0 +1,9 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiKeys struct { + Key1 *string `json:"key1,omitempty"` + Key2 *string `json:"key2,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_apiproperties.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_apiproperties.go new file mode 100644 index 00000000000..46adaffcada --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_apiproperties.go @@ -0,0 +1,17 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiProperties struct { + AadClientId *string `json:"aadClientId,omitempty"` + AadTenantId *string `json:"aadTenantId,omitempty"` + EventHubConnectionString *string `json:"eventHubConnectionString,omitempty"` + QnaAzureSearchEndpointId *string `json:"qnaAzureSearchEndpointId,omitempty"` + QnaAzureSearchEndpointKey *string `json:"qnaAzureSearchEndpointKey,omitempty"` + QnaRuntimeEndpoint *string `json:"qnaRuntimeEndpoint,omitempty"` + StatisticsEnabled *bool `json:"statisticsEnabled,omitempty"` + StorageAccountConnectionString *string `json:"storageAccountConnectionString,omitempty"` + SuperUser *string `json:"superUser,omitempty"` + WebsiteName *string `json:"websiteName,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_callratelimit.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_callratelimit.go new file mode 100644 index 00000000000..f416a9a4aa1 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_callratelimit.go @@ -0,0 +1,10 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CallRateLimit struct { + Count *float64 `json:"count,omitempty"` + RenewalPeriod *float64 `json:"renewalPeriod,omitempty"` + Rules *[]ThrottlingRule `json:"rules,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_capacityconfig.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_capacityconfig.go new file mode 100644 index 00000000000..aab7af4c33b --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_capacityconfig.go @@ -0,0 +1,12 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CapacityConfig struct { + AllowedValues *[]int64 `json:"allowedValues,omitempty"` + Default *int64 `json:"default,omitempty"` + Maximum *int64 `json:"maximum,omitempty"` + Minimum *int64 `json:"minimum,omitempty"` + Step *int64 `json:"step,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_checkdomainavailabilityparameter.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_checkdomainavailabilityparameter.go new file mode 100644 index 00000000000..0e1e9294241 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_checkdomainavailabilityparameter.go @@ -0,0 +1,10 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckDomainAvailabilityParameter struct { + Kind *string `json:"kind,omitempty"` + SubdomainName string `json:"subdomainName"` + Type string `json:"type"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_checkskuavailabilityparameter.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_checkskuavailabilityparameter.go new file mode 100644 index 00000000000..fe1aa94cc62 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_checkskuavailabilityparameter.go @@ -0,0 +1,10 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckSkuAvailabilityParameter struct { + Kind string `json:"kind"` + Skus []string `json:"skus"` + Type string `json:"type"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_commitmentplanassociation.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_commitmentplanassociation.go new file mode 100644 index 00000000000..5fdd840e21f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_commitmentplanassociation.go @@ -0,0 +1,9 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentPlanAssociation struct { + CommitmentPlanId *string `json:"commitmentPlanId,omitempty"` + CommitmentPlanLocation *string `json:"commitmentPlanLocation,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_deploymentmodel.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_deploymentmodel.go new file mode 100644 index 00000000000..6d21121cc19 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_deploymentmodel.go @@ -0,0 +1,12 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentModel struct { + CallRateLimit *CallRateLimit `json:"callRateLimit,omitempty"` + Format *string `json:"format,omitempty"` + Name *string `json:"name,omitempty"` + Source *string `json:"source,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_domainavailability.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_domainavailability.go new file mode 100644 index 00000000000..2e36d46eef5 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_domainavailability.go @@ -0,0 +1,12 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DomainAvailability struct { + IsSubdomainAvailable *bool `json:"isSubdomainAvailable,omitempty"` + Kind *string `json:"kind,omitempty"` + Reason *string `json:"reason,omitempty"` + SubdomainName *string `json:"subdomainName,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_encryption.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_encryption.go new file mode 100644 index 00000000000..be8e6b3d76f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_encryption.go @@ -0,0 +1,9 @@ +package cognitiveservicesaccounts + +// 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 { + KeySource *KeySource `json:"keySource,omitempty"` + KeyVaultProperties *KeyVaultProperties `json:"keyVaultProperties,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_iprule.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_iprule.go new file mode 100644 index 00000000000..1ef646c4c32 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_iprule.go @@ -0,0 +1,8 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPRule struct { + Value string `json:"value"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_keyvaultproperties.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_keyvaultproperties.go new file mode 100644 index 00000000000..2a522a3491d --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_keyvaultproperties.go @@ -0,0 +1,11 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultProperties struct { + IdentityClientId *string `json:"identityClientId,omitempty"` + KeyName *string `json:"keyName,omitempty"` + KeyVaultUri *string `json:"keyVaultUri,omitempty"` + KeyVersion *string `json:"keyVersion,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_metricname.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_metricname.go new file mode 100644 index 00000000000..696622a04da --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_metricname.go @@ -0,0 +1,9 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetricName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_modeldeprecationinfo.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_modeldeprecationinfo.go new file mode 100644 index 00000000000..f1a7e60596c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_modeldeprecationinfo.go @@ -0,0 +1,9 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ModelDeprecationInfo struct { + FineTune *string `json:"fineTune,omitempty"` + Inference *string `json:"inference,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_modelsku.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_modelsku.go new file mode 100644 index 00000000000..4905fd21d36 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_modelsku.go @@ -0,0 +1,30 @@ +package cognitiveservicesaccounts + +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 ModelSku struct { + Capacity *CapacityConfig `json:"capacity,omitempty"` + DeprecationDate *string `json:"deprecationDate,omitempty"` + Name *string `json:"name,omitempty"` + RateLimits *[]CallRateLimit `json:"rateLimits,omitempty"` + UsageName *string `json:"usageName,omitempty"` +} + +func (o *ModelSku) GetDeprecationDateAsTime() (*time.Time, error) { + if o.DeprecationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeprecationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ModelSku) SetDeprecationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeprecationDate = &formatted +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_multiregionsettings.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_multiregionsettings.go new file mode 100644 index 00000000000..3902cf093ae --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_multiregionsettings.go @@ -0,0 +1,9 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MultiRegionSettings struct { + Regions *[]RegionSetting `json:"regions,omitempty"` + RoutingMethod *RoutingMethods `json:"routingMethod,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_networkruleset.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_networkruleset.go new file mode 100644 index 00000000000..37f976f1c64 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_networkruleset.go @@ -0,0 +1,11 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NetworkRuleSet struct { + Bypass *ByPassSelection `json:"bypass,omitempty"` + DefaultAction *NetworkRuleAction `json:"defaultAction,omitempty"` + IPRules *[]IPRule `json:"ipRules,omitempty"` + VirtualNetworkRules *[]VirtualNetworkRule `json:"virtualNetworkRules,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privateendpoint.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privateendpoint.go new file mode 100644 index 00000000000..88ea8600bda --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privateendpoint.go @@ -0,0 +1,8 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privateendpointconnection.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privateendpointconnection.go new file mode 100644 index 00000000000..4e0eaa5a7ac --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privateendpointconnection.go @@ -0,0 +1,18 @@ +package cognitiveservicesaccounts + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privateendpointconnectionproperties.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..054f5e47091 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privatelinkserviceconnectionstate.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..19c6d65788e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_quotalimit.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_quotalimit.go new file mode 100644 index 00000000000..6fae5444a8d --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_quotalimit.go @@ -0,0 +1,10 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type QuotaLimit struct { + Count *float64 `json:"count,omitempty"` + RenewalPeriod *float64 `json:"renewalPeriod,omitempty"` + Rules *[]ThrottlingRule `json:"rules,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_regeneratekeyparameters.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_regeneratekeyparameters.go new file mode 100644 index 00000000000..c20914faab8 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_regeneratekeyparameters.go @@ -0,0 +1,8 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegenerateKeyParameters struct { + KeyName KeyName `json:"keyName"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_regionsetting.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_regionsetting.go new file mode 100644 index 00000000000..c7ec91042be --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_regionsetting.go @@ -0,0 +1,10 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegionSetting struct { + Customsubdomain *string `json:"customsubdomain,omitempty"` + Name *string `json:"name,omitempty"` + Value *float64 `json:"value,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_requestmatchpattern.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_requestmatchpattern.go new file mode 100644 index 00000000000..fb82270622e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_requestmatchpattern.go @@ -0,0 +1,9 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestMatchPattern struct { + Method *string `json:"method,omitempty"` + Path *string `json:"path,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_resourcesku.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_resourcesku.go new file mode 100644 index 00000000000..ffc5eccc031 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_resourcesku.go @@ -0,0 +1,13 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSku struct { + Kind *string `json:"kind,omitempty"` + Locations *[]string `json:"locations,omitempty"` + Name *string `json:"name,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Restrictions *[]ResourceSkuRestrictions `json:"restrictions,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_resourceskurestrictioninfo.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_resourceskurestrictioninfo.go new file mode 100644 index 00000000000..5f701af1d89 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_resourceskurestrictioninfo.go @@ -0,0 +1,13 @@ +package cognitiveservicesaccounts + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSkuRestrictionInfo struct { + Locations *[]string `json:"locations,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_resourceskurestrictions.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_resourceskurestrictions.go new file mode 100644 index 00000000000..2a91cfcc616 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_resourceskurestrictions.go @@ -0,0 +1,11 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSkuRestrictions struct { + ReasonCode *ResourceSkuRestrictionsReasonCode `json:"reasonCode,omitempty"` + RestrictionInfo *ResourceSkuRestrictionInfo `json:"restrictionInfo,omitempty"` + Type *ResourceSkuRestrictionsType `json:"type,omitempty"` + Values *[]string `json:"values,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_sku.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_sku.go new file mode 100644 index 00000000000..50eecc8d5ff --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_sku.go @@ -0,0 +1,12 @@ +package cognitiveservicesaccounts + +// 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/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skuavailability.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skuavailability.go new file mode 100644 index 00000000000..713f3e5841d --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skuavailability.go @@ -0,0 +1,13 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuAvailability struct { + Kind *string `json:"kind,omitempty"` + Message *string `json:"message,omitempty"` + Reason *string `json:"reason,omitempty"` + SkuAvailable *bool `json:"skuAvailable,omitempty"` + SkuName *string `json:"skuName,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skuavailabilitylistresult.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skuavailabilitylistresult.go new file mode 100644 index 00000000000..843010ce915 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skuavailabilitylistresult.go @@ -0,0 +1,8 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuAvailabilityListResult struct { + Value *[]SkuAvailability `json:"value,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skucapability.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skucapability.go new file mode 100644 index 00000000000..2508d7ebfbe --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skucapability.go @@ -0,0 +1,9 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuCapability struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skuchangeinfo.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skuchangeinfo.go new file mode 100644 index 00000000000..b3c6dec1620 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_skuchangeinfo.go @@ -0,0 +1,10 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuChangeInfo struct { + CountOfDowngrades *float64 `json:"countOfDowngrades,omitempty"` + CountOfUpgradesAfterDowngrades *float64 `json:"countOfUpgradesAfterDowngrades,omitempty"` + LastChangeDate *string `json:"lastChangeDate,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_throttlingrule.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_throttlingrule.go new file mode 100644 index 00000000000..35f94c2df40 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_throttlingrule.go @@ -0,0 +1,13 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThrottlingRule struct { + Count *float64 `json:"count,omitempty"` + DynamicThrottlingEnabled *bool `json:"dynamicThrottlingEnabled,omitempty"` + Key *string `json:"key,omitempty"` + MatchPatterns *[]RequestMatchPattern `json:"matchPatterns,omitempty"` + MinCount *float64 `json:"minCount,omitempty"` + RenewalPeriod *float64 `json:"renewalPeriod,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_usage.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_usage.go new file mode 100644 index 00000000000..37438a1a01c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_usage.go @@ -0,0 +1,14 @@ +package cognitiveservicesaccounts + +// 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 *float64 `json:"currentValue,omitempty"` + Limit *float64 `json:"limit,omitempty"` + Name *MetricName `json:"name,omitempty"` + NextResetTime *string `json:"nextResetTime,omitempty"` + QuotaPeriod *string `json:"quotaPeriod,omitempty"` + Status *QuotaUsageStatus `json:"status,omitempty"` + Unit *UnitType `json:"unit,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_userownedamlworkspace.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_userownedamlworkspace.go new file mode 100644 index 00000000000..ab8a7ab7cfe --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_userownedamlworkspace.go @@ -0,0 +1,9 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserOwnedAmlWorkspace struct { + IdentityClientId *string `json:"identityClientId,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_userownedstorage.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_userownedstorage.go new file mode 100644 index 00000000000..1d3c95441a3 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_userownedstorage.go @@ -0,0 +1,9 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserOwnedStorage struct { + IdentityClientId *string `json:"identityClientId,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_virtualnetworkrule.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_virtualnetworkrule.go new file mode 100644 index 00000000000..8f5f36973a6 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/model_virtualnetworkrule.go @@ -0,0 +1,10 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkRule struct { + Id string `json:"id"` + IgnoreMissingVnetServiceEndpoint *bool `json:"ignoreMissingVnetServiceEndpoint,omitempty"` + State *string `json:"state,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/predicates.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/predicates.go new file mode 100644 index 00000000000..4711b3cb54f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/predicates.go @@ -0,0 +1,136 @@ +package cognitiveservicesaccounts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccountOperationPredicate struct { + Etag *string + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p AccountOperationPredicate) Matches(input Account) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + 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 +} + +type AccountModelOperationPredicate struct { + Format *string + IsDefaultVersion *bool + MaxCapacity *int64 + Name *string + Source *string + Version *string +} + +func (p AccountModelOperationPredicate) Matches(input AccountModel) bool { + + if p.Format != nil && (input.Format == nil || *p.Format != *input.Format) { + return false + } + + if p.IsDefaultVersion != nil && (input.IsDefaultVersion == nil || *p.IsDefaultVersion != *input.IsDefaultVersion) { + return false + } + + if p.MaxCapacity != nil && (input.MaxCapacity == nil || *p.MaxCapacity != *input.MaxCapacity) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Source != nil && (input.Source == nil || *p.Source != *input.Source) { + return false + } + + if p.Version != nil && (input.Version == nil || *p.Version != *input.Version) { + return false + } + + return true +} + +type ResourceSkuOperationPredicate struct { + Kind *string + Name *string + ResourceType *string + Tier *string +} + +func (p ResourceSkuOperationPredicate) Matches(input ResourceSku) bool { + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.ResourceType != nil && (input.ResourceType == nil || *p.ResourceType != *input.ResourceType) { + return false + } + + if p.Tier != nil && (input.Tier == nil || *p.Tier != *input.Tier) { + return false + } + + return true +} + +type UsageOperationPredicate struct { + CurrentValue *float64 + Limit *float64 + NextResetTime *string + QuotaPeriod *string +} + +func (p UsageOperationPredicate) Matches(input Usage) bool { + + if p.CurrentValue != nil && (input.CurrentValue == nil || *p.CurrentValue != *input.CurrentValue) { + return false + } + + if p.Limit != nil && (input.Limit == nil || *p.Limit != *input.Limit) { + return false + } + + if p.NextResetTime != nil && (input.NextResetTime == nil || *p.NextResetTime != *input.NextResetTime) { + return false + } + + if p.QuotaPeriod != nil && (input.QuotaPeriod == nil || *p.QuotaPeriod != *input.QuotaPeriod) { + return false + } + + return true +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/version.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/version.go new file mode 100644 index 00000000000..a3f76d93b91 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicesaccounts/version.go @@ -0,0 +1,12 @@ +package cognitiveservicesaccounts + +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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/cognitiveservicesaccounts/%s", defaultApiVersion) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/README.md b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/README.md new file mode 100644 index 00000000000..5e4cd089bbf --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans` Documentation + +The `cognitiveservicescommitmentplans` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans" +``` + + +### Client Initialization + +```go +client := cognitiveservicescommitmentplans.NewCognitiveServicesCommitmentPlansClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CognitiveServicesCommitmentPlansClient.CommitmentPlansCreateOrUpdatePlan` + +```go +ctx := context.TODO() +id := cognitiveservicescommitmentplans.NewCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue") + +payload := cognitiveservicescommitmentplans.CommitmentPlan{ + // ... +} + + +if err := client.CommitmentPlansCreateOrUpdatePlanThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `CognitiveServicesCommitmentPlansClient.CommitmentPlansDeletePlan` + +```go +ctx := context.TODO() +id := cognitiveservicescommitmentplans.NewCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue") + +if err := client.CommitmentPlansDeletePlanThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `CognitiveServicesCommitmentPlansClient.CommitmentPlansGetPlan` + +```go +ctx := context.TODO() +id := cognitiveservicescommitmentplans.NewCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue") + +read, err := client.CommitmentPlansGetPlan(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CognitiveServicesCommitmentPlansClient.CommitmentPlansListPlansByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.CommitmentPlansListPlansByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.CommitmentPlansListPlansByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CognitiveServicesCommitmentPlansClient.CommitmentPlansListPlansBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.CommitmentPlansListPlansBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.CommitmentPlansListPlansBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CognitiveServicesCommitmentPlansClient.CommitmentPlansUpdatePlan` + +```go +ctx := context.TODO() +id := cognitiveservicescommitmentplans.NewCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue") + +payload := cognitiveservicescommitmentplans.PatchResourceTagsAndSku{ + // ... +} + + +if err := client.CommitmentPlansUpdatePlanThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/client.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/client.go new file mode 100644 index 00000000000..d15b664b06f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/client.go @@ -0,0 +1,26 @@ +package cognitiveservicescommitmentplans + +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 CognitiveServicesCommitmentPlansClient struct { + Client *resourcemanager.Client +} + +func NewCognitiveServicesCommitmentPlansClientWithBaseURI(sdkApi sdkEnv.Api) (*CognitiveServicesCommitmentPlansClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "cognitiveservicescommitmentplans", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CognitiveServicesCommitmentPlansClient: %+v", err) + } + + return &CognitiveServicesCommitmentPlansClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/constants.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/constants.go new file mode 100644 index 00000000000..6ac5130231b --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/constants.go @@ -0,0 +1,163 @@ +package cognitiveservicescommitmentplans + +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 CommitmentPlanProvisioningState string + +const ( + CommitmentPlanProvisioningStateAccepted CommitmentPlanProvisioningState = "Accepted" + CommitmentPlanProvisioningStateCanceled CommitmentPlanProvisioningState = "Canceled" + CommitmentPlanProvisioningStateCreating CommitmentPlanProvisioningState = "Creating" + CommitmentPlanProvisioningStateDeleting CommitmentPlanProvisioningState = "Deleting" + CommitmentPlanProvisioningStateFailed CommitmentPlanProvisioningState = "Failed" + CommitmentPlanProvisioningStateMoving CommitmentPlanProvisioningState = "Moving" + CommitmentPlanProvisioningStateSucceeded CommitmentPlanProvisioningState = "Succeeded" +) + +func PossibleValuesForCommitmentPlanProvisioningState() []string { + return []string{ + string(CommitmentPlanProvisioningStateAccepted), + string(CommitmentPlanProvisioningStateCanceled), + string(CommitmentPlanProvisioningStateCreating), + string(CommitmentPlanProvisioningStateDeleting), + string(CommitmentPlanProvisioningStateFailed), + string(CommitmentPlanProvisioningStateMoving), + string(CommitmentPlanProvisioningStateSucceeded), + } +} + +func (s *CommitmentPlanProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCommitmentPlanProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCommitmentPlanProvisioningState(input string) (*CommitmentPlanProvisioningState, error) { + vals := map[string]CommitmentPlanProvisioningState{ + "accepted": CommitmentPlanProvisioningStateAccepted, + "canceled": CommitmentPlanProvisioningStateCanceled, + "creating": CommitmentPlanProvisioningStateCreating, + "deleting": CommitmentPlanProvisioningStateDeleting, + "failed": CommitmentPlanProvisioningStateFailed, + "moving": CommitmentPlanProvisioningStateMoving, + "succeeded": CommitmentPlanProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CommitmentPlanProvisioningState(input) + return &out, nil +} + +type HostingModel string + +const ( + HostingModelConnectedContainer HostingModel = "ConnectedContainer" + HostingModelDisconnectedContainer HostingModel = "DisconnectedContainer" + HostingModelProvisionedWeb HostingModel = "ProvisionedWeb" + HostingModelWeb HostingModel = "Web" +) + +func PossibleValuesForHostingModel() []string { + return []string{ + string(HostingModelConnectedContainer), + string(HostingModelDisconnectedContainer), + string(HostingModelProvisionedWeb), + string(HostingModelWeb), + } +} + +func (s *HostingModel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHostingModel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHostingModel(input string) (*HostingModel, error) { + vals := map[string]HostingModel{ + "connectedcontainer": HostingModelConnectedContainer, + "disconnectedcontainer": HostingModelDisconnectedContainer, + "provisionedweb": HostingModelProvisionedWeb, + "web": HostingModelWeb, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HostingModel(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierEnterprise SkuTier = "Enterprise" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierEnterprise), + 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, + "enterprise": SkuTierEnterprise, + "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/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/id_commitmentplan.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/id_commitmentplan.go new file mode 100644 index 00000000000..9a4c396e587 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/id_commitmentplan.go @@ -0,0 +1,125 @@ +package cognitiveservicescommitmentplans + +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 = &CommitmentPlanId{} + +// CommitmentPlanId is a struct representing the Resource ID for a Commitment Plan +type CommitmentPlanId struct { + SubscriptionId string + ResourceGroupName string + CommitmentPlanName string +} + +// NewCommitmentPlanID returns a new CommitmentPlanId struct +func NewCommitmentPlanID(subscriptionId string, resourceGroupName string, commitmentPlanName string) CommitmentPlanId { + return CommitmentPlanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + CommitmentPlanName: commitmentPlanName, + } +} + +// ParseCommitmentPlanID parses 'input' into a CommitmentPlanId +func ParseCommitmentPlanID(input string) (*CommitmentPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(&CommitmentPlanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CommitmentPlanId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCommitmentPlanIDInsensitively parses 'input' case-insensitively into a CommitmentPlanId +// note: this method should only be used for API response data and not user input +func ParseCommitmentPlanIDInsensitively(input string) (*CommitmentPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(&CommitmentPlanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CommitmentPlanId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CommitmentPlanId) 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.CommitmentPlanName, ok = input.Parsed["commitmentPlanName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "commitmentPlanName", input) + } + + return nil +} + +// ValidateCommitmentPlanID checks that 'input' can be parsed as a Commitment Plan ID +func ValidateCommitmentPlanID(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 := ParseCommitmentPlanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Commitment Plan ID +func (id CommitmentPlanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/commitmentPlans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.CommitmentPlanName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Commitment Plan ID +func (id CommitmentPlanId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticCommitmentPlans", "commitmentPlans", "commitmentPlans"), + resourceids.UserSpecifiedSegment("commitmentPlanName", "commitmentPlanValue"), + } +} + +// String returns a human-readable description of this Commitment Plan ID +func (id CommitmentPlanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Commitment Plan Name: %q", id.CommitmentPlanName), + } + return fmt.Sprintf("Commitment Plan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/id_commitmentplan_test.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/id_commitmentplan_test.go new file mode 100644 index 00000000000..f3e03f0cd59 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/id_commitmentplan_test.go @@ -0,0 +1,282 @@ +package cognitiveservicescommitmentplans + +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 = &CommitmentPlanId{} + +func TestNewCommitmentPlanID(t *testing.T) { + id := NewCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue") + + 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.CommitmentPlanName != "commitmentPlanValue" { + t.Fatalf("Expected %q but got %q for Segment 'CommitmentPlanName'", id.CommitmentPlanName, "commitmentPlanValue") + } +} + +func TestFormatCommitmentPlanID(t *testing.T) { + actual := NewCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCommitmentPlanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CommitmentPlanId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue", + Expected: &CommitmentPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + CommitmentPlanName: "commitmentPlanValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCommitmentPlanID(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.CommitmentPlanName != v.Expected.CommitmentPlanName { + t.Fatalf("Expected %q but got %q for CommitmentPlanName", v.Expected.CommitmentPlanName, actual.CommitmentPlanName) + } + + } +} + +func TestParseCommitmentPlanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CommitmentPlanId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/cOmMiTmEnTpLaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue", + Expected: &CommitmentPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + CommitmentPlanName: "commitmentPlanValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/cOmMiTmEnTpLaNs/cOmMiTmEnTpLaNvAlUe", + Expected: &CommitmentPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + CommitmentPlanName: "cOmMiTmEnTpLaNvAlUe", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/cOmMiTmEnTpLaNs/cOmMiTmEnTpLaNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCommitmentPlanIDInsensitively(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.CommitmentPlanName != v.Expected.CommitmentPlanName { + t.Fatalf("Expected %q but got %q for CommitmentPlanName", v.Expected.CommitmentPlanName, actual.CommitmentPlanName) + } + + } +} + +func TestSegmentsForCommitmentPlanId(t *testing.T) { + segments := CommitmentPlanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CommitmentPlanId 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/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplanscreateorupdateplan.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplanscreateorupdateplan.go new file mode 100644 index 00000000000..7e2e600efd7 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplanscreateorupdateplan.go @@ -0,0 +1,75 @@ +package cognitiveservicescommitmentplans + +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 CommitmentPlansCreateOrUpdatePlanOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CommitmentPlan +} + +// CommitmentPlansCreateOrUpdatePlan ... +func (c CognitiveServicesCommitmentPlansClient) CommitmentPlansCreateOrUpdatePlan(ctx context.Context, id CommitmentPlanId, input CommitmentPlan) (result CommitmentPlansCreateOrUpdatePlanOperationResponse, 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 +} + +// CommitmentPlansCreateOrUpdatePlanThenPoll performs CommitmentPlansCreateOrUpdatePlan then polls until it's completed +func (c CognitiveServicesCommitmentPlansClient) CommitmentPlansCreateOrUpdatePlanThenPoll(ctx context.Context, id CommitmentPlanId, input CommitmentPlan) error { + result, err := c.CommitmentPlansCreateOrUpdatePlan(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CommitmentPlansCreateOrUpdatePlan: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CommitmentPlansCreateOrUpdatePlan: %+v", err) + } + + return nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplansdeleteplan.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplansdeleteplan.go new file mode 100644 index 00000000000..1a5dec6e3a5 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplansdeleteplan.go @@ -0,0 +1,71 @@ +package cognitiveservicescommitmentplans + +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 CommitmentPlansDeletePlanOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// CommitmentPlansDeletePlan ... +func (c CognitiveServicesCommitmentPlansClient) CommitmentPlansDeletePlan(ctx context.Context, id CommitmentPlanId) (result CommitmentPlansDeletePlanOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CommitmentPlansDeletePlanThenPoll performs CommitmentPlansDeletePlan then polls until it's completed +func (c CognitiveServicesCommitmentPlansClient) CommitmentPlansDeletePlanThenPoll(ctx context.Context, id CommitmentPlanId) error { + result, err := c.CommitmentPlansDeletePlan(ctx, id) + if err != nil { + return fmt.Errorf("performing CommitmentPlansDeletePlan: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CommitmentPlansDeletePlan: %+v", err) + } + + return nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplansgetplan.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplansgetplan.go new file mode 100644 index 00000000000..e72a8b796bf --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplansgetplan.go @@ -0,0 +1,54 @@ +package cognitiveservicescommitmentplans + +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 CommitmentPlansGetPlanOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CommitmentPlan +} + +// CommitmentPlansGetPlan ... +func (c CognitiveServicesCommitmentPlansClient) CommitmentPlansGetPlan(ctx context.Context, id CommitmentPlanId) (result CommitmentPlansGetPlanOperationResponse, 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 CommitmentPlan + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplanslistplansbyresourcegroup.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplanslistplansbyresourcegroup.go new file mode 100644 index 00000000000..149d7ff654b --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplanslistplansbyresourcegroup.go @@ -0,0 +1,92 @@ +package cognitiveservicescommitmentplans + +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 CommitmentPlansListPlansByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CommitmentPlan +} + +type CommitmentPlansListPlansByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []CommitmentPlan +} + +// CommitmentPlansListPlansByResourceGroup ... +func (c CognitiveServicesCommitmentPlansClient) CommitmentPlansListPlansByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result CommitmentPlansListPlansByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.CognitiveServices/commitmentPlans", 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 *[]CommitmentPlan `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// CommitmentPlansListPlansByResourceGroupComplete retrieves all the results into a single object +func (c CognitiveServicesCommitmentPlansClient) CommitmentPlansListPlansByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (CommitmentPlansListPlansByResourceGroupCompleteResult, error) { + return c.CommitmentPlansListPlansByResourceGroupCompleteMatchingPredicate(ctx, id, CommitmentPlanOperationPredicate{}) +} + +// CommitmentPlansListPlansByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CognitiveServicesCommitmentPlansClient) CommitmentPlansListPlansByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate CommitmentPlanOperationPredicate) (result CommitmentPlansListPlansByResourceGroupCompleteResult, err error) { + items := make([]CommitmentPlan, 0) + + resp, err := c.CommitmentPlansListPlansByResourceGroup(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 = CommitmentPlansListPlansByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplanslistplansbysubscription.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplanslistplansbysubscription.go new file mode 100644 index 00000000000..f472fc1d19d --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplanslistplansbysubscription.go @@ -0,0 +1,92 @@ +package cognitiveservicescommitmentplans + +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 CommitmentPlansListPlansBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CommitmentPlan +} + +type CommitmentPlansListPlansBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []CommitmentPlan +} + +// CommitmentPlansListPlansBySubscription ... +func (c CognitiveServicesCommitmentPlansClient) CommitmentPlansListPlansBySubscription(ctx context.Context, id commonids.SubscriptionId) (result CommitmentPlansListPlansBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.CognitiveServices/commitmentPlans", 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 *[]CommitmentPlan `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// CommitmentPlansListPlansBySubscriptionComplete retrieves all the results into a single object +func (c CognitiveServicesCommitmentPlansClient) CommitmentPlansListPlansBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (CommitmentPlansListPlansBySubscriptionCompleteResult, error) { + return c.CommitmentPlansListPlansBySubscriptionCompleteMatchingPredicate(ctx, id, CommitmentPlanOperationPredicate{}) +} + +// CommitmentPlansListPlansBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CognitiveServicesCommitmentPlansClient) CommitmentPlansListPlansBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate CommitmentPlanOperationPredicate) (result CommitmentPlansListPlansBySubscriptionCompleteResult, err error) { + items := make([]CommitmentPlan, 0) + + resp, err := c.CommitmentPlansListPlansBySubscription(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 = CommitmentPlansListPlansBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplansupdateplan.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplansupdateplan.go new file mode 100644 index 00000000000..f70b9e57b9b --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/method_commitmentplansupdateplan.go @@ -0,0 +1,75 @@ +package cognitiveservicescommitmentplans + +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 CommitmentPlansUpdatePlanOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CommitmentPlan +} + +// CommitmentPlansUpdatePlan ... +func (c CognitiveServicesCommitmentPlansClient) CommitmentPlansUpdatePlan(ctx context.Context, id CommitmentPlanId, input PatchResourceTagsAndSku) (result CommitmentPlansUpdatePlanOperationResponse, 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 +} + +// CommitmentPlansUpdatePlanThenPoll performs CommitmentPlansUpdatePlan then polls until it's completed +func (c CognitiveServicesCommitmentPlansClient) CommitmentPlansUpdatePlanThenPoll(ctx context.Context, id CommitmentPlanId, input PatchResourceTagsAndSku) error { + result, err := c.CommitmentPlansUpdatePlan(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CommitmentPlansUpdatePlan: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CommitmentPlansUpdatePlan: %+v", err) + } + + return nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentperiod.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentperiod.go new file mode 100644 index 00000000000..e5a15dfa50a --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentperiod.go @@ -0,0 +1,12 @@ +package cognitiveservicescommitmentplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentPeriod struct { + Count *int64 `json:"count,omitempty"` + EndDate *string `json:"endDate,omitempty"` + Quota *CommitmentQuota `json:"quota,omitempty"` + StartDate *string `json:"startDate,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentplan.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentplan.go new file mode 100644 index 00000000000..7d2624b688e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentplan.go @@ -0,0 +1,21 @@ +package cognitiveservicescommitmentplans + +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 CommitmentPlan struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CommitmentPlanProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentplanproperties.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentplanproperties.go new file mode 100644 index 00000000000..3ae9cfe5669 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentplanproperties.go @@ -0,0 +1,16 @@ +package cognitiveservicescommitmentplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentPlanProperties struct { + AutoRenew *bool `json:"autoRenew,omitempty"` + CommitmentPlanGuid *string `json:"commitmentPlanGuid,omitempty"` + Current *CommitmentPeriod `json:"current,omitempty"` + HostingModel *HostingModel `json:"hostingModel,omitempty"` + Last *CommitmentPeriod `json:"last,omitempty"` + Next *CommitmentPeriod `json:"next,omitempty"` + PlanType *string `json:"planType,omitempty"` + ProvisioningIssues *[]string `json:"provisioningIssues,omitempty"` + ProvisioningState *CommitmentPlanProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentquota.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentquota.go new file mode 100644 index 00000000000..cf65e5559f7 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_commitmentquota.go @@ -0,0 +1,9 @@ +package cognitiveservicescommitmentplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentQuota struct { + Quantity *int64 `json:"quantity,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_patchresourcetagsandsku.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_patchresourcetagsandsku.go new file mode 100644 index 00000000000..da51601385c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_patchresourcetagsandsku.go @@ -0,0 +1,9 @@ +package cognitiveservicescommitmentplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchResourceTagsAndSku struct { + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_sku.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_sku.go new file mode 100644 index 00000000000..a8856f523f1 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/model_sku.go @@ -0,0 +1,12 @@ +package cognitiveservicescommitmentplans + +// 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/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/predicates.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/predicates.go new file mode 100644 index 00000000000..2a6f11835e4 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/predicates.go @@ -0,0 +1,42 @@ +package cognitiveservicescommitmentplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentPlanOperationPredicate struct { + Etag *string + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p CommitmentPlanOperationPredicate) Matches(input CommitmentPlan) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + 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/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/version.go b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/version.go new file mode 100644 index 00000000000..b38c3c699d4 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/cognitiveservicescommitmentplans/version.go @@ -0,0 +1,12 @@ +package cognitiveservicescommitmentplans + +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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/cognitiveservicescommitmentplans/%s", defaultApiVersion) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/README.md b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/README.md new file mode 100644 index 00000000000..e2075c022f1 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/README.md @@ -0,0 +1,148 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/commitmentplans` Documentation + +The `commitmentplans` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/commitmentplans" +``` + + +### Client Initialization + +```go +client := commitmentplans.NewCommitmentPlansClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CommitmentPlansClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := commitmentplans.NewAccountCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "commitmentPlanValue") + +payload := commitmentplans.CommitmentPlan{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CommitmentPlansClient.CreateOrUpdateAssociation` + +```go +ctx := context.TODO() +id := commitmentplans.NewAccountAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue", "accountAssociationValue") + +payload := commitmentplans.CommitmentPlanAccountAssociation{ + // ... +} + + +if err := client.CreateOrUpdateAssociationThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `CommitmentPlansClient.Delete` + +```go +ctx := context.TODO() +id := commitmentplans.NewAccountCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "commitmentPlanValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `CommitmentPlansClient.DeleteAssociation` + +```go +ctx := context.TODO() +id := commitmentplans.NewAccountAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue", "accountAssociationValue") + +if err := client.DeleteAssociationThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `CommitmentPlansClient.Get` + +```go +ctx := context.TODO() +id := commitmentplans.NewAccountCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "commitmentPlanValue") + +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: `CommitmentPlansClient.GetAssociation` + +```go +ctx := context.TODO() +id := commitmentplans.NewAccountAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue", "accountAssociationValue") + +read, err := client.GetAssociation(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CommitmentPlansClient.List` + +```go +ctx := context.TODO() +id := commitmentplans.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `CommitmentPlansClient.ListAssociations` + +```go +ctx := context.TODO() +id := commitmentplans.NewCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue") + +// alternatively `client.ListAssociations(ctx, id)` can be used to do batched pagination +items, err := client.ListAssociationsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/client.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/client.go new file mode 100644 index 00000000000..eccd5e46144 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/client.go @@ -0,0 +1,26 @@ +package commitmentplans + +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 CommitmentPlansClient struct { + Client *resourcemanager.Client +} + +func NewCommitmentPlansClientWithBaseURI(sdkApi sdkEnv.Api) (*CommitmentPlansClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "commitmentplans", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CommitmentPlansClient: %+v", err) + } + + return &CommitmentPlansClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/constants.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/constants.go new file mode 100644 index 00000000000..02f27832726 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/constants.go @@ -0,0 +1,163 @@ +package commitmentplans + +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 CommitmentPlanProvisioningState string + +const ( + CommitmentPlanProvisioningStateAccepted CommitmentPlanProvisioningState = "Accepted" + CommitmentPlanProvisioningStateCanceled CommitmentPlanProvisioningState = "Canceled" + CommitmentPlanProvisioningStateCreating CommitmentPlanProvisioningState = "Creating" + CommitmentPlanProvisioningStateDeleting CommitmentPlanProvisioningState = "Deleting" + CommitmentPlanProvisioningStateFailed CommitmentPlanProvisioningState = "Failed" + CommitmentPlanProvisioningStateMoving CommitmentPlanProvisioningState = "Moving" + CommitmentPlanProvisioningStateSucceeded CommitmentPlanProvisioningState = "Succeeded" +) + +func PossibleValuesForCommitmentPlanProvisioningState() []string { + return []string{ + string(CommitmentPlanProvisioningStateAccepted), + string(CommitmentPlanProvisioningStateCanceled), + string(CommitmentPlanProvisioningStateCreating), + string(CommitmentPlanProvisioningStateDeleting), + string(CommitmentPlanProvisioningStateFailed), + string(CommitmentPlanProvisioningStateMoving), + string(CommitmentPlanProvisioningStateSucceeded), + } +} + +func (s *CommitmentPlanProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCommitmentPlanProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCommitmentPlanProvisioningState(input string) (*CommitmentPlanProvisioningState, error) { + vals := map[string]CommitmentPlanProvisioningState{ + "accepted": CommitmentPlanProvisioningStateAccepted, + "canceled": CommitmentPlanProvisioningStateCanceled, + "creating": CommitmentPlanProvisioningStateCreating, + "deleting": CommitmentPlanProvisioningStateDeleting, + "failed": CommitmentPlanProvisioningStateFailed, + "moving": CommitmentPlanProvisioningStateMoving, + "succeeded": CommitmentPlanProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CommitmentPlanProvisioningState(input) + return &out, nil +} + +type HostingModel string + +const ( + HostingModelConnectedContainer HostingModel = "ConnectedContainer" + HostingModelDisconnectedContainer HostingModel = "DisconnectedContainer" + HostingModelProvisionedWeb HostingModel = "ProvisionedWeb" + HostingModelWeb HostingModel = "Web" +) + +func PossibleValuesForHostingModel() []string { + return []string{ + string(HostingModelConnectedContainer), + string(HostingModelDisconnectedContainer), + string(HostingModelProvisionedWeb), + string(HostingModelWeb), + } +} + +func (s *HostingModel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHostingModel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHostingModel(input string) (*HostingModel, error) { + vals := map[string]HostingModel{ + "connectedcontainer": HostingModelConnectedContainer, + "disconnectedcontainer": HostingModelDisconnectedContainer, + "provisionedweb": HostingModelProvisionedWeb, + "web": HostingModelWeb, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HostingModel(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierEnterprise SkuTier = "Enterprise" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierEnterprise), + 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, + "enterprise": SkuTierEnterprise, + "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/cognitive/2023-10-01-preview/commitmentplans/id_account.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_account.go new file mode 100644 index 00000000000..aacd722f59c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_account.go @@ -0,0 +1,125 @@ +package commitmentplans + +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 = &AccountId{} + +// AccountId is a struct representing the Resource ID for a Account +type AccountId struct { + SubscriptionId string + ResourceGroupName string + AccountName string +} + +// NewAccountID returns a new AccountId struct +func NewAccountID(subscriptionId string, resourceGroupName string, accountName string) AccountId { + return AccountId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + } +} + +// ParseAccountID parses 'input' into a AccountId +func ParseAccountID(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccountIDInsensitively parses 'input' case-insensitively into a AccountId +// note: this method should only be used for API response data and not user input +func ParseAccountIDInsensitively(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccountId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + return nil +} + +// ValidateAccountID checks that 'input' can be parsed as a Account ID +func ValidateAccountID(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 := ParseAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Account ID +func (id AccountId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Account ID +func (id AccountId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + } +} + +// String returns a human-readable description of this Account ID +func (id AccountId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + } + return fmt.Sprintf("Account (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_account_test.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_account_test.go new file mode 100644 index 00000000000..ac0c307b9ad --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_account_test.go @@ -0,0 +1,282 @@ +package commitmentplans + +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 = &AccountId{} + +func TestNewAccountID(t *testing.T) { + id := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } +} + +func TestFormatAccountID(t *testing.T) { + actual := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccountID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestParseAccountIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestSegmentsForAccountId(t *testing.T) { + segments := AccountId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccountId 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/cognitive/2023-10-01-preview/commitmentplans/id_accountassociation.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountassociation.go new file mode 100644 index 00000000000..be9cc4d54fd --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountassociation.go @@ -0,0 +1,134 @@ +package commitmentplans + +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 = &AccountAssociationId{} + +// AccountAssociationId is a struct representing the Resource ID for a Account Association +type AccountAssociationId struct { + SubscriptionId string + ResourceGroupName string + CommitmentPlanName string + AccountAssociationName string +} + +// NewAccountAssociationID returns a new AccountAssociationId struct +func NewAccountAssociationID(subscriptionId string, resourceGroupName string, commitmentPlanName string, accountAssociationName string) AccountAssociationId { + return AccountAssociationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + CommitmentPlanName: commitmentPlanName, + AccountAssociationName: accountAssociationName, + } +} + +// ParseAccountAssociationID parses 'input' into a AccountAssociationId +func ParseAccountAssociationID(input string) (*AccountAssociationId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountAssociationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountAssociationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccountAssociationIDInsensitively parses 'input' case-insensitively into a AccountAssociationId +// note: this method should only be used for API response data and not user input +func ParseAccountAssociationIDInsensitively(input string) (*AccountAssociationId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountAssociationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountAssociationId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccountAssociationId) 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.CommitmentPlanName, ok = input.Parsed["commitmentPlanName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "commitmentPlanName", input) + } + + if id.AccountAssociationName, ok = input.Parsed["accountAssociationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountAssociationName", input) + } + + return nil +} + +// ValidateAccountAssociationID checks that 'input' can be parsed as a Account Association ID +func ValidateAccountAssociationID(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 := ParseAccountAssociationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Account Association ID +func (id AccountAssociationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/commitmentPlans/%s/accountAssociations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.CommitmentPlanName, id.AccountAssociationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Account Association ID +func (id AccountAssociationId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticCommitmentPlans", "commitmentPlans", "commitmentPlans"), + resourceids.UserSpecifiedSegment("commitmentPlanName", "commitmentPlanValue"), + resourceids.StaticSegment("staticAccountAssociations", "accountAssociations", "accountAssociations"), + resourceids.UserSpecifiedSegment("accountAssociationName", "accountAssociationValue"), + } +} + +// String returns a human-readable description of this Account Association ID +func (id AccountAssociationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Commitment Plan Name: %q", id.CommitmentPlanName), + fmt.Sprintf("Account Association Name: %q", id.AccountAssociationName), + } + return fmt.Sprintf("Account Association (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountassociation_test.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountassociation_test.go new file mode 100644 index 00000000000..35a86d70c5e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountassociation_test.go @@ -0,0 +1,327 @@ +package commitmentplans + +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 = &AccountAssociationId{} + +func TestNewAccountAssociationID(t *testing.T) { + id := NewAccountAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue", "accountAssociationValue") + + 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.CommitmentPlanName != "commitmentPlanValue" { + t.Fatalf("Expected %q but got %q for Segment 'CommitmentPlanName'", id.CommitmentPlanName, "commitmentPlanValue") + } + + if id.AccountAssociationName != "accountAssociationValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountAssociationName'", id.AccountAssociationName, "accountAssociationValue") + } +} + +func TestFormatAccountAssociationID(t *testing.T) { + actual := NewAccountAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue", "accountAssociationValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue/accountAssociations/accountAssociationValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccountAssociationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountAssociationId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue/accountAssociations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue/accountAssociations/accountAssociationValue", + Expected: &AccountAssociationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + CommitmentPlanName: "commitmentPlanValue", + AccountAssociationName: "accountAssociationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue/accountAssociations/accountAssociationValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountAssociationID(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.CommitmentPlanName != v.Expected.CommitmentPlanName { + t.Fatalf("Expected %q but got %q for CommitmentPlanName", v.Expected.CommitmentPlanName, actual.CommitmentPlanName) + } + + if actual.AccountAssociationName != v.Expected.AccountAssociationName { + t.Fatalf("Expected %q but got %q for AccountAssociationName", v.Expected.AccountAssociationName, actual.AccountAssociationName) + } + + } +} + +func TestParseAccountAssociationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountAssociationId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/cOmMiTmEnTpLaNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/cOmMiTmEnTpLaNs/cOmMiTmEnTpLaNvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue/accountAssociations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/cOmMiTmEnTpLaNs/cOmMiTmEnTpLaNvAlUe/aCcOuNtAsSoCiAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue/accountAssociations/accountAssociationValue", + Expected: &AccountAssociationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + CommitmentPlanName: "commitmentPlanValue", + AccountAssociationName: "accountAssociationValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue/accountAssociations/accountAssociationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/cOmMiTmEnTpLaNs/cOmMiTmEnTpLaNvAlUe/aCcOuNtAsSoCiAtIoNs/aCcOuNtAsSoCiAtIoNvAlUe", + Expected: &AccountAssociationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + CommitmentPlanName: "cOmMiTmEnTpLaNvAlUe", + AccountAssociationName: "aCcOuNtAsSoCiAtIoNvAlUe", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/cOmMiTmEnTpLaNs/cOmMiTmEnTpLaNvAlUe/aCcOuNtAsSoCiAtIoNs/aCcOuNtAsSoCiAtIoNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountAssociationIDInsensitively(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.CommitmentPlanName != v.Expected.CommitmentPlanName { + t.Fatalf("Expected %q but got %q for CommitmentPlanName", v.Expected.CommitmentPlanName, actual.CommitmentPlanName) + } + + if actual.AccountAssociationName != v.Expected.AccountAssociationName { + t.Fatalf("Expected %q but got %q for AccountAssociationName", v.Expected.AccountAssociationName, actual.AccountAssociationName) + } + + } +} + +func TestSegmentsForAccountAssociationId(t *testing.T) { + segments := AccountAssociationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccountAssociationId 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/cognitive/2023-10-01-preview/commitmentplans/id_accountcommitmentplan.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountcommitmentplan.go new file mode 100644 index 00000000000..bb4cf4dce5b --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountcommitmentplan.go @@ -0,0 +1,134 @@ +package commitmentplans + +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 = &AccountCommitmentPlanId{} + +// AccountCommitmentPlanId is a struct representing the Resource ID for a Account Commitment Plan +type AccountCommitmentPlanId struct { + SubscriptionId string + ResourceGroupName string + AccountName string + CommitmentPlanName string +} + +// NewAccountCommitmentPlanID returns a new AccountCommitmentPlanId struct +func NewAccountCommitmentPlanID(subscriptionId string, resourceGroupName string, accountName string, commitmentPlanName string) AccountCommitmentPlanId { + return AccountCommitmentPlanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + CommitmentPlanName: commitmentPlanName, + } +} + +// ParseAccountCommitmentPlanID parses 'input' into a AccountCommitmentPlanId +func ParseAccountCommitmentPlanID(input string) (*AccountCommitmentPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountCommitmentPlanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountCommitmentPlanId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccountCommitmentPlanIDInsensitively parses 'input' case-insensitively into a AccountCommitmentPlanId +// note: this method should only be used for API response data and not user input +func ParseAccountCommitmentPlanIDInsensitively(input string) (*AccountCommitmentPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountCommitmentPlanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountCommitmentPlanId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccountCommitmentPlanId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + if id.CommitmentPlanName, ok = input.Parsed["commitmentPlanName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "commitmentPlanName", input) + } + + return nil +} + +// ValidateAccountCommitmentPlanID checks that 'input' can be parsed as a Account Commitment Plan ID +func ValidateAccountCommitmentPlanID(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 := ParseAccountCommitmentPlanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Account Commitment Plan ID +func (id AccountCommitmentPlanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s/commitmentPlans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName, id.CommitmentPlanName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Account Commitment Plan ID +func (id AccountCommitmentPlanId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + resourceids.StaticSegment("staticCommitmentPlans", "commitmentPlans", "commitmentPlans"), + resourceids.UserSpecifiedSegment("commitmentPlanName", "commitmentPlanValue"), + } +} + +// String returns a human-readable description of this Account Commitment Plan ID +func (id AccountCommitmentPlanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + fmt.Sprintf("Commitment Plan Name: %q", id.CommitmentPlanName), + } + return fmt.Sprintf("Account Commitment Plan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountcommitmentplan_test.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountcommitmentplan_test.go new file mode 100644 index 00000000000..399138d8605 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_accountcommitmentplan_test.go @@ -0,0 +1,327 @@ +package commitmentplans + +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 = &AccountCommitmentPlanId{} + +func TestNewAccountCommitmentPlanID(t *testing.T) { + id := NewAccountCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "commitmentPlanValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } + + if id.CommitmentPlanName != "commitmentPlanValue" { + t.Fatalf("Expected %q but got %q for Segment 'CommitmentPlanName'", id.CommitmentPlanName, "commitmentPlanValue") + } +} + +func TestFormatAccountCommitmentPlanID(t *testing.T) { + actual := NewAccountCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "commitmentPlanValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/commitmentPlans/commitmentPlanValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccountCommitmentPlanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountCommitmentPlanId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/commitmentPlans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/commitmentPlans/commitmentPlanValue", + Expected: &AccountCommitmentPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + CommitmentPlanName: "commitmentPlanValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/commitmentPlans/commitmentPlanValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountCommitmentPlanID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.CommitmentPlanName != v.Expected.CommitmentPlanName { + t.Fatalf("Expected %q but got %q for CommitmentPlanName", v.Expected.CommitmentPlanName, actual.CommitmentPlanName) + } + + } +} + +func TestParseAccountCommitmentPlanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountCommitmentPlanId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/commitmentPlans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/cOmMiTmEnTpLaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/commitmentPlans/commitmentPlanValue", + Expected: &AccountCommitmentPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + CommitmentPlanName: "commitmentPlanValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/commitmentPlans/commitmentPlanValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/cOmMiTmEnTpLaNs/cOmMiTmEnTpLaNvAlUe", + Expected: &AccountCommitmentPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + CommitmentPlanName: "cOmMiTmEnTpLaNvAlUe", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/cOmMiTmEnTpLaNs/cOmMiTmEnTpLaNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountCommitmentPlanIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.CommitmentPlanName != v.Expected.CommitmentPlanName { + t.Fatalf("Expected %q but got %q for CommitmentPlanName", v.Expected.CommitmentPlanName, actual.CommitmentPlanName) + } + + } +} + +func TestSegmentsForAccountCommitmentPlanId(t *testing.T) { + segments := AccountCommitmentPlanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccountCommitmentPlanId 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/cognitive/2023-10-01-preview/commitmentplans/id_commitmentplan.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_commitmentplan.go new file mode 100644 index 00000000000..5f49def8a1a --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_commitmentplan.go @@ -0,0 +1,125 @@ +package commitmentplans + +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 = &CommitmentPlanId{} + +// CommitmentPlanId is a struct representing the Resource ID for a Commitment Plan +type CommitmentPlanId struct { + SubscriptionId string + ResourceGroupName string + CommitmentPlanName string +} + +// NewCommitmentPlanID returns a new CommitmentPlanId struct +func NewCommitmentPlanID(subscriptionId string, resourceGroupName string, commitmentPlanName string) CommitmentPlanId { + return CommitmentPlanId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + CommitmentPlanName: commitmentPlanName, + } +} + +// ParseCommitmentPlanID parses 'input' into a CommitmentPlanId +func ParseCommitmentPlanID(input string) (*CommitmentPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(&CommitmentPlanId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CommitmentPlanId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCommitmentPlanIDInsensitively parses 'input' case-insensitively into a CommitmentPlanId +// note: this method should only be used for API response data and not user input +func ParseCommitmentPlanIDInsensitively(input string) (*CommitmentPlanId, error) { + parser := resourceids.NewParserFromResourceIdType(&CommitmentPlanId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CommitmentPlanId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CommitmentPlanId) 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.CommitmentPlanName, ok = input.Parsed["commitmentPlanName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "commitmentPlanName", input) + } + + return nil +} + +// ValidateCommitmentPlanID checks that 'input' can be parsed as a Commitment Plan ID +func ValidateCommitmentPlanID(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 := ParseCommitmentPlanID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Commitment Plan ID +func (id CommitmentPlanId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/commitmentPlans/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.CommitmentPlanName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Commitment Plan ID +func (id CommitmentPlanId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticCommitmentPlans", "commitmentPlans", "commitmentPlans"), + resourceids.UserSpecifiedSegment("commitmentPlanName", "commitmentPlanValue"), + } +} + +// String returns a human-readable description of this Commitment Plan ID +func (id CommitmentPlanId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Commitment Plan Name: %q", id.CommitmentPlanName), + } + return fmt.Sprintf("Commitment Plan (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_commitmentplan_test.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_commitmentplan_test.go new file mode 100644 index 00000000000..fb121e889a0 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/id_commitmentplan_test.go @@ -0,0 +1,282 @@ +package commitmentplans + +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 = &CommitmentPlanId{} + +func TestNewCommitmentPlanID(t *testing.T) { + id := NewCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue") + + 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.CommitmentPlanName != "commitmentPlanValue" { + t.Fatalf("Expected %q but got %q for Segment 'CommitmentPlanName'", id.CommitmentPlanName, "commitmentPlanValue") + } +} + +func TestFormatCommitmentPlanID(t *testing.T) { + actual := NewCommitmentPlanID("12345678-1234-9876-4563-123456789012", "example-resource-group", "commitmentPlanValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCommitmentPlanID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CommitmentPlanId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue", + Expected: &CommitmentPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + CommitmentPlanName: "commitmentPlanValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCommitmentPlanID(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.CommitmentPlanName != v.Expected.CommitmentPlanName { + t.Fatalf("Expected %q but got %q for CommitmentPlanName", v.Expected.CommitmentPlanName, actual.CommitmentPlanName) + } + + } +} + +func TestParseCommitmentPlanIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CommitmentPlanId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/cOmMiTmEnTpLaNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue", + Expected: &CommitmentPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + CommitmentPlanName: "commitmentPlanValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/commitmentPlans/commitmentPlanValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/cOmMiTmEnTpLaNs/cOmMiTmEnTpLaNvAlUe", + Expected: &CommitmentPlanId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + CommitmentPlanName: "cOmMiTmEnTpLaNvAlUe", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/cOmMiTmEnTpLaNs/cOmMiTmEnTpLaNvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCommitmentPlanIDInsensitively(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.CommitmentPlanName != v.Expected.CommitmentPlanName { + t.Fatalf("Expected %q but got %q for CommitmentPlanName", v.Expected.CommitmentPlanName, actual.CommitmentPlanName) + } + + } +} + +func TestSegmentsForCommitmentPlanId(t *testing.T) { + segments := CommitmentPlanId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CommitmentPlanId 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/cognitive/2023-10-01-preview/commitmentplans/method_createorupdate.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_createorupdate.go new file mode 100644 index 00000000000..9e198245dd8 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_createorupdate.go @@ -0,0 +1,59 @@ +package commitmentplans + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CommitmentPlan +} + +// CreateOrUpdate ... +func (c CommitmentPlansClient) CreateOrUpdate(ctx context.Context, id AccountCommitmentPlanId, input CommitmentPlan) (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 + } + + var model CommitmentPlan + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_createorupdateassociation.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_createorupdateassociation.go new file mode 100644 index 00000000000..5c273b1d303 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_createorupdateassociation.go @@ -0,0 +1,75 @@ +package commitmentplans + +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 CreateOrUpdateAssociationOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CommitmentPlanAccountAssociation +} + +// CreateOrUpdateAssociation ... +func (c CommitmentPlansClient) CreateOrUpdateAssociation(ctx context.Context, id AccountAssociationId, input CommitmentPlanAccountAssociation) (result CreateOrUpdateAssociationOperationResponse, 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 +} + +// CreateOrUpdateAssociationThenPoll performs CreateOrUpdateAssociation then polls until it's completed +func (c CommitmentPlansClient) CreateOrUpdateAssociationThenPoll(ctx context.Context, id AccountAssociationId, input CommitmentPlanAccountAssociation) error { + result, err := c.CreateOrUpdateAssociation(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdateAssociation: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdateAssociation: %+v", err) + } + + return nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_delete.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_delete.go new file mode 100644 index 00000000000..26f212fce5f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_delete.go @@ -0,0 +1,71 @@ +package commitmentplans + +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 CommitmentPlansClient) Delete(ctx context.Context, id AccountCommitmentPlanId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c CommitmentPlansClient) DeleteThenPoll(ctx context.Context, id AccountCommitmentPlanId) 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/cognitive/2023-10-01-preview/commitmentplans/method_deleteassociation.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_deleteassociation.go new file mode 100644 index 00000000000..c61f6a4fc44 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_deleteassociation.go @@ -0,0 +1,71 @@ +package commitmentplans + +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 DeleteAssociationOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// DeleteAssociation ... +func (c CommitmentPlansClient) DeleteAssociation(ctx context.Context, id AccountAssociationId) (result DeleteAssociationOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteAssociationThenPoll performs DeleteAssociation then polls until it's completed +func (c CommitmentPlansClient) DeleteAssociationThenPoll(ctx context.Context, id AccountAssociationId) error { + result, err := c.DeleteAssociation(ctx, id) + if err != nil { + return fmt.Errorf("performing DeleteAssociation: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after DeleteAssociation: %+v", err) + } + + return nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_get.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_get.go new file mode 100644 index 00000000000..9221f10e690 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_get.go @@ -0,0 +1,54 @@ +package commitmentplans + +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 *CommitmentPlan +} + +// Get ... +func (c CommitmentPlansClient) Get(ctx context.Context, id AccountCommitmentPlanId) (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 CommitmentPlan + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_getassociation.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_getassociation.go new file mode 100644 index 00000000000..89904210382 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_getassociation.go @@ -0,0 +1,54 @@ +package commitmentplans + +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 GetAssociationOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CommitmentPlanAccountAssociation +} + +// GetAssociation ... +func (c CommitmentPlansClient) GetAssociation(ctx context.Context, id AccountAssociationId) (result GetAssociationOperationResponse, 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 CommitmentPlanAccountAssociation + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_list.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_list.go new file mode 100644 index 00000000000..9bb35d267d9 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_list.go @@ -0,0 +1,91 @@ +package commitmentplans + +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 *[]CommitmentPlan +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []CommitmentPlan +} + +// List ... +func (c CommitmentPlansClient) List(ctx context.Context, id AccountId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/commitmentPlans", 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 *[]CommitmentPlan `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 CommitmentPlansClient) ListComplete(ctx context.Context, id AccountId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, CommitmentPlanOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CommitmentPlansClient) ListCompleteMatchingPredicate(ctx context.Context, id AccountId, predicate CommitmentPlanOperationPredicate) (result ListCompleteResult, err error) { + items := make([]CommitmentPlan, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_listassociations.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_listassociations.go new file mode 100644 index 00000000000..2cd51fc6e3a --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/method_listassociations.go @@ -0,0 +1,91 @@ +package commitmentplans + +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 ListAssociationsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CommitmentPlanAccountAssociation +} + +type ListAssociationsCompleteResult struct { + LatestHttpResponse *http.Response + Items []CommitmentPlanAccountAssociation +} + +// ListAssociations ... +func (c CommitmentPlansClient) ListAssociations(ctx context.Context, id CommitmentPlanId) (result ListAssociationsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/accountAssociations", 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 *[]CommitmentPlanAccountAssociation `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListAssociationsComplete retrieves all the results into a single object +func (c CommitmentPlansClient) ListAssociationsComplete(ctx context.Context, id CommitmentPlanId) (ListAssociationsCompleteResult, error) { + return c.ListAssociationsCompleteMatchingPredicate(ctx, id, CommitmentPlanAccountAssociationOperationPredicate{}) +} + +// ListAssociationsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CommitmentPlansClient) ListAssociationsCompleteMatchingPredicate(ctx context.Context, id CommitmentPlanId, predicate CommitmentPlanAccountAssociationOperationPredicate) (result ListAssociationsCompleteResult, err error) { + items := make([]CommitmentPlanAccountAssociation, 0) + + resp, err := c.ListAssociations(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 = ListAssociationsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentperiod.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentperiod.go new file mode 100644 index 00000000000..1e1404407e6 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentperiod.go @@ -0,0 +1,12 @@ +package commitmentplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentPeriod struct { + Count *int64 `json:"count,omitempty"` + EndDate *string `json:"endDate,omitempty"` + Quota *CommitmentQuota `json:"quota,omitempty"` + StartDate *string `json:"startDate,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplan.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplan.go new file mode 100644 index 00000000000..14d4fd907e8 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplan.go @@ -0,0 +1,21 @@ +package commitmentplans + +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 CommitmentPlan struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Kind *string `json:"kind,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CommitmentPlanProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplanaccountassociation.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplanaccountassociation.go new file mode 100644 index 00000000000..5dc6ade1e96 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplanaccountassociation.go @@ -0,0 +1,18 @@ +package commitmentplans + +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 CommitmentPlanAccountAssociation struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CommitmentPlanAccountAssociationProperties `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/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplanaccountassociationproperties.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplanaccountassociationproperties.go new file mode 100644 index 00000000000..b14d6688f86 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplanaccountassociationproperties.go @@ -0,0 +1,8 @@ +package commitmentplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentPlanAccountAssociationProperties struct { + AccountId *string `json:"accountId,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplanproperties.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplanproperties.go new file mode 100644 index 00000000000..b5f2e6865f9 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentplanproperties.go @@ -0,0 +1,16 @@ +package commitmentplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentPlanProperties struct { + AutoRenew *bool `json:"autoRenew,omitempty"` + CommitmentPlanGuid *string `json:"commitmentPlanGuid,omitempty"` + Current *CommitmentPeriod `json:"current,omitempty"` + HostingModel *HostingModel `json:"hostingModel,omitempty"` + Last *CommitmentPeriod `json:"last,omitempty"` + Next *CommitmentPeriod `json:"next,omitempty"` + PlanType *string `json:"planType,omitempty"` + ProvisioningIssues *[]string `json:"provisioningIssues,omitempty"` + ProvisioningState *CommitmentPlanProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentquota.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentquota.go new file mode 100644 index 00000000000..9a0ae20000c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_commitmentquota.go @@ -0,0 +1,9 @@ +package commitmentplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentQuota struct { + Quantity *int64 `json:"quantity,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_sku.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_sku.go new file mode 100644 index 00000000000..0bd766c62ef --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/model_sku.go @@ -0,0 +1,12 @@ +package commitmentplans + +// 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/cognitive/2023-10-01-preview/commitmentplans/predicates.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/predicates.go new file mode 100644 index 00000000000..26c60f96ce0 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/predicates.go @@ -0,0 +1,70 @@ +package commitmentplans + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentPlanOperationPredicate struct { + Etag *string + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p CommitmentPlanOperationPredicate) Matches(input CommitmentPlan) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + 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 +} + +type CommitmentPlanAccountAssociationOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p CommitmentPlanAccountAssociationOperationPredicate) Matches(input CommitmentPlanAccountAssociation) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + 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/cognitive/2023-10-01-preview/commitmentplans/version.go b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/version.go new file mode 100644 index 00000000000..2d3cc5744d1 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmentplans/version.go @@ -0,0 +1,12 @@ +package commitmentplans + +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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/commitmentplans/%s", defaultApiVersion) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/README.md b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/README.md new file mode 100644 index 00000000000..8dca551690b --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/commitmenttiers` Documentation + +The `commitmenttiers` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/commitmenttiers" +``` + + +### Client Initialization + +```go +client := commitmenttiers.NewCommitmentTiersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CommitmentTiersClient.List` + +```go +ctx := context.TODO() +id := commitmenttiers.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/client.go b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/client.go new file mode 100644 index 00000000000..859c1a4a147 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/client.go @@ -0,0 +1,26 @@ +package commitmenttiers + +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 CommitmentTiersClient struct { + Client *resourcemanager.Client +} + +func NewCommitmentTiersClientWithBaseURI(sdkApi sdkEnv.Api) (*CommitmentTiersClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "commitmenttiers", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CommitmentTiersClient: %+v", err) + } + + return &CommitmentTiersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/constants.go b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/constants.go new file mode 100644 index 00000000000..a70846f9462 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/constants.go @@ -0,0 +1,57 @@ +package commitmenttiers + +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 HostingModel string + +const ( + HostingModelConnectedContainer HostingModel = "ConnectedContainer" + HostingModelDisconnectedContainer HostingModel = "DisconnectedContainer" + HostingModelProvisionedWeb HostingModel = "ProvisionedWeb" + HostingModelWeb HostingModel = "Web" +) + +func PossibleValuesForHostingModel() []string { + return []string{ + string(HostingModelConnectedContainer), + string(HostingModelDisconnectedContainer), + string(HostingModelProvisionedWeb), + string(HostingModelWeb), + } +} + +func (s *HostingModel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseHostingModel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseHostingModel(input string) (*HostingModel, error) { + vals := map[string]HostingModel{ + "connectedcontainer": HostingModelConnectedContainer, + "disconnectedcontainer": HostingModelDisconnectedContainer, + "provisionedweb": HostingModelProvisionedWeb, + "web": HostingModelWeb, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := HostingModel(input) + return &out, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/id_location.go b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/id_location.go new file mode 100644 index 00000000000..1478805c7b7 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/id_location.go @@ -0,0 +1,116 @@ +package commitmenttiers + +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.CognitiveServices/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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + 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/cognitive/2023-10-01-preview/commitmenttiers/id_location_test.go b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/id_location_test.go new file mode 100644 index 00000000000..650ba1491f8 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/id_location_test.go @@ -0,0 +1,237 @@ +package commitmenttiers + +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.CognitiveServices/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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/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.CognitiveServices/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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/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.CognitiveServices/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/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.cOgNiTiVeSeRvIcEs/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/cognitive/2023-10-01-preview/commitmenttiers/method_list.go b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/method_list.go new file mode 100644 index 00000000000..77a57ca9f23 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/method_list.go @@ -0,0 +1,91 @@ +package commitmenttiers + +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 *[]CommitmentTier +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []CommitmentTier +} + +// List ... +func (c CommitmentTiersClient) List(ctx context.Context, id LocationId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/commitmentTiers", 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 *[]CommitmentTier `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 CommitmentTiersClient) ListComplete(ctx context.Context, id LocationId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, CommitmentTierOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CommitmentTiersClient) ListCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate CommitmentTierOperationPredicate) (result ListCompleteResult, err error) { + items := make([]CommitmentTier, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/model_commitmentcost.go b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/model_commitmentcost.go new file mode 100644 index 00000000000..95367079be8 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/model_commitmentcost.go @@ -0,0 +1,9 @@ +package commitmenttiers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentCost struct { + CommitmentMeterId *string `json:"commitmentMeterId,omitempty"` + OverageMeterId *string `json:"overageMeterId,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/model_commitmentquota.go b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/model_commitmentquota.go new file mode 100644 index 00000000000..3391c9d2e54 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/model_commitmentquota.go @@ -0,0 +1,9 @@ +package commitmenttiers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentQuota struct { + Quantity *int64 `json:"quantity,omitempty"` + Unit *string `json:"unit,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/model_commitmenttier.go b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/model_commitmenttier.go new file mode 100644 index 00000000000..e8e8f089c49 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/model_commitmenttier.go @@ -0,0 +1,15 @@ +package commitmenttiers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentTier struct { + Cost *CommitmentCost `json:"cost,omitempty"` + HostingModel *HostingModel `json:"hostingModel,omitempty"` + Kind *string `json:"kind,omitempty"` + MaxCount *int64 `json:"maxCount,omitempty"` + PlanType *string `json:"planType,omitempty"` + Quota *CommitmentQuota `json:"quota,omitempty"` + SkuName *string `json:"skuName,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/predicates.go b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/predicates.go new file mode 100644 index 00000000000..54244bba0d1 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/predicates.go @@ -0,0 +1,37 @@ +package commitmenttiers + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CommitmentTierOperationPredicate struct { + Kind *string + MaxCount *int64 + PlanType *string + SkuName *string + Tier *string +} + +func (p CommitmentTierOperationPredicate) Matches(input CommitmentTier) bool { + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + return false + } + + if p.MaxCount != nil && (input.MaxCount == nil || *p.MaxCount != *input.MaxCount) { + return false + } + + if p.PlanType != nil && (input.PlanType == nil || *p.PlanType != *input.PlanType) { + return false + } + + if p.SkuName != nil && (input.SkuName == nil || *p.SkuName != *input.SkuName) { + return false + } + + if p.Tier != nil && (input.Tier == nil || *p.Tier != *input.Tier) { + return false + } + + return true +} diff --git a/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/version.go b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/version.go new file mode 100644 index 00000000000..0ab81038c2c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/commitmenttiers/version.go @@ -0,0 +1,12 @@ +package commitmenttiers + +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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/commitmenttiers/%s", defaultApiVersion) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/README.md b/resource-manager/cognitive/2023-10-01-preview/deployments/README.md new file mode 100644 index 00000000000..0a08b269097 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/README.md @@ -0,0 +1,116 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/deployments` Documentation + +The `deployments` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/deployments" +``` + + +### Client Initialization + +```go +client := deployments.NewDeploymentsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DeploymentsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := deployments.NewDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "deploymentValue") + +payload := deployments.Deployment{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.Delete` + +```go +ctx := context.TODO() +id := deployments.NewDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "deploymentValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DeploymentsClient.Get` + +```go +ctx := context.TODO() +id := deployments.NewDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "deploymentValue") + +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: `DeploymentsClient.List` + +```go +ctx := context.TODO() +id := deployments.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeploymentsClient.ListSkus` + +```go +ctx := context.TODO() +id := deployments.NewDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "deploymentValue") + +// alternatively `client.ListSkus(ctx, id)` can be used to do batched pagination +items, err := client.ListSkusComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `DeploymentsClient.Update` + +```go +ctx := context.TODO() +id := deployments.NewDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "deploymentValue") + +payload := deployments.PatchResourceTagsAndSku{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/client.go b/resource-manager/cognitive/2023-10-01-preview/deployments/client.go new file mode 100644 index 00000000000..50a604559bd --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/client.go @@ -0,0 +1,26 @@ +package deployments + +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 DeploymentsClient struct { + Client *resourcemanager.Client +} + +func NewDeploymentsClientWithBaseURI(sdkApi sdkEnv.Api) (*DeploymentsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "deployments", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating DeploymentsClient: %+v", err) + } + + return &DeploymentsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/constants.go b/resource-manager/cognitive/2023-10-01-preview/deployments/constants.go new file mode 100644 index 00000000000..e02d96bceec --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/constants.go @@ -0,0 +1,204 @@ +package deployments + +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 DeploymentModelVersionUpgradeOption string + +const ( + DeploymentModelVersionUpgradeOptionNoAutoUpgrade DeploymentModelVersionUpgradeOption = "NoAutoUpgrade" + DeploymentModelVersionUpgradeOptionOnceCurrentVersionExpired DeploymentModelVersionUpgradeOption = "OnceCurrentVersionExpired" + DeploymentModelVersionUpgradeOptionOnceNewDefaultVersionAvailable DeploymentModelVersionUpgradeOption = "OnceNewDefaultVersionAvailable" +) + +func PossibleValuesForDeploymentModelVersionUpgradeOption() []string { + return []string{ + string(DeploymentModelVersionUpgradeOptionNoAutoUpgrade), + string(DeploymentModelVersionUpgradeOptionOnceCurrentVersionExpired), + string(DeploymentModelVersionUpgradeOptionOnceNewDefaultVersionAvailable), + } +} + +func (s *DeploymentModelVersionUpgradeOption) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentModelVersionUpgradeOption(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentModelVersionUpgradeOption(input string) (*DeploymentModelVersionUpgradeOption, error) { + vals := map[string]DeploymentModelVersionUpgradeOption{ + "noautoupgrade": DeploymentModelVersionUpgradeOptionNoAutoUpgrade, + "oncecurrentversionexpired": DeploymentModelVersionUpgradeOptionOnceCurrentVersionExpired, + "oncenewdefaultversionavailable": DeploymentModelVersionUpgradeOptionOnceNewDefaultVersionAvailable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentModelVersionUpgradeOption(input) + return &out, nil +} + +type DeploymentProvisioningState string + +const ( + DeploymentProvisioningStateAccepted DeploymentProvisioningState = "Accepted" + DeploymentProvisioningStateCanceled DeploymentProvisioningState = "Canceled" + DeploymentProvisioningStateCreating DeploymentProvisioningState = "Creating" + DeploymentProvisioningStateDeleting DeploymentProvisioningState = "Deleting" + DeploymentProvisioningStateDisabled DeploymentProvisioningState = "Disabled" + DeploymentProvisioningStateFailed DeploymentProvisioningState = "Failed" + DeploymentProvisioningStateMoving DeploymentProvisioningState = "Moving" + DeploymentProvisioningStateSucceeded DeploymentProvisioningState = "Succeeded" +) + +func PossibleValuesForDeploymentProvisioningState() []string { + return []string{ + string(DeploymentProvisioningStateAccepted), + string(DeploymentProvisioningStateCanceled), + string(DeploymentProvisioningStateCreating), + string(DeploymentProvisioningStateDeleting), + string(DeploymentProvisioningStateDisabled), + string(DeploymentProvisioningStateFailed), + string(DeploymentProvisioningStateMoving), + string(DeploymentProvisioningStateSucceeded), + } +} + +func (s *DeploymentProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentProvisioningState(input string) (*DeploymentProvisioningState, error) { + vals := map[string]DeploymentProvisioningState{ + "accepted": DeploymentProvisioningStateAccepted, + "canceled": DeploymentProvisioningStateCanceled, + "creating": DeploymentProvisioningStateCreating, + "deleting": DeploymentProvisioningStateDeleting, + "disabled": DeploymentProvisioningStateDisabled, + "failed": DeploymentProvisioningStateFailed, + "moving": DeploymentProvisioningStateMoving, + "succeeded": DeploymentProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentProvisioningState(input) + return &out, nil +} + +type DeploymentScaleType string + +const ( + DeploymentScaleTypeManual DeploymentScaleType = "Manual" + DeploymentScaleTypeStandard DeploymentScaleType = "Standard" +) + +func PossibleValuesForDeploymentScaleType() []string { + return []string{ + string(DeploymentScaleTypeManual), + string(DeploymentScaleTypeStandard), + } +} + +func (s *DeploymentScaleType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentScaleType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentScaleType(input string) (*DeploymentScaleType, error) { + vals := map[string]DeploymentScaleType{ + "manual": DeploymentScaleTypeManual, + "standard": DeploymentScaleTypeStandard, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentScaleType(input) + return &out, nil +} + +type SkuTier string + +const ( + SkuTierBasic SkuTier = "Basic" + SkuTierEnterprise SkuTier = "Enterprise" + SkuTierFree SkuTier = "Free" + SkuTierPremium SkuTier = "Premium" + SkuTierStandard SkuTier = "Standard" +) + +func PossibleValuesForSkuTier() []string { + return []string{ + string(SkuTierBasic), + string(SkuTierEnterprise), + 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, + "enterprise": SkuTierEnterprise, + "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/cognitive/2023-10-01-preview/deployments/id_account.go b/resource-manager/cognitive/2023-10-01-preview/deployments/id_account.go new file mode 100644 index 00000000000..f7c40fbf169 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/id_account.go @@ -0,0 +1,125 @@ +package deployments + +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 = &AccountId{} + +// AccountId is a struct representing the Resource ID for a Account +type AccountId struct { + SubscriptionId string + ResourceGroupName string + AccountName string +} + +// NewAccountID returns a new AccountId struct +func NewAccountID(subscriptionId string, resourceGroupName string, accountName string) AccountId { + return AccountId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + } +} + +// ParseAccountID parses 'input' into a AccountId +func ParseAccountID(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccountIDInsensitively parses 'input' case-insensitively into a AccountId +// note: this method should only be used for API response data and not user input +func ParseAccountIDInsensitively(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccountId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + return nil +} + +// ValidateAccountID checks that 'input' can be parsed as a Account ID +func ValidateAccountID(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 := ParseAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Account ID +func (id AccountId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Account ID +func (id AccountId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + } +} + +// String returns a human-readable description of this Account ID +func (id AccountId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + } + return fmt.Sprintf("Account (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/id_account_test.go b/resource-manager/cognitive/2023-10-01-preview/deployments/id_account_test.go new file mode 100644 index 00000000000..fb9df1329e2 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/id_account_test.go @@ -0,0 +1,282 @@ +package deployments + +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 = &AccountId{} + +func TestNewAccountID(t *testing.T) { + id := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } +} + +func TestFormatAccountID(t *testing.T) { + actual := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccountID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestParseAccountIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestSegmentsForAccountId(t *testing.T) { + segments := AccountId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccountId 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/cognitive/2023-10-01-preview/deployments/id_deployment.go b/resource-manager/cognitive/2023-10-01-preview/deployments/id_deployment.go new file mode 100644 index 00000000000..129e81274c0 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/id_deployment.go @@ -0,0 +1,134 @@ +package deployments + +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 = &DeploymentId{} + +// DeploymentId is a struct representing the Resource ID for a Deployment +type DeploymentId struct { + SubscriptionId string + ResourceGroupName string + AccountName string + DeploymentName string +} + +// NewDeploymentID returns a new DeploymentId struct +func NewDeploymentID(subscriptionId string, resourceGroupName string, accountName string, deploymentName string) DeploymentId { + return DeploymentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + DeploymentName: deploymentName, + } +} + +// ParseDeploymentID parses 'input' into a DeploymentId +func ParseDeploymentID(input string) (*DeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeploymentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeploymentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseDeploymentIDInsensitively parses 'input' case-insensitively into a DeploymentId +// note: this method should only be used for API response data and not user input +func ParseDeploymentIDInsensitively(input string) (*DeploymentId, error) { + parser := resourceids.NewParserFromResourceIdType(&DeploymentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := DeploymentId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *DeploymentId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + if id.DeploymentName, ok = input.Parsed["deploymentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "deploymentName", input) + } + + return nil +} + +// ValidateDeploymentID checks that 'input' can be parsed as a Deployment ID +func ValidateDeploymentID(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 := ParseDeploymentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Deployment ID +func (id DeploymentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s/deployments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName, id.DeploymentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Deployment ID +func (id DeploymentId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + resourceids.StaticSegment("staticDeployments", "deployments", "deployments"), + resourceids.UserSpecifiedSegment("deploymentName", "deploymentValue"), + } +} + +// String returns a human-readable description of this Deployment ID +func (id DeploymentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + fmt.Sprintf("Deployment Name: %q", id.DeploymentName), + } + return fmt.Sprintf("Deployment (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/id_deployment_test.go b/resource-manager/cognitive/2023-10-01-preview/deployments/id_deployment_test.go new file mode 100644 index 00000000000..414d92b5788 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/id_deployment_test.go @@ -0,0 +1,327 @@ +package deployments + +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 = &DeploymentId{} + +func TestNewDeploymentID(t *testing.T) { + id := NewDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "deploymentValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } + + if id.DeploymentName != "deploymentValue" { + t.Fatalf("Expected %q but got %q for Segment 'DeploymentName'", id.DeploymentName, "deploymentValue") + } +} + +func TestFormatDeploymentID(t *testing.T) { + actual := NewDeploymentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "deploymentValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/deployments/deploymentValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseDeploymentID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeploymentId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/deployments", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/deployments/deploymentValue", + Expected: &DeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + DeploymentName: "deploymentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/deployments/deploymentValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeploymentID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestParseDeploymentIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *DeploymentId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/deployments", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/dEpLoYmEnTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/deployments/deploymentValue", + Expected: &DeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + DeploymentName: "deploymentValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/deployments/deploymentValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/dEpLoYmEnTs/dEpLoYmEnTvAlUe", + Expected: &DeploymentId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + DeploymentName: "dEpLoYmEnTvAlUe", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/dEpLoYmEnTs/dEpLoYmEnTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseDeploymentIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.DeploymentName != v.Expected.DeploymentName { + t.Fatalf("Expected %q but got %q for DeploymentName", v.Expected.DeploymentName, actual.DeploymentName) + } + + } +} + +func TestSegmentsForDeploymentId(t *testing.T) { + segments := DeploymentId{}.Segments() + if len(segments) == 0 { + t.Fatalf("DeploymentId 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/cognitive/2023-10-01-preview/deployments/method_createorupdate.go b/resource-manager/cognitive/2023-10-01-preview/deployments/method_createorupdate.go new file mode 100644 index 00000000000..25281a68040 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/method_createorupdate.go @@ -0,0 +1,75 @@ +package deployments + +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 *Deployment +} + +// CreateOrUpdate ... +func (c DeploymentsClient) CreateOrUpdate(ctx context.Context, id DeploymentId, input Deployment) (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 DeploymentsClient) CreateOrUpdateThenPoll(ctx context.Context, id DeploymentId, input Deployment) 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/cognitive/2023-10-01-preview/deployments/method_delete.go b/resource-manager/cognitive/2023-10-01-preview/deployments/method_delete.go new file mode 100644 index 00000000000..dae0ddc2b66 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/method_delete.go @@ -0,0 +1,71 @@ +package deployments + +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 DeploymentsClient) Delete(ctx context.Context, id DeploymentId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c DeploymentsClient) DeleteThenPoll(ctx context.Context, id DeploymentId) 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/cognitive/2023-10-01-preview/deployments/method_get.go b/resource-manager/cognitive/2023-10-01-preview/deployments/method_get.go new file mode 100644 index 00000000000..957621b4fb1 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/method_get.go @@ -0,0 +1,54 @@ +package deployments + +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 *Deployment +} + +// Get ... +func (c DeploymentsClient) Get(ctx context.Context, id DeploymentId) (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 Deployment + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/method_list.go b/resource-manager/cognitive/2023-10-01-preview/deployments/method_list.go new file mode 100644 index 00000000000..1a1f66eaf88 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/method_list.go @@ -0,0 +1,91 @@ +package deployments + +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 *[]Deployment +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Deployment +} + +// List ... +func (c DeploymentsClient) List(ctx context.Context, id AccountId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/deployments", 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 *[]Deployment `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 DeploymentsClient) ListComplete(ctx context.Context, id AccountId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, DeploymentOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentsClient) ListCompleteMatchingPredicate(ctx context.Context, id AccountId, predicate DeploymentOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Deployment, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/method_listskus.go b/resource-manager/cognitive/2023-10-01-preview/deployments/method_listskus.go new file mode 100644 index 00000000000..169fe473af8 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/method_listskus.go @@ -0,0 +1,91 @@ +package deployments + +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 ListSkusOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SkuResource +} + +type ListSkusCompleteResult struct { + LatestHttpResponse *http.Response + Items []SkuResource +} + +// ListSkus ... +func (c DeploymentsClient) ListSkus(ctx context.Context, id DeploymentId) (result ListSkusOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/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 *[]SkuResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListSkusComplete retrieves all the results into a single object +func (c DeploymentsClient) ListSkusComplete(ctx context.Context, id DeploymentId) (ListSkusCompleteResult, error) { + return c.ListSkusCompleteMatchingPredicate(ctx, id, SkuResourceOperationPredicate{}) +} + +// ListSkusCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c DeploymentsClient) ListSkusCompleteMatchingPredicate(ctx context.Context, id DeploymentId, predicate SkuResourceOperationPredicate) (result ListSkusCompleteResult, err error) { + items := make([]SkuResource, 0) + + resp, err := c.ListSkus(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 = ListSkusCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/method_update.go b/resource-manager/cognitive/2023-10-01-preview/deployments/method_update.go new file mode 100644 index 00000000000..38169cc3cc1 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/method_update.go @@ -0,0 +1,75 @@ +package deployments + +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 *Deployment +} + +// Update ... +func (c DeploymentsClient) Update(ctx context.Context, id DeploymentId, input PatchResourceTagsAndSku) (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 DeploymentsClient) UpdateThenPoll(ctx context.Context, id DeploymentId, input PatchResourceTagsAndSku) 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/cognitive/2023-10-01-preview/deployments/model_callratelimit.go b/resource-manager/cognitive/2023-10-01-preview/deployments/model_callratelimit.go new file mode 100644 index 00000000000..b5b9fbe009d --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/model_callratelimit.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CallRateLimit struct { + Count *float64 `json:"count,omitempty"` + RenewalPeriod *float64 `json:"renewalPeriod,omitempty"` + Rules *[]ThrottlingRule `json:"rules,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/model_capacityconfig.go b/resource-manager/cognitive/2023-10-01-preview/deployments/model_capacityconfig.go new file mode 100644 index 00000000000..3a9fbfb28db --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/model_capacityconfig.go @@ -0,0 +1,12 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CapacityConfig struct { + AllowedValues *[]int64 `json:"allowedValues,omitempty"` + Default *int64 `json:"default,omitempty"` + Maximum *int64 `json:"maximum,omitempty"` + Minimum *int64 `json:"minimum,omitempty"` + Step *int64 `json:"step,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/model_deployment.go b/resource-manager/cognitive/2023-10-01-preview/deployments/model_deployment.go new file mode 100644 index 00000000000..46d1f30b18f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/model_deployment.go @@ -0,0 +1,19 @@ +package deployments + +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 Deployment struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DeploymentProperties `json:"properties,omitempty"` + Sku *Sku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentcapacitysettings.go b/resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentcapacitysettings.go new file mode 100644 index 00000000000..513b4429493 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentcapacitysettings.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentCapacitySettings struct { + DesignatedCapacity *int64 `json:"designatedCapacity,omitempty"` + Priority *int64 `json:"priority,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentmodel.go b/resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentmodel.go new file mode 100644 index 00000000000..dc69b396c5f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentmodel.go @@ -0,0 +1,12 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentModel struct { + CallRateLimit *CallRateLimit `json:"callRateLimit,omitempty"` + Format *string `json:"format,omitempty"` + Name *string `json:"name,omitempty"` + Source *string `json:"source,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentproperties.go b/resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentproperties.go new file mode 100644 index 00000000000..3e1fb558c54 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentproperties.go @@ -0,0 +1,18 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentProperties struct { + CallRateLimit *CallRateLimit `json:"callRateLimit,omitempty"` + Capabilities *map[string]string `json:"capabilities,omitempty"` + CapacitySettings *DeploymentCapacitySettings `json:"capacitySettings,omitempty"` + CurrentCapacity *int64 `json:"currentCapacity,omitempty"` + DynamicThrottlingEnabled *bool `json:"dynamicThrottlingEnabled,omitempty"` + Model *DeploymentModel `json:"model,omitempty"` + ProvisioningState *DeploymentProvisioningState `json:"provisioningState,omitempty"` + RaiPolicyName *string `json:"raiPolicyName,omitempty"` + RateLimits *[]ThrottlingRule `json:"rateLimits,omitempty"` + ScaleSettings *DeploymentScaleSettings `json:"scaleSettings,omitempty"` + VersionUpgradeOption *DeploymentModelVersionUpgradeOption `json:"versionUpgradeOption,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentscalesettings.go b/resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentscalesettings.go new file mode 100644 index 00000000000..85659600ba3 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/model_deploymentscalesettings.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentScaleSettings struct { + ActiveCapacity *int64 `json:"activeCapacity,omitempty"` + Capacity *int64 `json:"capacity,omitempty"` + ScaleType *DeploymentScaleType `json:"scaleType,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/model_patchresourcetagsandsku.go b/resource-manager/cognitive/2023-10-01-preview/deployments/model_patchresourcetagsandsku.go new file mode 100644 index 00000000000..2dcdac738c4 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/model_patchresourcetagsandsku.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchResourceTagsAndSku struct { + Sku *Sku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/model_requestmatchpattern.go b/resource-manager/cognitive/2023-10-01-preview/deployments/model_requestmatchpattern.go new file mode 100644 index 00000000000..f12d0ac24a7 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/model_requestmatchpattern.go @@ -0,0 +1,9 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestMatchPattern struct { + Method *string `json:"method,omitempty"` + Path *string `json:"path,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/model_sku.go b/resource-manager/cognitive/2023-10-01-preview/deployments/model_sku.go new file mode 100644 index 00000000000..b6155eb7e80 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/model_sku.go @@ -0,0 +1,12 @@ +package deployments + +// 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/cognitive/2023-10-01-preview/deployments/model_skuresource.go b/resource-manager/cognitive/2023-10-01-preview/deployments/model_skuresource.go new file mode 100644 index 00000000000..6899d4d1037 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/model_skuresource.go @@ -0,0 +1,10 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SkuResource struct { + Capacity *CapacityConfig `json:"capacity,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Sku *Sku `json:"sku,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/model_throttlingrule.go b/resource-manager/cognitive/2023-10-01-preview/deployments/model_throttlingrule.go new file mode 100644 index 00000000000..cf811dd64e6 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/model_throttlingrule.go @@ -0,0 +1,13 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThrottlingRule struct { + Count *float64 `json:"count,omitempty"` + DynamicThrottlingEnabled *bool `json:"dynamicThrottlingEnabled,omitempty"` + Key *string `json:"key,omitempty"` + MatchPatterns *[]RequestMatchPattern `json:"matchPatterns,omitempty"` + MinCount *float64 `json:"minCount,omitempty"` + RenewalPeriod *float64 `json:"renewalPeriod,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/predicates.go b/resource-manager/cognitive/2023-10-01-preview/deployments/predicates.go new file mode 100644 index 00000000000..ad325be8cdf --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/predicates.go @@ -0,0 +1,45 @@ +package deployments + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p DeploymentOperationPredicate) Matches(input Deployment) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + 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 SkuResourceOperationPredicate struct { + ResourceType *string +} + +func (p SkuResourceOperationPredicate) Matches(input SkuResource) bool { + + if p.ResourceType != nil && (input.ResourceType == nil || *p.ResourceType != *input.ResourceType) { + return false + } + + return true +} diff --git a/resource-manager/cognitive/2023-10-01-preview/deployments/version.go b/resource-manager/cognitive/2023-10-01-preview/deployments/version.go new file mode 100644 index 00000000000..8d5270efaf7 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/deployments/version.go @@ -0,0 +1,12 @@ +package deployments + +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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/deployments/%s", defaultApiVersion) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/README.md b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/README.md new file mode 100644 index 00000000000..e81097f3809 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/README.md @@ -0,0 +1,86 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/encryptionscopes` Documentation + +The `encryptionscopes` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/encryptionscopes" +``` + + +### Client Initialization + +```go +client := encryptionscopes.NewEncryptionScopesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `EncryptionScopesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := encryptionscopes.NewEncryptionScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "encryptionScopeValue") + +payload := encryptionscopes.EncryptionScope{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `EncryptionScopesClient.Delete` + +```go +ctx := context.TODO() +id := encryptionscopes.NewEncryptionScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "encryptionScopeValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `EncryptionScopesClient.Get` + +```go +ctx := context.TODO() +id := encryptionscopes.NewEncryptionScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "encryptionScopeValue") + +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: `EncryptionScopesClient.List` + +```go +ctx := context.TODO() +id := encryptionscopes.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/client.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/client.go new file mode 100644 index 00000000000..cece7665062 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/client.go @@ -0,0 +1,26 @@ +package encryptionscopes + +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 EncryptionScopesClient struct { + Client *resourcemanager.Client +} + +func NewEncryptionScopesClientWithBaseURI(sdkApi sdkEnv.Api) (*EncryptionScopesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "encryptionscopes", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating EncryptionScopesClient: %+v", err) + } + + return &EncryptionScopesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/constants.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/constants.go new file mode 100644 index 00000000000..c59e4ece946 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/constants.go @@ -0,0 +1,148 @@ +package encryptionscopes + +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 EncryptionScopeProvisioningState string + +const ( + EncryptionScopeProvisioningStateAccepted EncryptionScopeProvisioningState = "Accepted" + EncryptionScopeProvisioningStateCanceled EncryptionScopeProvisioningState = "Canceled" + EncryptionScopeProvisioningStateCreating EncryptionScopeProvisioningState = "Creating" + EncryptionScopeProvisioningStateDeleting EncryptionScopeProvisioningState = "Deleting" + EncryptionScopeProvisioningStateFailed EncryptionScopeProvisioningState = "Failed" + EncryptionScopeProvisioningStateMoving EncryptionScopeProvisioningState = "Moving" + EncryptionScopeProvisioningStateSucceeded EncryptionScopeProvisioningState = "Succeeded" +) + +func PossibleValuesForEncryptionScopeProvisioningState() []string { + return []string{ + string(EncryptionScopeProvisioningStateAccepted), + string(EncryptionScopeProvisioningStateCanceled), + string(EncryptionScopeProvisioningStateCreating), + string(EncryptionScopeProvisioningStateDeleting), + string(EncryptionScopeProvisioningStateFailed), + string(EncryptionScopeProvisioningStateMoving), + string(EncryptionScopeProvisioningStateSucceeded), + } +} + +func (s *EncryptionScopeProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEncryptionScopeProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEncryptionScopeProvisioningState(input string) (*EncryptionScopeProvisioningState, error) { + vals := map[string]EncryptionScopeProvisioningState{ + "accepted": EncryptionScopeProvisioningStateAccepted, + "canceled": EncryptionScopeProvisioningStateCanceled, + "creating": EncryptionScopeProvisioningStateCreating, + "deleting": EncryptionScopeProvisioningStateDeleting, + "failed": EncryptionScopeProvisioningStateFailed, + "moving": EncryptionScopeProvisioningStateMoving, + "succeeded": EncryptionScopeProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EncryptionScopeProvisioningState(input) + return &out, nil +} + +type EncryptionScopeState string + +const ( + EncryptionScopeStateDisabled EncryptionScopeState = "Disabled" + EncryptionScopeStateEnabled EncryptionScopeState = "Enabled" +) + +func PossibleValuesForEncryptionScopeState() []string { + return []string{ + string(EncryptionScopeStateDisabled), + string(EncryptionScopeStateEnabled), + } +} + +func (s *EncryptionScopeState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseEncryptionScopeState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseEncryptionScopeState(input string) (*EncryptionScopeState, error) { + vals := map[string]EncryptionScopeState{ + "disabled": EncryptionScopeStateDisabled, + "enabled": EncryptionScopeStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := EncryptionScopeState(input) + return &out, nil +} + +type KeySource string + +const ( + KeySourceMicrosoftPointCognitiveServices KeySource = "Microsoft.CognitiveServices" + KeySourceMicrosoftPointKeyVault KeySource = "Microsoft.KeyVault" +) + +func PossibleValuesForKeySource() []string { + return []string{ + string(KeySourceMicrosoftPointCognitiveServices), + string(KeySourceMicrosoftPointKeyVault), + } +} + +func (s *KeySource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseKeySource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseKeySource(input string) (*KeySource, error) { + vals := map[string]KeySource{ + "microsoft.cognitiveservices": KeySourceMicrosoftPointCognitiveServices, + "microsoft.keyvault": KeySourceMicrosoftPointKeyVault, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := KeySource(input) + return &out, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_account.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_account.go new file mode 100644 index 00000000000..bd7dc19ce1f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_account.go @@ -0,0 +1,125 @@ +package encryptionscopes + +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 = &AccountId{} + +// AccountId is a struct representing the Resource ID for a Account +type AccountId struct { + SubscriptionId string + ResourceGroupName string + AccountName string +} + +// NewAccountID returns a new AccountId struct +func NewAccountID(subscriptionId string, resourceGroupName string, accountName string) AccountId { + return AccountId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + } +} + +// ParseAccountID parses 'input' into a AccountId +func ParseAccountID(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccountIDInsensitively parses 'input' case-insensitively into a AccountId +// note: this method should only be used for API response data and not user input +func ParseAccountIDInsensitively(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccountId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + return nil +} + +// ValidateAccountID checks that 'input' can be parsed as a Account ID +func ValidateAccountID(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 := ParseAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Account ID +func (id AccountId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Account ID +func (id AccountId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + } +} + +// String returns a human-readable description of this Account ID +func (id AccountId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + } + return fmt.Sprintf("Account (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_account_test.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_account_test.go new file mode 100644 index 00000000000..263a6550e05 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_account_test.go @@ -0,0 +1,282 @@ +package encryptionscopes + +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 = &AccountId{} + +func TestNewAccountID(t *testing.T) { + id := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } +} + +func TestFormatAccountID(t *testing.T) { + actual := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccountID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestParseAccountIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestSegmentsForAccountId(t *testing.T) { + segments := AccountId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccountId 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/cognitive/2023-10-01-preview/encryptionscopes/id_encryptionscope.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_encryptionscope.go new file mode 100644 index 00000000000..ab932ed6df8 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_encryptionscope.go @@ -0,0 +1,134 @@ +package encryptionscopes + +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 = &EncryptionScopeId{} + +// EncryptionScopeId is a struct representing the Resource ID for a Encryption Scope +type EncryptionScopeId struct { + SubscriptionId string + ResourceGroupName string + AccountName string + EncryptionScopeName string +} + +// NewEncryptionScopeID returns a new EncryptionScopeId struct +func NewEncryptionScopeID(subscriptionId string, resourceGroupName string, accountName string, encryptionScopeName string) EncryptionScopeId { + return EncryptionScopeId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + EncryptionScopeName: encryptionScopeName, + } +} + +// ParseEncryptionScopeID parses 'input' into a EncryptionScopeId +func ParseEncryptionScopeID(input string) (*EncryptionScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(&EncryptionScopeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EncryptionScopeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseEncryptionScopeIDInsensitively parses 'input' case-insensitively into a EncryptionScopeId +// note: this method should only be used for API response data and not user input +func ParseEncryptionScopeIDInsensitively(input string) (*EncryptionScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(&EncryptionScopeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := EncryptionScopeId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *EncryptionScopeId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + if id.EncryptionScopeName, ok = input.Parsed["encryptionScopeName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "encryptionScopeName", input) + } + + return nil +} + +// ValidateEncryptionScopeID checks that 'input' can be parsed as a Encryption Scope ID +func ValidateEncryptionScopeID(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 := ParseEncryptionScopeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Encryption Scope ID +func (id EncryptionScopeId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s/encryptionScopes/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName, id.EncryptionScopeName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Encryption Scope ID +func (id EncryptionScopeId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + resourceids.StaticSegment("staticEncryptionScopes", "encryptionScopes", "encryptionScopes"), + resourceids.UserSpecifiedSegment("encryptionScopeName", "encryptionScopeValue"), + } +} + +// String returns a human-readable description of this Encryption Scope ID +func (id EncryptionScopeId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + fmt.Sprintf("Encryption Scope Name: %q", id.EncryptionScopeName), + } + return fmt.Sprintf("Encryption Scope (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_encryptionscope_test.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_encryptionscope_test.go new file mode 100644 index 00000000000..7164b13c78e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/id_encryptionscope_test.go @@ -0,0 +1,327 @@ +package encryptionscopes + +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 = &EncryptionScopeId{} + +func TestNewEncryptionScopeID(t *testing.T) { + id := NewEncryptionScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "encryptionScopeValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } + + if id.EncryptionScopeName != "encryptionScopeValue" { + t.Fatalf("Expected %q but got %q for Segment 'EncryptionScopeName'", id.EncryptionScopeName, "encryptionScopeValue") + } +} + +func TestFormatEncryptionScopeID(t *testing.T) { + actual := NewEncryptionScopeID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "encryptionScopeValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/encryptionScopes/encryptionScopeValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseEncryptionScopeID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EncryptionScopeId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/encryptionScopes", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/encryptionScopes/encryptionScopeValue", + Expected: &EncryptionScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + EncryptionScopeName: "encryptionScopeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/encryptionScopes/encryptionScopeValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEncryptionScopeID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.EncryptionScopeName != v.Expected.EncryptionScopeName { + t.Fatalf("Expected %q but got %q for EncryptionScopeName", v.Expected.EncryptionScopeName, actual.EncryptionScopeName) + } + + } +} + +func TestParseEncryptionScopeIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *EncryptionScopeId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/encryptionScopes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/eNcRyPtIoNsCoPeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/encryptionScopes/encryptionScopeValue", + Expected: &EncryptionScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + EncryptionScopeName: "encryptionScopeValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/encryptionScopes/encryptionScopeValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/eNcRyPtIoNsCoPeS/eNcRyPtIoNsCoPeVaLuE", + Expected: &EncryptionScopeId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + EncryptionScopeName: "eNcRyPtIoNsCoPeVaLuE", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/eNcRyPtIoNsCoPeS/eNcRyPtIoNsCoPeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseEncryptionScopeIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.EncryptionScopeName != v.Expected.EncryptionScopeName { + t.Fatalf("Expected %q but got %q for EncryptionScopeName", v.Expected.EncryptionScopeName, actual.EncryptionScopeName) + } + + } +} + +func TestSegmentsForEncryptionScopeId(t *testing.T) { + segments := EncryptionScopeId{}.Segments() + if len(segments) == 0 { + t.Fatalf("EncryptionScopeId 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/cognitive/2023-10-01-preview/encryptionscopes/method_createorupdate.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_createorupdate.go new file mode 100644 index 00000000000..09cb6a98b6e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_createorupdate.go @@ -0,0 +1,59 @@ +package encryptionscopes + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *EncryptionScope +} + +// CreateOrUpdate ... +func (c EncryptionScopesClient) CreateOrUpdate(ctx context.Context, id EncryptionScopeId, input EncryptionScope) (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 + } + + var model EncryptionScope + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_delete.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_delete.go new file mode 100644 index 00000000000..dc81c63d67e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_delete.go @@ -0,0 +1,70 @@ +package encryptionscopes + +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 EncryptionScopesClient) Delete(ctx context.Context, id EncryptionScopeId) (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 EncryptionScopesClient) DeleteThenPoll(ctx context.Context, id EncryptionScopeId) 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/cognitive/2023-10-01-preview/encryptionscopes/method_get.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_get.go new file mode 100644 index 00000000000..f3d244a9d4a --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_get.go @@ -0,0 +1,54 @@ +package encryptionscopes + +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 *EncryptionScope +} + +// Get ... +func (c EncryptionScopesClient) Get(ctx context.Context, id EncryptionScopeId) (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 EncryptionScope + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_list.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_list.go new file mode 100644 index 00000000000..0c41aa19696 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/method_list.go @@ -0,0 +1,91 @@ +package encryptionscopes + +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 *[]EncryptionScope +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []EncryptionScope +} + +// List ... +func (c EncryptionScopesClient) List(ctx context.Context, id AccountId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/encryptionScopes", 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 *[]EncryptionScope `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 EncryptionScopesClient) ListComplete(ctx context.Context, id AccountId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, EncryptionScopeOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c EncryptionScopesClient) ListCompleteMatchingPredicate(ctx context.Context, id AccountId, predicate EncryptionScopeOperationPredicate) (result ListCompleteResult, err error) { + items := make([]EncryptionScope, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/model_encryptionscope.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/model_encryptionscope.go new file mode 100644 index 00000000000..857245673ba --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/model_encryptionscope.go @@ -0,0 +1,18 @@ +package encryptionscopes + +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 EncryptionScope struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *EncryptionScopeProperties `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/cognitive/2023-10-01-preview/encryptionscopes/model_encryptionscopeproperties.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/model_encryptionscopeproperties.go new file mode 100644 index 00000000000..223ce1b62b8 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/model_encryptionscopeproperties.go @@ -0,0 +1,11 @@ +package encryptionscopes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionScopeProperties struct { + KeySource *KeySource `json:"keySource,omitempty"` + KeyVaultProperties *KeyVaultProperties `json:"keyVaultProperties,omitempty"` + ProvisioningState *EncryptionScopeProvisioningState `json:"provisioningState,omitempty"` + State *EncryptionScopeState `json:"state,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/model_keyvaultproperties.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/model_keyvaultproperties.go new file mode 100644 index 00000000000..8806a8cce9f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/model_keyvaultproperties.go @@ -0,0 +1,11 @@ +package encryptionscopes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type KeyVaultProperties struct { + IdentityClientId *string `json:"identityClientId,omitempty"` + KeyName *string `json:"keyName,omitempty"` + KeyVaultUri *string `json:"keyVaultUri,omitempty"` + KeyVersion *string `json:"keyVersion,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/predicates.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/predicates.go new file mode 100644 index 00000000000..03db73be113 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/predicates.go @@ -0,0 +1,32 @@ +package encryptionscopes + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type EncryptionScopeOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p EncryptionScopeOperationPredicate) Matches(input EncryptionScope) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + 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/cognitive/2023-10-01-preview/encryptionscopes/version.go b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/version.go new file mode 100644 index 00000000000..a4702a0f4d0 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/encryptionscopes/version.go @@ -0,0 +1,12 @@ +package encryptionscopes + +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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/encryptionscopes/%s", defaultApiVersion) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/README.md b/resource-manager/cognitive/2023-10-01-preview/models/README.md new file mode 100644 index 00000000000..f94a07987b1 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/models` Documentation + +The `models` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/models" +``` + + +### Client Initialization + +```go +client := models.NewModelsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ModelsClient.List` + +```go +ctx := context.TODO() +id := models.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/models/client.go b/resource-manager/cognitive/2023-10-01-preview/models/client.go new file mode 100644 index 00000000000..420b150ded1 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/client.go @@ -0,0 +1,26 @@ +package models + +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 ModelsClient struct { + Client *resourcemanager.Client +} + +func NewModelsClientWithBaseURI(sdkApi sdkEnv.Api) (*ModelsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "models", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ModelsClient: %+v", err) + } + + return &ModelsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/constants.go b/resource-manager/cognitive/2023-10-01-preview/models/constants.go new file mode 100644 index 00000000000..9b4e730c48c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/constants.go @@ -0,0 +1,51 @@ +package models + +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 ModelLifecycleStatus string + +const ( + ModelLifecycleStatusGenerallyAvailable ModelLifecycleStatus = "GenerallyAvailable" + ModelLifecycleStatusPreview ModelLifecycleStatus = "Preview" +) + +func PossibleValuesForModelLifecycleStatus() []string { + return []string{ + string(ModelLifecycleStatusGenerallyAvailable), + string(ModelLifecycleStatusPreview), + } +} + +func (s *ModelLifecycleStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseModelLifecycleStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseModelLifecycleStatus(input string) (*ModelLifecycleStatus, error) { + vals := map[string]ModelLifecycleStatus{ + "generallyavailable": ModelLifecycleStatusGenerallyAvailable, + "preview": ModelLifecycleStatusPreview, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ModelLifecycleStatus(input) + return &out, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/id_location.go b/resource-manager/cognitive/2023-10-01-preview/models/id_location.go new file mode 100644 index 00000000000..5c75e0fd52a --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/id_location.go @@ -0,0 +1,116 @@ +package models + +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.CognitiveServices/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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + 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/cognitive/2023-10-01-preview/models/id_location_test.go b/resource-manager/cognitive/2023-10-01-preview/models/id_location_test.go new file mode 100644 index 00000000000..c7c68de6f5d --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/id_location_test.go @@ -0,0 +1,237 @@ +package models + +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.CognitiveServices/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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/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.CognitiveServices/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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/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.CognitiveServices/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/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.cOgNiTiVeSeRvIcEs/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/cognitive/2023-10-01-preview/models/method_list.go b/resource-manager/cognitive/2023-10-01-preview/models/method_list.go new file mode 100644 index 00000000000..6c218b8edd2 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/method_list.go @@ -0,0 +1,91 @@ +package models + +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 *[]Model +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Model +} + +// List ... +func (c ModelsClient) List(ctx context.Context, id LocationId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/models", 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 *[]Model `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 ModelsClient) ListComplete(ctx context.Context, id LocationId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ModelOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ModelsClient) ListCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate ModelOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Model, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/model_accountmodel.go b/resource-manager/cognitive/2023-10-01-preview/models/model_accountmodel.go new file mode 100644 index 00000000000..cfcce9f5715 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/model_accountmodel.go @@ -0,0 +1,25 @@ +package models + +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 AccountModel struct { + BaseModel *DeploymentModel `json:"baseModel,omitempty"` + CallRateLimit *CallRateLimit `json:"callRateLimit,omitempty"` + Capabilities *map[string]string `json:"capabilities,omitempty"` + Deprecation *ModelDeprecationInfo `json:"deprecation,omitempty"` + FinetuneCapabilities *map[string]string `json:"finetuneCapabilities,omitempty"` + Format *string `json:"format,omitempty"` + IsDefaultVersion *bool `json:"isDefaultVersion,omitempty"` + LifecycleStatus *ModelLifecycleStatus `json:"lifecycleStatus,omitempty"` + MaxCapacity *int64 `json:"maxCapacity,omitempty"` + Name *string `json:"name,omitempty"` + Skus *[]ModelSku `json:"skus,omitempty"` + Source *string `json:"source,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/model_callratelimit.go b/resource-manager/cognitive/2023-10-01-preview/models/model_callratelimit.go new file mode 100644 index 00000000000..4b486177d22 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/model_callratelimit.go @@ -0,0 +1,10 @@ +package models + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CallRateLimit struct { + Count *float64 `json:"count,omitempty"` + RenewalPeriod *float64 `json:"renewalPeriod,omitempty"` + Rules *[]ThrottlingRule `json:"rules,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/model_capacityconfig.go b/resource-manager/cognitive/2023-10-01-preview/models/model_capacityconfig.go new file mode 100644 index 00000000000..6d019095535 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/model_capacityconfig.go @@ -0,0 +1,12 @@ +package models + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CapacityConfig struct { + AllowedValues *[]int64 `json:"allowedValues,omitempty"` + Default *int64 `json:"default,omitempty"` + Maximum *int64 `json:"maximum,omitempty"` + Minimum *int64 `json:"minimum,omitempty"` + Step *int64 `json:"step,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/model_deploymentmodel.go b/resource-manager/cognitive/2023-10-01-preview/models/model_deploymentmodel.go new file mode 100644 index 00000000000..90d184f1077 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/model_deploymentmodel.go @@ -0,0 +1,12 @@ +package models + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeploymentModel struct { + CallRateLimit *CallRateLimit `json:"callRateLimit,omitempty"` + Format *string `json:"format,omitempty"` + Name *string `json:"name,omitempty"` + Source *string `json:"source,omitempty"` + Version *string `json:"version,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/model_model.go b/resource-manager/cognitive/2023-10-01-preview/models/model_model.go new file mode 100644 index 00000000000..b9130018997 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/model_model.go @@ -0,0 +1,10 @@ +package models + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Model struct { + Kind *string `json:"kind,omitempty"` + Model *AccountModel `json:"model,omitempty"` + SkuName *string `json:"skuName,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/model_modeldeprecationinfo.go b/resource-manager/cognitive/2023-10-01-preview/models/model_modeldeprecationinfo.go new file mode 100644 index 00000000000..e3856468184 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/model_modeldeprecationinfo.go @@ -0,0 +1,9 @@ +package models + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ModelDeprecationInfo struct { + FineTune *string `json:"fineTune,omitempty"` + Inference *string `json:"inference,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/model_modelsku.go b/resource-manager/cognitive/2023-10-01-preview/models/model_modelsku.go new file mode 100644 index 00000000000..71a7b011de3 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/model_modelsku.go @@ -0,0 +1,30 @@ +package models + +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 ModelSku struct { + Capacity *CapacityConfig `json:"capacity,omitempty"` + DeprecationDate *string `json:"deprecationDate,omitempty"` + Name *string `json:"name,omitempty"` + RateLimits *[]CallRateLimit `json:"rateLimits,omitempty"` + UsageName *string `json:"usageName,omitempty"` +} + +func (o *ModelSku) GetDeprecationDateAsTime() (*time.Time, error) { + if o.DeprecationDate == nil { + return nil, nil + } + return dates.ParseAsFormat(o.DeprecationDate, "2006-01-02T15:04:05Z07:00") +} + +func (o *ModelSku) SetDeprecationDateAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.DeprecationDate = &formatted +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/model_requestmatchpattern.go b/resource-manager/cognitive/2023-10-01-preview/models/model_requestmatchpattern.go new file mode 100644 index 00000000000..082533b693a --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/model_requestmatchpattern.go @@ -0,0 +1,9 @@ +package models + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RequestMatchPattern struct { + Method *string `json:"method,omitempty"` + Path *string `json:"path,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/model_throttlingrule.go b/resource-manager/cognitive/2023-10-01-preview/models/model_throttlingrule.go new file mode 100644 index 00000000000..55a8dbeff7b --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/model_throttlingrule.go @@ -0,0 +1,13 @@ +package models + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ThrottlingRule struct { + Count *float64 `json:"count,omitempty"` + DynamicThrottlingEnabled *bool `json:"dynamicThrottlingEnabled,omitempty"` + Key *string `json:"key,omitempty"` + MatchPatterns *[]RequestMatchPattern `json:"matchPatterns,omitempty"` + MinCount *float64 `json:"minCount,omitempty"` + RenewalPeriod *float64 `json:"renewalPeriod,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/predicates.go b/resource-manager/cognitive/2023-10-01-preview/models/predicates.go new file mode 100644 index 00000000000..f557c1de06c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/predicates.go @@ -0,0 +1,22 @@ +package models + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ModelOperationPredicate struct { + Kind *string + SkuName *string +} + +func (p ModelOperationPredicate) Matches(input Model) bool { + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + return false + } + + if p.SkuName != nil && (input.SkuName == nil || *p.SkuName != *input.SkuName) { + return false + } + + return true +} diff --git a/resource-manager/cognitive/2023-10-01-preview/models/version.go b/resource-manager/cognitive/2023-10-01-preview/models/version.go new file mode 100644 index 00000000000..dcdbb86a0cd --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/models/version.go @@ -0,0 +1,12 @@ +package models + +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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/models/%s", defaultApiVersion) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/README.md b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/README.md new file mode 100644 index 00000000000..6fca1ad5862 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/README.md @@ -0,0 +1,81 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections` Documentation + +The `privateendpointconnections` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections" +``` + + +### Client Initialization + +```go +client := privateendpointconnections.NewPrivateEndpointConnectionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "privateEndpointConnectionValue") + +payload := privateendpointconnections.PrivateEndpointConnection{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Delete` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "privateEndpointConnectionValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.Get` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "privateEndpointConnectionValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PrivateEndpointConnectionsClient.List` + +```go +ctx := context.TODO() +id := privateendpointconnections.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/client.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/client.go new file mode 100644 index 00000000000..3bf7a6afe1f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/client.go @@ -0,0 +1,26 @@ +package privateendpointconnections + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionsClient struct { + Client *resourcemanager.Client +} + +func NewPrivateEndpointConnectionsClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateEndpointConnectionsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "privateendpointconnections", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateEndpointConnectionsClient: %+v", err) + } + + return &PrivateEndpointConnectionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/constants.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/constants.go new file mode 100644 index 00000000000..c5850609650 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/constants.go @@ -0,0 +1,101 @@ +package privateendpointconnections + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +func PossibleValuesForPrivateEndpointConnectionProvisioningState() []string { + return []string{ + string(PrivateEndpointConnectionProvisioningStateCreating), + string(PrivateEndpointConnectionProvisioningStateDeleting), + string(PrivateEndpointConnectionProvisioningStateFailed), + string(PrivateEndpointConnectionProvisioningStateSucceeded), + } +} + +func (s *PrivateEndpointConnectionProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointConnectionProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointConnectionProvisioningState(input string) (*PrivateEndpointConnectionProvisioningState, error) { + vals := map[string]PrivateEndpointConnectionProvisioningState{ + "creating": PrivateEndpointConnectionProvisioningStateCreating, + "deleting": PrivateEndpointConnectionProvisioningStateDeleting, + "failed": PrivateEndpointConnectionProvisioningStateFailed, + "succeeded": PrivateEndpointConnectionProvisioningStateSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointConnectionProvisioningState(input) + return &out, nil +} + +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateEndpointServiceConnectionStatus() []string { + return []string{ + string(PrivateEndpointServiceConnectionStatusApproved), + string(PrivateEndpointServiceConnectionStatusPending), + string(PrivateEndpointServiceConnectionStatusRejected), + } +} + +func (s *PrivateEndpointServiceConnectionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePrivateEndpointServiceConnectionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePrivateEndpointServiceConnectionStatus(input string) (*PrivateEndpointServiceConnectionStatus, error) { + vals := map[string]PrivateEndpointServiceConnectionStatus{ + "approved": PrivateEndpointServiceConnectionStatusApproved, + "pending": PrivateEndpointServiceConnectionStatusPending, + "rejected": PrivateEndpointServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateEndpointServiceConnectionStatus(input) + return &out, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_account.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_account.go new file mode 100644 index 00000000000..dd29b697445 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_account.go @@ -0,0 +1,125 @@ +package privateendpointconnections + +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 = &AccountId{} + +// AccountId is a struct representing the Resource ID for a Account +type AccountId struct { + SubscriptionId string + ResourceGroupName string + AccountName string +} + +// NewAccountID returns a new AccountId struct +func NewAccountID(subscriptionId string, resourceGroupName string, accountName string) AccountId { + return AccountId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + } +} + +// ParseAccountID parses 'input' into a AccountId +func ParseAccountID(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccountIDInsensitively parses 'input' case-insensitively into a AccountId +// note: this method should only be used for API response data and not user input +func ParseAccountIDInsensitively(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccountId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + return nil +} + +// ValidateAccountID checks that 'input' can be parsed as a Account ID +func ValidateAccountID(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 := ParseAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Account ID +func (id AccountId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Account ID +func (id AccountId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + } +} + +// String returns a human-readable description of this Account ID +func (id AccountId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + } + return fmt.Sprintf("Account (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_account_test.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_account_test.go new file mode 100644 index 00000000000..9898028f60d --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_account_test.go @@ -0,0 +1,282 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AccountId{} + +func TestNewAccountID(t *testing.T) { + id := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } +} + +func TestFormatAccountID(t *testing.T) { + actual := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccountID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestParseAccountIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestSegmentsForAccountId(t *testing.T) { + segments := AccountId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccountId 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/cognitive/2023-10-01-preview/privateendpointconnections/id_privateendpointconnection.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_privateendpointconnection.go new file mode 100644 index 00000000000..5b7122e1f99 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_privateendpointconnection.go @@ -0,0 +1,134 @@ +package privateendpointconnections + +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 = &PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + AccountName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, accountName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(&PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PrivateEndpointConnectionId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PrivateEndpointConnectionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + if id.PrivateEndpointConnectionName, ok = input.Parsed["privateEndpointConnectionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "privateEndpointConnectionName", input) + } + + return nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_privateendpointconnection_test.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..f78fc254039 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/id_privateendpointconnection_test.go @@ -0,0 +1,327 @@ +package privateendpointconnections + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "privateEndpointConnectionValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_createorupdate.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_createorupdate.go new file mode 100644 index 00000000000..943007e4641 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_createorupdate.go @@ -0,0 +1,75 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// CreateOrUpdate ... +func (c PrivateEndpointConnectionsClient) CreateOrUpdate(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c PrivateEndpointConnectionsClient) CreateOrUpdateThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_delete.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_delete.go new file mode 100644 index 00000000000..63c26e8f27f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_delete.go @@ -0,0 +1,71 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c PrivateEndpointConnectionsClient) Delete(ctx context.Context, id PrivateEndpointConnectionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c PrivateEndpointConnectionsClient) DeleteThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_get.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_get.go new file mode 100644 index 00000000000..8dc28d7ff7a --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_get.go @@ -0,0 +1,54 @@ +package privateendpointconnections + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnection +} + +// Get ... +func (c PrivateEndpointConnectionsClient) Get(ctx context.Context, id PrivateEndpointConnectionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnection + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_list.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_list.go new file mode 100644 index 00000000000..1da156ba99e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/method_list.go @@ -0,0 +1,55 @@ +package privateendpointconnections + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateEndpointConnectionListResult +} + +// List ... +func (c PrivateEndpointConnectionsClient) List(ctx context.Context, id AccountId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateEndpointConnections", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateEndpointConnectionListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpoint.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpoint.go new file mode 100644 index 00000000000..1bc8cf2a97c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpoint.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpointconnection.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpointconnection.go new file mode 100644 index 00000000000..647e922db00 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpointconnection.go @@ -0,0 +1,18 @@ +package privateendpointconnections + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnection struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateEndpointConnectionProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpointconnectionlistresult.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpointconnectionlistresult.go new file mode 100644 index 00000000000..92a9ecb105a --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpointconnectionlistresult.go @@ -0,0 +1,8 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionListResult struct { + Value *[]PrivateEndpointConnection `json:"value,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..fb540c904b6 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privateendpointconnectionproperties.go @@ -0,0 +1,11 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + GroupIds *[]string `json:"groupIds,omitempty"` + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` + ProvisioningState *PrivateEndpointConnectionProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstate.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..ec3f7a9f24c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package privateendpointconnections + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description *string `json:"description,omitempty"` + Status *PrivateEndpointServiceConnectionStatus `json:"status,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/version.go b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/version.go new file mode 100644 index 00000000000..6aced303ba5 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privateendpointconnections/version.go @@ -0,0 +1,12 @@ +package privateendpointconnections + +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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privateendpointconnections/%s", defaultApiVersion) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/README.md b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/README.md new file mode 100644 index 00000000000..e8e7464d1c6 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/privatelinkresources` Documentation + +The `privatelinkresources` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/privatelinkresources" +``` + + +### Client Initialization + +```go +client := privatelinkresources.NewPrivateLinkResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PrivateLinkResourcesClient.List` + +```go +ctx := context.TODO() +id := privatelinkresources.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +read, err := client.List(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/client.go b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/client.go new file mode 100644 index 00000000000..e6e22caa746 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/client.go @@ -0,0 +1,26 @@ +package privatelinkresources + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourcesClient struct { + Client *resourcemanager.Client +} + +func NewPrivateLinkResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*PrivateLinkResourcesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "privatelinkresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PrivateLinkResourcesClient: %+v", err) + } + + return &PrivateLinkResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/id_account.go b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/id_account.go new file mode 100644 index 00000000000..8c12b95071d --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/id_account.go @@ -0,0 +1,125 @@ +package privatelinkresources + +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 = &AccountId{} + +// AccountId is a struct representing the Resource ID for a Account +type AccountId struct { + SubscriptionId string + ResourceGroupName string + AccountName string +} + +// NewAccountID returns a new AccountId struct +func NewAccountID(subscriptionId string, resourceGroupName string, accountName string) AccountId { + return AccountId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + } +} + +// ParseAccountID parses 'input' into a AccountId +func ParseAccountID(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccountIDInsensitively parses 'input' case-insensitively into a AccountId +// note: this method should only be used for API response data and not user input +func ParseAccountIDInsensitively(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccountId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + return nil +} + +// ValidateAccountID checks that 'input' can be parsed as a Account ID +func ValidateAccountID(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 := ParseAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Account ID +func (id AccountId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Account ID +func (id AccountId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + } +} + +// String returns a human-readable description of this Account ID +func (id AccountId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + } + return fmt.Sprintf("Account (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/id_account_test.go b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/id_account_test.go new file mode 100644 index 00000000000..ec1cc536c02 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/id_account_test.go @@ -0,0 +1,282 @@ +package privatelinkresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AccountId{} + +func TestNewAccountID(t *testing.T) { + id := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } +} + +func TestFormatAccountID(t *testing.T) { + actual := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccountID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestParseAccountIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestSegmentsForAccountId(t *testing.T) { + segments := AccountId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccountId 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/cognitive/2023-10-01-preview/privatelinkresources/method_list.go b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/method_list.go new file mode 100644 index 00000000000..a5772a8c49c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/method_list.go @@ -0,0 +1,55 @@ +package privatelinkresources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PrivateLinkResourceListResult +} + +// List ... +func (c PrivateLinkResourcesClient) List(ctx context.Context, id AccountId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/privateLinkResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PrivateLinkResourceListResult + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/model_privatelinkresource.go b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/model_privatelinkresource.go new file mode 100644 index 00000000000..69e8ae0e57a --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/model_privatelinkresource.go @@ -0,0 +1,11 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PrivateLinkResourceProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/model_privatelinkresourcelistresult.go b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/model_privatelinkresourcelistresult.go new file mode 100644 index 00000000000..fa950217c47 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/model_privatelinkresourcelistresult.go @@ -0,0 +1,8 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceListResult struct { + Value *[]PrivateLinkResource `json:"value,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/model_privatelinkresourceproperties.go b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/model_privatelinkresourceproperties.go new file mode 100644 index 00000000000..b20a6aab034 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/model_privatelinkresourceproperties.go @@ -0,0 +1,11 @@ +package privatelinkresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResourceProperties struct { + DisplayName *string `json:"displayName,omitempty"` + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/version.go b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/version.go new file mode 100644 index 00000000000..7093fcb3bc2 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/privatelinkresources/version.go @@ -0,0 +1,12 @@ +package privatelinkresources + +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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/privatelinkresources/%s", defaultApiVersion) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/README.md b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/README.md new file mode 100644 index 00000000000..0487017b9a8 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/README.md @@ -0,0 +1,152 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/raiblocklists` Documentation + +The `raiblocklists` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/raiblocklists" +``` + + +### Client Initialization + +```go +client := raiblocklists.NewRaiBlocklistsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RaiBlocklistsClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := raiblocklists.NewRaiBlocklistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiBlocklistValue") + +payload := raiblocklists.RaiBlocklist{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RaiBlocklistsClient.Delete` + +```go +ctx := context.TODO() +id := raiblocklists.NewRaiBlocklistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiBlocklistValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RaiBlocklistsClient.Get` + +```go +ctx := context.TODO() +id := raiblocklists.NewRaiBlocklistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiBlocklistValue") + +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: `RaiBlocklistsClient.List` + +```go +ctx := context.TODO() +id := raiblocklists.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `RaiBlocklistsClient.RaiBlocklistItemsCreateOrUpdate` + +```go +ctx := context.TODO() +id := raiblocklists.NewRaiBlocklistItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiBlocklistValue", "raiBlocklistItemValue") + +payload := raiblocklists.RaiBlocklistItem{ + // ... +} + + +read, err := client.RaiBlocklistItemsCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RaiBlocklistsClient.RaiBlocklistItemsDelete` + +```go +ctx := context.TODO() +id := raiblocklists.NewRaiBlocklistItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiBlocklistValue", "raiBlocklistItemValue") + +if err := client.RaiBlocklistItemsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RaiBlocklistsClient.RaiBlocklistItemsGet` + +```go +ctx := context.TODO() +id := raiblocklists.NewRaiBlocklistItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiBlocklistValue", "raiBlocklistItemValue") + +read, err := client.RaiBlocklistItemsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RaiBlocklistsClient.RaiBlocklistItemsList` + +```go +ctx := context.TODO() +id := raiblocklists.NewRaiBlocklistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiBlocklistValue") + +// alternatively `client.RaiBlocklistItemsList(ctx, id)` can be used to do batched pagination +items, err := client.RaiBlocklistItemsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/client.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/client.go new file mode 100644 index 00000000000..64c359bae8f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/client.go @@ -0,0 +1,26 @@ +package raiblocklists + +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 RaiBlocklistsClient struct { + Client *resourcemanager.Client +} + +func NewRaiBlocklistsClientWithBaseURI(sdkApi sdkEnv.Api) (*RaiBlocklistsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "raiblocklists", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RaiBlocklistsClient: %+v", err) + } + + return &RaiBlocklistsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_account.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_account.go new file mode 100644 index 00000000000..bd6323bf785 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_account.go @@ -0,0 +1,125 @@ +package raiblocklists + +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 = &AccountId{} + +// AccountId is a struct representing the Resource ID for a Account +type AccountId struct { + SubscriptionId string + ResourceGroupName string + AccountName string +} + +// NewAccountID returns a new AccountId struct +func NewAccountID(subscriptionId string, resourceGroupName string, accountName string) AccountId { + return AccountId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + } +} + +// ParseAccountID parses 'input' into a AccountId +func ParseAccountID(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccountIDInsensitively parses 'input' case-insensitively into a AccountId +// note: this method should only be used for API response data and not user input +func ParseAccountIDInsensitively(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccountId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + return nil +} + +// ValidateAccountID checks that 'input' can be parsed as a Account ID +func ValidateAccountID(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 := ParseAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Account ID +func (id AccountId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Account ID +func (id AccountId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + } +} + +// String returns a human-readable description of this Account ID +func (id AccountId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + } + return fmt.Sprintf("Account (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_account_test.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_account_test.go new file mode 100644 index 00000000000..a4311cdd203 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_account_test.go @@ -0,0 +1,282 @@ +package raiblocklists + +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 = &AccountId{} + +func TestNewAccountID(t *testing.T) { + id := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } +} + +func TestFormatAccountID(t *testing.T) { + actual := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccountID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestParseAccountIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestSegmentsForAccountId(t *testing.T) { + segments := AccountId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccountId 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/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklist.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklist.go new file mode 100644 index 00000000000..7de76f94d8c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklist.go @@ -0,0 +1,134 @@ +package raiblocklists + +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 = &RaiBlocklistId{} + +// RaiBlocklistId is a struct representing the Resource ID for a Rai Blocklist +type RaiBlocklistId struct { + SubscriptionId string + ResourceGroupName string + AccountName string + RaiBlocklistName string +} + +// NewRaiBlocklistID returns a new RaiBlocklistId struct +func NewRaiBlocklistID(subscriptionId string, resourceGroupName string, accountName string, raiBlocklistName string) RaiBlocklistId { + return RaiBlocklistId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + RaiBlocklistName: raiBlocklistName, + } +} + +// ParseRaiBlocklistID parses 'input' into a RaiBlocklistId +func ParseRaiBlocklistID(input string) (*RaiBlocklistId, error) { + parser := resourceids.NewParserFromResourceIdType(&RaiBlocklistId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RaiBlocklistId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRaiBlocklistIDInsensitively parses 'input' case-insensitively into a RaiBlocklistId +// note: this method should only be used for API response data and not user input +func ParseRaiBlocklistIDInsensitively(input string) (*RaiBlocklistId, error) { + parser := resourceids.NewParserFromResourceIdType(&RaiBlocklistId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RaiBlocklistId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RaiBlocklistId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + if id.RaiBlocklistName, ok = input.Parsed["raiBlocklistName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "raiBlocklistName", input) + } + + return nil +} + +// ValidateRaiBlocklistID checks that 'input' can be parsed as a Rai Blocklist ID +func ValidateRaiBlocklistID(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 := ParseRaiBlocklistID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Rai Blocklist ID +func (id RaiBlocklistId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s/raiBlocklists/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName, id.RaiBlocklistName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Rai Blocklist ID +func (id RaiBlocklistId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + resourceids.StaticSegment("staticRaiBlocklists", "raiBlocklists", "raiBlocklists"), + resourceids.UserSpecifiedSegment("raiBlocklistName", "raiBlocklistValue"), + } +} + +// String returns a human-readable description of this Rai Blocklist ID +func (id RaiBlocklistId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + fmt.Sprintf("Rai Blocklist Name: %q", id.RaiBlocklistName), + } + return fmt.Sprintf("Rai Blocklist (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklist_test.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklist_test.go new file mode 100644 index 00000000000..6be7ef464ca --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklist_test.go @@ -0,0 +1,327 @@ +package raiblocklists + +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 = &RaiBlocklistId{} + +func TestNewRaiBlocklistID(t *testing.T) { + id := NewRaiBlocklistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiBlocklistValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } + + if id.RaiBlocklistName != "raiBlocklistValue" { + t.Fatalf("Expected %q but got %q for Segment 'RaiBlocklistName'", id.RaiBlocklistName, "raiBlocklistValue") + } +} + +func TestFormatRaiBlocklistID(t *testing.T) { + actual := NewRaiBlocklistID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiBlocklistValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRaiBlocklistID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RaiBlocklistId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue", + Expected: &RaiBlocklistId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + RaiBlocklistName: "raiBlocklistValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRaiBlocklistID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.RaiBlocklistName != v.Expected.RaiBlocklistName { + t.Fatalf("Expected %q but got %q for RaiBlocklistName", v.Expected.RaiBlocklistName, actual.RaiBlocklistName) + } + + } +} + +func TestParseRaiBlocklistIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RaiBlocklistId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/rAiBlOcKlIsTs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue", + Expected: &RaiBlocklistId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + RaiBlocklistName: "raiBlocklistValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/rAiBlOcKlIsTs/rAiBlOcKlIsTvAlUe", + Expected: &RaiBlocklistId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + RaiBlocklistName: "rAiBlOcKlIsTvAlUe", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/rAiBlOcKlIsTs/rAiBlOcKlIsTvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRaiBlocklistIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.RaiBlocklistName != v.Expected.RaiBlocklistName { + t.Fatalf("Expected %q but got %q for RaiBlocklistName", v.Expected.RaiBlocklistName, actual.RaiBlocklistName) + } + + } +} + +func TestSegmentsForRaiBlocklistId(t *testing.T) { + segments := RaiBlocklistId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RaiBlocklistId 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/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklistitem.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklistitem.go new file mode 100644 index 00000000000..ceacc76301f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklistitem.go @@ -0,0 +1,143 @@ +package raiblocklists + +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 = &RaiBlocklistItemId{} + +// RaiBlocklistItemId is a struct representing the Resource ID for a Rai Blocklist Item +type RaiBlocklistItemId struct { + SubscriptionId string + ResourceGroupName string + AccountName string + RaiBlocklistName string + RaiBlocklistItemName string +} + +// NewRaiBlocklistItemID returns a new RaiBlocklistItemId struct +func NewRaiBlocklistItemID(subscriptionId string, resourceGroupName string, accountName string, raiBlocklistName string, raiBlocklistItemName string) RaiBlocklistItemId { + return RaiBlocklistItemId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + RaiBlocklistName: raiBlocklistName, + RaiBlocklistItemName: raiBlocklistItemName, + } +} + +// ParseRaiBlocklistItemID parses 'input' into a RaiBlocklistItemId +func ParseRaiBlocklistItemID(input string) (*RaiBlocklistItemId, error) { + parser := resourceids.NewParserFromResourceIdType(&RaiBlocklistItemId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RaiBlocklistItemId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRaiBlocklistItemIDInsensitively parses 'input' case-insensitively into a RaiBlocklistItemId +// note: this method should only be used for API response data and not user input +func ParseRaiBlocklistItemIDInsensitively(input string) (*RaiBlocklistItemId, error) { + parser := resourceids.NewParserFromResourceIdType(&RaiBlocklistItemId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RaiBlocklistItemId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RaiBlocklistItemId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + if id.RaiBlocklistName, ok = input.Parsed["raiBlocklistName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "raiBlocklistName", input) + } + + if id.RaiBlocklistItemName, ok = input.Parsed["raiBlocklistItemName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "raiBlocklistItemName", input) + } + + return nil +} + +// ValidateRaiBlocklistItemID checks that 'input' can be parsed as a Rai Blocklist Item ID +func ValidateRaiBlocklistItemID(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 := ParseRaiBlocklistItemID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Rai Blocklist Item ID +func (id RaiBlocklistItemId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s/raiBlocklists/%s/raiBlocklistItems/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName, id.RaiBlocklistName, id.RaiBlocklistItemName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Rai Blocklist Item ID +func (id RaiBlocklistItemId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + resourceids.StaticSegment("staticRaiBlocklists", "raiBlocklists", "raiBlocklists"), + resourceids.UserSpecifiedSegment("raiBlocklistName", "raiBlocklistValue"), + resourceids.StaticSegment("staticRaiBlocklistItems", "raiBlocklistItems", "raiBlocklistItems"), + resourceids.UserSpecifiedSegment("raiBlocklistItemName", "raiBlocklistItemValue"), + } +} + +// String returns a human-readable description of this Rai Blocklist Item ID +func (id RaiBlocklistItemId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + fmt.Sprintf("Rai Blocklist Name: %q", id.RaiBlocklistName), + fmt.Sprintf("Rai Blocklist Item Name: %q", id.RaiBlocklistItemName), + } + return fmt.Sprintf("Rai Blocklist Item (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklistitem_test.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklistitem_test.go new file mode 100644 index 00000000000..986000f6737 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/id_raiblocklistitem_test.go @@ -0,0 +1,372 @@ +package raiblocklists + +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 = &RaiBlocklistItemId{} + +func TestNewRaiBlocklistItemID(t *testing.T) { + id := NewRaiBlocklistItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiBlocklistValue", "raiBlocklistItemValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } + + if id.RaiBlocklistName != "raiBlocklistValue" { + t.Fatalf("Expected %q but got %q for Segment 'RaiBlocklistName'", id.RaiBlocklistName, "raiBlocklistValue") + } + + if id.RaiBlocklistItemName != "raiBlocklistItemValue" { + t.Fatalf("Expected %q but got %q for Segment 'RaiBlocklistItemName'", id.RaiBlocklistItemName, "raiBlocklistItemValue") + } +} + +func TestFormatRaiBlocklistItemID(t *testing.T) { + actual := NewRaiBlocklistItemID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiBlocklistValue", "raiBlocklistItemValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue/raiBlocklistItems/raiBlocklistItemValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRaiBlocklistItemID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RaiBlocklistItemId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue/raiBlocklistItems", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue/raiBlocklistItems/raiBlocklistItemValue", + Expected: &RaiBlocklistItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + RaiBlocklistName: "raiBlocklistValue", + RaiBlocklistItemName: "raiBlocklistItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue/raiBlocklistItems/raiBlocklistItemValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRaiBlocklistItemID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.RaiBlocklistName != v.Expected.RaiBlocklistName { + t.Fatalf("Expected %q but got %q for RaiBlocklistName", v.Expected.RaiBlocklistName, actual.RaiBlocklistName) + } + + if actual.RaiBlocklistItemName != v.Expected.RaiBlocklistItemName { + t.Fatalf("Expected %q but got %q for RaiBlocklistItemName", v.Expected.RaiBlocklistItemName, actual.RaiBlocklistItemName) + } + + } +} + +func TestParseRaiBlocklistItemIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RaiBlocklistItemId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/rAiBlOcKlIsTs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/rAiBlOcKlIsTs/rAiBlOcKlIsTvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue/raiBlocklistItems", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/rAiBlOcKlIsTs/rAiBlOcKlIsTvAlUe/rAiBlOcKlIsTiTeMs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue/raiBlocklistItems/raiBlocklistItemValue", + Expected: &RaiBlocklistItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + RaiBlocklistName: "raiBlocklistValue", + RaiBlocklistItemName: "raiBlocklistItemValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiBlocklists/raiBlocklistValue/raiBlocklistItems/raiBlocklistItemValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/rAiBlOcKlIsTs/rAiBlOcKlIsTvAlUe/rAiBlOcKlIsTiTeMs/rAiBlOcKlIsTiTeMvAlUe", + Expected: &RaiBlocklistItemId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + RaiBlocklistName: "rAiBlOcKlIsTvAlUe", + RaiBlocklistItemName: "rAiBlOcKlIsTiTeMvAlUe", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/rAiBlOcKlIsTs/rAiBlOcKlIsTvAlUe/rAiBlOcKlIsTiTeMs/rAiBlOcKlIsTiTeMvAlUe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRaiBlocklistItemIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.RaiBlocklistName != v.Expected.RaiBlocklistName { + t.Fatalf("Expected %q but got %q for RaiBlocklistName", v.Expected.RaiBlocklistName, actual.RaiBlocklistName) + } + + if actual.RaiBlocklistItemName != v.Expected.RaiBlocklistItemName { + t.Fatalf("Expected %q but got %q for RaiBlocklistItemName", v.Expected.RaiBlocklistItemName, actual.RaiBlocklistItemName) + } + + } +} + +func TestSegmentsForRaiBlocklistItemId(t *testing.T) { + segments := RaiBlocklistItemId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RaiBlocklistItemId 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/cognitive/2023-10-01-preview/raiblocklists/method_createorupdate.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_createorupdate.go new file mode 100644 index 00000000000..9bcd2f53455 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_createorupdate.go @@ -0,0 +1,59 @@ +package raiblocklists + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RaiBlocklist +} + +// CreateOrUpdate ... +func (c RaiBlocklistsClient) CreateOrUpdate(ctx context.Context, id RaiBlocklistId, input RaiBlocklist) (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 + } + + var model RaiBlocklist + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_delete.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_delete.go new file mode 100644 index 00000000000..621e422780f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_delete.go @@ -0,0 +1,70 @@ +package raiblocklists + +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 RaiBlocklistsClient) Delete(ctx context.Context, id RaiBlocklistId) (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 RaiBlocklistsClient) DeleteThenPoll(ctx context.Context, id RaiBlocklistId) 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/cognitive/2023-10-01-preview/raiblocklists/method_get.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_get.go new file mode 100644 index 00000000000..14d4705b0af --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_get.go @@ -0,0 +1,54 @@ +package raiblocklists + +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 *RaiBlocklist +} + +// Get ... +func (c RaiBlocklistsClient) Get(ctx context.Context, id RaiBlocklistId) (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 RaiBlocklist + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_list.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_list.go new file mode 100644 index 00000000000..0982a03ab43 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_list.go @@ -0,0 +1,91 @@ +package raiblocklists + +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 *[]RaiBlocklist +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RaiBlocklist +} + +// List ... +func (c RaiBlocklistsClient) List(ctx context.Context, id AccountId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/raiBlocklists", 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 *[]RaiBlocklist `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 RaiBlocklistsClient) ListComplete(ctx context.Context, id AccountId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, RaiBlocklistOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RaiBlocklistsClient) ListCompleteMatchingPredicate(ctx context.Context, id AccountId, predicate RaiBlocklistOperationPredicate) (result ListCompleteResult, err error) { + items := make([]RaiBlocklist, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemscreateorupdate.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemscreateorupdate.go new file mode 100644 index 00000000000..a28cc0a0d99 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemscreateorupdate.go @@ -0,0 +1,59 @@ +package raiblocklists + +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 RaiBlocklistItemsCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RaiBlocklistItem +} + +// RaiBlocklistItemsCreateOrUpdate ... +func (c RaiBlocklistsClient) RaiBlocklistItemsCreateOrUpdate(ctx context.Context, id RaiBlocklistItemId, input RaiBlocklistItem) (result RaiBlocklistItemsCreateOrUpdateOperationResponse, 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 RaiBlocklistItem + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemsdelete.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemsdelete.go new file mode 100644 index 00000000000..b832a825b54 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemsdelete.go @@ -0,0 +1,70 @@ +package raiblocklists + +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 RaiBlocklistItemsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// RaiBlocklistItemsDelete ... +func (c RaiBlocklistsClient) RaiBlocklistItemsDelete(ctx context.Context, id RaiBlocklistItemId) (result RaiBlocklistItemsDeleteOperationResponse, 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 +} + +// RaiBlocklistItemsDeleteThenPoll performs RaiBlocklistItemsDelete then polls until it's completed +func (c RaiBlocklistsClient) RaiBlocklistItemsDeleteThenPoll(ctx context.Context, id RaiBlocklistItemId) error { + result, err := c.RaiBlocklistItemsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing RaiBlocklistItemsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after RaiBlocklistItemsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemsget.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemsget.go new file mode 100644 index 00000000000..76cb8b2a723 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemsget.go @@ -0,0 +1,54 @@ +package raiblocklists + +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 RaiBlocklistItemsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RaiBlocklistItem +} + +// RaiBlocklistItemsGet ... +func (c RaiBlocklistsClient) RaiBlocklistItemsGet(ctx context.Context, id RaiBlocklistItemId) (result RaiBlocklistItemsGetOperationResponse, 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 RaiBlocklistItem + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemslist.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemslist.go new file mode 100644 index 00000000000..01af65fdf4c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/method_raiblocklistitemslist.go @@ -0,0 +1,91 @@ +package raiblocklists + +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 RaiBlocklistItemsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RaiBlocklistItem +} + +type RaiBlocklistItemsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RaiBlocklistItem +} + +// RaiBlocklistItemsList ... +func (c RaiBlocklistsClient) RaiBlocklistItemsList(ctx context.Context, id RaiBlocklistId) (result RaiBlocklistItemsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/raiBlocklistItems", 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 *[]RaiBlocklistItem `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// RaiBlocklistItemsListComplete retrieves all the results into a single object +func (c RaiBlocklistsClient) RaiBlocklistItemsListComplete(ctx context.Context, id RaiBlocklistId) (RaiBlocklistItemsListCompleteResult, error) { + return c.RaiBlocklistItemsListCompleteMatchingPredicate(ctx, id, RaiBlocklistItemOperationPredicate{}) +} + +// RaiBlocklistItemsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RaiBlocklistsClient) RaiBlocklistItemsListCompleteMatchingPredicate(ctx context.Context, id RaiBlocklistId, predicate RaiBlocklistItemOperationPredicate) (result RaiBlocklistItemsListCompleteResult, err error) { + items := make([]RaiBlocklistItem, 0) + + resp, err := c.RaiBlocklistItemsList(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 = RaiBlocklistItemsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklist.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklist.go new file mode 100644 index 00000000000..8be491a1b59 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklist.go @@ -0,0 +1,18 @@ +package raiblocklists + +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 RaiBlocklist struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RaiBlocklistProperties `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/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklistitem.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklistitem.go new file mode 100644 index 00000000000..98bd2267f96 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklistitem.go @@ -0,0 +1,18 @@ +package raiblocklists + +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 RaiBlocklistItem struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RaiBlocklistItemProperties `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/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklistitemproperties.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklistitemproperties.go new file mode 100644 index 00000000000..f6b4e7ca37a --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklistitemproperties.go @@ -0,0 +1,9 @@ +package raiblocklists + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RaiBlocklistItemProperties struct { + IsRegex *bool `json:"isRegex,omitempty"` + Pattern *string `json:"pattern,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklistproperties.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklistproperties.go new file mode 100644 index 00000000000..816f9b75e26 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/model_raiblocklistproperties.go @@ -0,0 +1,8 @@ +package raiblocklists + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RaiBlocklistProperties struct { + Description *string `json:"description,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raiblocklists/predicates.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/predicates.go new file mode 100644 index 00000000000..a317e1c7318 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/predicates.go @@ -0,0 +1,60 @@ +package raiblocklists + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RaiBlocklistOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p RaiBlocklistOperationPredicate) Matches(input RaiBlocklist) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + 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 RaiBlocklistItemOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p RaiBlocklistItemOperationPredicate) Matches(input RaiBlocklistItem) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + 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/cognitive/2023-10-01-preview/raiblocklists/version.go b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/version.go new file mode 100644 index 00000000000..c529ffb2d97 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raiblocklists/version.go @@ -0,0 +1,12 @@ +package raiblocklists + +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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/raiblocklists/%s", defaultApiVersion) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/README.md b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/README.md new file mode 100644 index 00000000000..e84e9a08566 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/raicontentfilters` Documentation + +The `raicontentfilters` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/raicontentfilters" +``` + + +### Client Initialization + +```go +client := raicontentfilters.NewRaiContentFiltersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RaiContentFiltersClient.List` + +```go +ctx := context.TODO() +id := raicontentfilters.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/client.go b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/client.go new file mode 100644 index 00000000000..eb82011a3c8 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/client.go @@ -0,0 +1,26 @@ +package raicontentfilters + +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 RaiContentFiltersClient struct { + Client *resourcemanager.Client +} + +func NewRaiContentFiltersClientWithBaseURI(sdkApi sdkEnv.Api) (*RaiContentFiltersClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "raicontentfilters", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RaiContentFiltersClient: %+v", err) + } + + return &RaiContentFiltersClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/constants.go b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/constants.go new file mode 100644 index 00000000000..23eabbddbc6 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/constants.go @@ -0,0 +1,51 @@ +package raicontentfilters + +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 RaiContentFilterType string + +const ( + RaiContentFilterTypeMultiLevel RaiContentFilterType = "MultiLevel" + RaiContentFilterTypeSwitch RaiContentFilterType = "Switch" +) + +func PossibleValuesForRaiContentFilterType() []string { + return []string{ + string(RaiContentFilterTypeMultiLevel), + string(RaiContentFilterTypeSwitch), + } +} + +func (s *RaiContentFilterType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRaiContentFilterType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRaiContentFilterType(input string) (*RaiContentFilterType, error) { + vals := map[string]RaiContentFilterType{ + "multilevel": RaiContentFilterTypeMultiLevel, + "switch": RaiContentFilterTypeSwitch, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RaiContentFilterType(input) + return &out, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/id_location.go b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/id_location.go new file mode 100644 index 00000000000..2a8e4ff5946 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/id_location.go @@ -0,0 +1,116 @@ +package raicontentfilters + +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.CognitiveServices/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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + 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/cognitive/2023-10-01-preview/raicontentfilters/id_location_test.go b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/id_location_test.go new file mode 100644 index 00000000000..18ca7f5c59b --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/id_location_test.go @@ -0,0 +1,237 @@ +package raicontentfilters + +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.CognitiveServices/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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/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.CognitiveServices/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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/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.CognitiveServices/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/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.cOgNiTiVeSeRvIcEs/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/cognitive/2023-10-01-preview/raicontentfilters/method_list.go b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/method_list.go new file mode 100644 index 00000000000..cafc3460178 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/method_list.go @@ -0,0 +1,91 @@ +package raicontentfilters + +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 *[]RaiContentFilter +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RaiContentFilter +} + +// List ... +func (c RaiContentFiltersClient) List(ctx context.Context, id LocationId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/raiContentFilters", 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 *[]RaiContentFilter `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 RaiContentFiltersClient) ListComplete(ctx context.Context, id LocationId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, RaiContentFilterOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RaiContentFiltersClient) ListCompleteMatchingPredicate(ctx context.Context, id LocationId, predicate RaiContentFilterOperationPredicate) (result ListCompleteResult, err error) { + items := make([]RaiContentFilter, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/model_raicontentfilter.go b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/model_raicontentfilter.go new file mode 100644 index 00000000000..df6cb86adb5 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/model_raicontentfilter.go @@ -0,0 +1,10 @@ +package raicontentfilters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RaiContentFilter struct { + Description *string `json:"description,omitempty"` + FilterType *RaiContentFilterType `json:"filterType,omitempty"` + PolicyName *string `json:"policyName,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/predicates.go b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/predicates.go new file mode 100644 index 00000000000..6deb908c012 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/predicates.go @@ -0,0 +1,22 @@ +package raicontentfilters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RaiContentFilterOperationPredicate struct { + Description *string + PolicyName *string +} + +func (p RaiContentFilterOperationPredicate) Matches(input RaiContentFilter) bool { + + if p.Description != nil && (input.Description == nil || *p.Description != *input.Description) { + return false + } + + if p.PolicyName != nil && (input.PolicyName == nil || *p.PolicyName != *input.PolicyName) { + return false + } + + return true +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/version.go b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/version.go new file mode 100644 index 00000000000..c87c8983a9d --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raicontentfilters/version.go @@ -0,0 +1,12 @@ +package raicontentfilters + +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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/raicontentfilters/%s", defaultApiVersion) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raipolicies/README.md b/resource-manager/cognitive/2023-10-01-preview/raipolicies/README.md new file mode 100644 index 00000000000..c8cfce8ed0b --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/README.md @@ -0,0 +1,86 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/raipolicies` Documentation + +The `raipolicies` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/raipolicies" +``` + + +### Client Initialization + +```go +client := raipolicies.NewRaiPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RaiPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := raipolicies.NewRaiPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiPolicyValue") + +payload := raipolicies.RaiPolicy{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RaiPoliciesClient.Delete` + +```go +ctx := context.TODO() +id := raipolicies.NewRaiPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiPolicyValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RaiPoliciesClient.Get` + +```go +ctx := context.TODO() +id := raipolicies.NewRaiPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiPolicyValue") + +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: `RaiPoliciesClient.List` + +```go +ctx := context.TODO() +id := raipolicies.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/raipolicies/client.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/client.go new file mode 100644 index 00000000000..0d0c51b52ca --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/client.go @@ -0,0 +1,26 @@ +package raipolicies + +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 RaiPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewRaiPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*RaiPoliciesClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "raipolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RaiPoliciesClient: %+v", err) + } + + return &RaiPoliciesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raipolicies/constants.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/constants.go new file mode 100644 index 00000000000..b9e667662f1 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/constants.go @@ -0,0 +1,180 @@ +package raipolicies + +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 AllowedContentLevel string + +const ( + AllowedContentLevelHigh AllowedContentLevel = "High" + AllowedContentLevelLow AllowedContentLevel = "Low" + AllowedContentLevelMedium AllowedContentLevel = "Medium" +) + +func PossibleValuesForAllowedContentLevel() []string { + return []string{ + string(AllowedContentLevelHigh), + string(AllowedContentLevelLow), + string(AllowedContentLevelMedium), + } +} + +func (s *AllowedContentLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAllowedContentLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAllowedContentLevel(input string) (*AllowedContentLevel, error) { + vals := map[string]AllowedContentLevel{ + "high": AllowedContentLevelHigh, + "low": AllowedContentLevelLow, + "medium": AllowedContentLevelMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AllowedContentLevel(input) + return &out, nil +} + +type RaiPolicyContentSource string + +const ( + RaiPolicyContentSourceCompletion RaiPolicyContentSource = "Completion" + RaiPolicyContentSourcePrompt RaiPolicyContentSource = "Prompt" +) + +func PossibleValuesForRaiPolicyContentSource() []string { + return []string{ + string(RaiPolicyContentSourceCompletion), + string(RaiPolicyContentSourcePrompt), + } +} + +func (s *RaiPolicyContentSource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRaiPolicyContentSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRaiPolicyContentSource(input string) (*RaiPolicyContentSource, error) { + vals := map[string]RaiPolicyContentSource{ + "completion": RaiPolicyContentSourceCompletion, + "prompt": RaiPolicyContentSourcePrompt, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RaiPolicyContentSource(input) + return &out, nil +} + +type RaiPolicyMode string + +const ( + RaiPolicyModeBlocking RaiPolicyMode = "Blocking" + RaiPolicyModeDefault RaiPolicyMode = "Default" + RaiPolicyModeDeferred RaiPolicyMode = "Deferred" +) + +func PossibleValuesForRaiPolicyMode() []string { + return []string{ + string(RaiPolicyModeBlocking), + string(RaiPolicyModeDefault), + string(RaiPolicyModeDeferred), + } +} + +func (s *RaiPolicyMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRaiPolicyMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRaiPolicyMode(input string) (*RaiPolicyMode, error) { + vals := map[string]RaiPolicyMode{ + "blocking": RaiPolicyModeBlocking, + "default": RaiPolicyModeDefault, + "deferred": RaiPolicyModeDeferred, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RaiPolicyMode(input) + return &out, nil +} + +type RaiPolicyType string + +const ( + RaiPolicyTypeSystemManaged RaiPolicyType = "SystemManaged" + RaiPolicyTypeUserManaged RaiPolicyType = "UserManaged" +) + +func PossibleValuesForRaiPolicyType() []string { + return []string{ + string(RaiPolicyTypeSystemManaged), + string(RaiPolicyTypeUserManaged), + } +} + +func (s *RaiPolicyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRaiPolicyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRaiPolicyType(input string) (*RaiPolicyType, error) { + vals := map[string]RaiPolicyType{ + "systemmanaged": RaiPolicyTypeSystemManaged, + "usermanaged": RaiPolicyTypeUserManaged, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RaiPolicyType(input) + return &out, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raipolicies/id_account.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/id_account.go new file mode 100644 index 00000000000..390de5e7784 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/id_account.go @@ -0,0 +1,125 @@ +package raipolicies + +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 = &AccountId{} + +// AccountId is a struct representing the Resource ID for a Account +type AccountId struct { + SubscriptionId string + ResourceGroupName string + AccountName string +} + +// NewAccountID returns a new AccountId struct +func NewAccountID(subscriptionId string, resourceGroupName string, accountName string) AccountId { + return AccountId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + } +} + +// ParseAccountID parses 'input' into a AccountId +func ParseAccountID(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccountIDInsensitively parses 'input' case-insensitively into a AccountId +// note: this method should only be used for API response data and not user input +func ParseAccountIDInsensitively(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccountId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + return nil +} + +// ValidateAccountID checks that 'input' can be parsed as a Account ID +func ValidateAccountID(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 := ParseAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Account ID +func (id AccountId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Account ID +func (id AccountId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + } +} + +// String returns a human-readable description of this Account ID +func (id AccountId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + } + return fmt.Sprintf("Account (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raipolicies/id_account_test.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/id_account_test.go new file mode 100644 index 00000000000..00d073794a9 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/id_account_test.go @@ -0,0 +1,282 @@ +package raipolicies + +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 = &AccountId{} + +func TestNewAccountID(t *testing.T) { + id := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } +} + +func TestFormatAccountID(t *testing.T) { + actual := NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAccountID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestParseAccountIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AccountId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Expected: &AccountId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAccountIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + } +} + +func TestSegmentsForAccountId(t *testing.T) { + segments := AccountId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AccountId 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/cognitive/2023-10-01-preview/raipolicies/id_raipolicy.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/id_raipolicy.go new file mode 100644 index 00000000000..043b93a1426 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/id_raipolicy.go @@ -0,0 +1,134 @@ +package raipolicies + +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 = &RaiPolicyId{} + +// RaiPolicyId is a struct representing the Resource ID for a Rai Policy +type RaiPolicyId struct { + SubscriptionId string + ResourceGroupName string + AccountName string + RaiPolicyName string +} + +// NewRaiPolicyID returns a new RaiPolicyId struct +func NewRaiPolicyID(subscriptionId string, resourceGroupName string, accountName string, raiPolicyName string) RaiPolicyId { + return RaiPolicyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + RaiPolicyName: raiPolicyName, + } +} + +// ParseRaiPolicyID parses 'input' into a RaiPolicyId +func ParseRaiPolicyID(input string) (*RaiPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&RaiPolicyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RaiPolicyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRaiPolicyIDInsensitively parses 'input' case-insensitively into a RaiPolicyId +// note: this method should only be used for API response data and not user input +func ParseRaiPolicyIDInsensitively(input string) (*RaiPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&RaiPolicyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RaiPolicyId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RaiPolicyId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + if id.RaiPolicyName, ok = input.Parsed["raiPolicyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "raiPolicyName", input) + } + + return nil +} + +// ValidateRaiPolicyID checks that 'input' can be parsed as a Rai Policy ID +func ValidateRaiPolicyID(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 := ParseRaiPolicyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Rai Policy ID +func (id RaiPolicyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s/raiPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName, id.RaiPolicyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Rai Policy ID +func (id RaiPolicyId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountValue"), + resourceids.StaticSegment("staticRaiPolicies", "raiPolicies", "raiPolicies"), + resourceids.UserSpecifiedSegment("raiPolicyName", "raiPolicyValue"), + } +} + +// String returns a human-readable description of this Rai Policy ID +func (id RaiPolicyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + fmt.Sprintf("Rai Policy Name: %q", id.RaiPolicyName), + } + return fmt.Sprintf("Rai Policy (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raipolicies/id_raipolicy_test.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/id_raipolicy_test.go new file mode 100644 index 00000000000..a4095e3e04b --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/id_raipolicy_test.go @@ -0,0 +1,327 @@ +package raipolicies + +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 = &RaiPolicyId{} + +func TestNewRaiPolicyID(t *testing.T) { + id := NewRaiPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiPolicyValue") + + 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.AccountName != "accountValue" { + t.Fatalf("Expected %q but got %q for Segment 'AccountName'", id.AccountName, "accountValue") + } + + if id.RaiPolicyName != "raiPolicyValue" { + t.Fatalf("Expected %q but got %q for Segment 'RaiPolicyName'", id.RaiPolicyName, "raiPolicyValue") + } +} + +func TestFormatRaiPolicyID(t *testing.T) { + actual := NewRaiPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountValue", "raiPolicyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiPolicies/raiPolicyValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseRaiPolicyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RaiPolicyId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiPolicies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiPolicies/raiPolicyValue", + Expected: &RaiPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + RaiPolicyName: "raiPolicyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiPolicies/raiPolicyValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRaiPolicyID(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.RaiPolicyName != v.Expected.RaiPolicyName { + t.Fatalf("Expected %q but got %q for RaiPolicyName", v.Expected.RaiPolicyName, actual.RaiPolicyName) + } + + } +} + +func TestParseRaiPolicyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *RaiPolicyId + }{ + { + // 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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/rAiPoLiCiEs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiPolicies/raiPolicyValue", + Expected: &RaiPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + AccountName: "accountValue", + RaiPolicyName: "raiPolicyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.CognitiveServices/accounts/accountValue/raiPolicies/raiPolicyValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/rAiPoLiCiEs/rAiPoLiCyVaLuE", + Expected: &RaiPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + AccountName: "aCcOuNtVaLuE", + RaiPolicyName: "rAiPoLiCyVaLuE", + }, + }, + { + // 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.cOgNiTiVeSeRvIcEs/aCcOuNtS/aCcOuNtVaLuE/rAiPoLiCiEs/rAiPoLiCyVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseRaiPolicyIDInsensitively(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.AccountName != v.Expected.AccountName { + t.Fatalf("Expected %q but got %q for AccountName", v.Expected.AccountName, actual.AccountName) + } + + if actual.RaiPolicyName != v.Expected.RaiPolicyName { + t.Fatalf("Expected %q but got %q for RaiPolicyName", v.Expected.RaiPolicyName, actual.RaiPolicyName) + } + + } +} + +func TestSegmentsForRaiPolicyId(t *testing.T) { + segments := RaiPolicyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("RaiPolicyId 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/cognitive/2023-10-01-preview/raipolicies/method_createorupdate.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/method_createorupdate.go new file mode 100644 index 00000000000..5ba358f6405 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/method_createorupdate.go @@ -0,0 +1,59 @@ +package raipolicies + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RaiPolicy +} + +// CreateOrUpdate ... +func (c RaiPoliciesClient) CreateOrUpdate(ctx context.Context, id RaiPolicyId, input RaiPolicy) (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 + } + + var model RaiPolicy + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raipolicies/method_delete.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/method_delete.go new file mode 100644 index 00000000000..fdb2a53c932 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/method_delete.go @@ -0,0 +1,70 @@ +package raipolicies + +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 RaiPoliciesClient) Delete(ctx context.Context, id RaiPolicyId) (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 RaiPoliciesClient) DeleteThenPoll(ctx context.Context, id RaiPolicyId) 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/cognitive/2023-10-01-preview/raipolicies/method_get.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/method_get.go new file mode 100644 index 00000000000..9b6b75cc0bf --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/method_get.go @@ -0,0 +1,54 @@ +package raipolicies + +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 *RaiPolicy +} + +// Get ... +func (c RaiPoliciesClient) Get(ctx context.Context, id RaiPolicyId) (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 RaiPolicy + result.Model = &model + + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raipolicies/method_list.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/method_list.go new file mode 100644 index 00000000000..265297c7253 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/method_list.go @@ -0,0 +1,91 @@ +package raipolicies + +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 *[]RaiPolicy +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RaiPolicy +} + +// List ... +func (c RaiPoliciesClient) List(ctx context.Context, id AccountId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/raiPolicies", 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 *[]RaiPolicy `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 RaiPoliciesClient) ListComplete(ctx context.Context, id AccountId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, RaiPolicyOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RaiPoliciesClient) ListCompleteMatchingPredicate(ctx context.Context, id AccountId, predicate RaiPolicyOperationPredicate) (result ListCompleteResult, err error) { + items := make([]RaiPolicy, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raiblocklistconfig.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raiblocklistconfig.go new file mode 100644 index 00000000000..9b10c559e7f --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raiblocklistconfig.go @@ -0,0 +1,9 @@ +package raipolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RaiBlocklistConfig struct { + Blocking *bool `json:"blocking,omitempty"` + BlocklistName *string `json:"blocklistName,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raipolicy.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raipolicy.go new file mode 100644 index 00000000000..b373a9fdc22 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raipolicy.go @@ -0,0 +1,18 @@ +package raipolicies + +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 RaiPolicy struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RaiPolicyProperties `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/cognitive/2023-10-01-preview/raipolicies/model_raipolicycontentfilter.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raipolicycontentfilter.go new file mode 100644 index 00000000000..9b88270428c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raipolicycontentfilter.go @@ -0,0 +1,12 @@ +package raipolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RaiPolicyContentFilter struct { + AllowedContentLevel *AllowedContentLevel `json:"allowedContentLevel,omitempty"` + Blocking *bool `json:"blocking,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Name *string `json:"name,omitempty"` + Source *RaiPolicyContentSource `json:"source,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raipolicyproperties.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raipolicyproperties.go new file mode 100644 index 00000000000..ff700db1d2a --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/model_raipolicyproperties.go @@ -0,0 +1,13 @@ +package raipolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RaiPolicyProperties struct { + BasePolicyName *string `json:"basePolicyName,omitempty"` + CompletionBlocklists *[]RaiBlocklistConfig `json:"completionBlocklists,omitempty"` + ContentFilters *[]RaiPolicyContentFilter `json:"contentFilters,omitempty"` + Mode *RaiPolicyMode `json:"mode,omitempty"` + PolicyType *RaiPolicyType `json:"policyType,omitempty"` + PromptBlocklists *[]RaiBlocklistConfig `json:"promptBlocklists,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/raipolicies/predicates.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/predicates.go new file mode 100644 index 00000000000..4f56bb41f17 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/predicates.go @@ -0,0 +1,32 @@ +package raipolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RaiPolicyOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p RaiPolicyOperationPredicate) Matches(input RaiPolicy) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + 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/cognitive/2023-10-01-preview/raipolicies/version.go b/resource-manager/cognitive/2023-10-01-preview/raipolicies/version.go new file mode 100644 index 00000000000..8f58a7c18b7 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/raipolicies/version.go @@ -0,0 +1,12 @@ +package raipolicies + +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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/raipolicies/%s", defaultApiVersion) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/skus/README.md b/resource-manager/cognitive/2023-10-01-preview/skus/README.md new file mode 100644 index 00000000000..78bc8545f57 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/skus/README.md @@ -0,0 +1,38 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/skus` Documentation + +The `skus` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/skus" +``` + + +### Client Initialization + +```go +client := skus.NewSkusClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SkusClient.ResourceSkusList` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ResourceSkusList(ctx, id)` can be used to do batched pagination +items, err := client.ResourceSkusListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/skus/client.go b/resource-manager/cognitive/2023-10-01-preview/skus/client.go new file mode 100644 index 00000000000..90cd04245b3 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/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/cognitive/2023-10-01-preview/skus/constants.go b/resource-manager/cognitive/2023-10-01-preview/skus/constants.go new file mode 100644 index 00000000000..280c65cf8bc --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/skus/constants.go @@ -0,0 +1,92 @@ +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 ResourceSkuRestrictionsReasonCode string + +const ( + ResourceSkuRestrictionsReasonCodeNotAvailableForSubscription ResourceSkuRestrictionsReasonCode = "NotAvailableForSubscription" + ResourceSkuRestrictionsReasonCodeQuotaId ResourceSkuRestrictionsReasonCode = "QuotaId" +) + +func PossibleValuesForResourceSkuRestrictionsReasonCode() []string { + return []string{ + string(ResourceSkuRestrictionsReasonCodeNotAvailableForSubscription), + string(ResourceSkuRestrictionsReasonCodeQuotaId), + } +} + +func (s *ResourceSkuRestrictionsReasonCode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceSkuRestrictionsReasonCode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceSkuRestrictionsReasonCode(input string) (*ResourceSkuRestrictionsReasonCode, error) { + vals := map[string]ResourceSkuRestrictionsReasonCode{ + "notavailableforsubscription": ResourceSkuRestrictionsReasonCodeNotAvailableForSubscription, + "quotaid": ResourceSkuRestrictionsReasonCodeQuotaId, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceSkuRestrictionsReasonCode(input) + return &out, nil +} + +type ResourceSkuRestrictionsType string + +const ( + ResourceSkuRestrictionsTypeLocation ResourceSkuRestrictionsType = "Location" + ResourceSkuRestrictionsTypeZone ResourceSkuRestrictionsType = "Zone" +) + +func PossibleValuesForResourceSkuRestrictionsType() []string { + return []string{ + string(ResourceSkuRestrictionsTypeLocation), + string(ResourceSkuRestrictionsTypeZone), + } +} + +func (s *ResourceSkuRestrictionsType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceSkuRestrictionsType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceSkuRestrictionsType(input string) (*ResourceSkuRestrictionsType, error) { + vals := map[string]ResourceSkuRestrictionsType{ + "location": ResourceSkuRestrictionsTypeLocation, + "zone": ResourceSkuRestrictionsTypeZone, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceSkuRestrictionsType(input) + return &out, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/skus/method_resourceskuslist.go b/resource-manager/cognitive/2023-10-01-preview/skus/method_resourceskuslist.go new file mode 100644 index 00000000000..f413ce519b6 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/skus/method_resourceskuslist.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 ResourceSkusListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceSku +} + +type ResourceSkusListCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceSku +} + +// ResourceSkusList ... +func (c SkusClient) ResourceSkusList(ctx context.Context, id commonids.SubscriptionId) (result ResourceSkusListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/providers/Microsoft.CognitiveServices/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 *[]ResourceSku `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ResourceSkusListComplete retrieves all the results into a single object +func (c SkusClient) ResourceSkusListComplete(ctx context.Context, id commonids.SubscriptionId) (ResourceSkusListCompleteResult, error) { + return c.ResourceSkusListCompleteMatchingPredicate(ctx, id, ResourceSkuOperationPredicate{}) +} + +// ResourceSkusListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SkusClient) ResourceSkusListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ResourceSkuOperationPredicate) (result ResourceSkusListCompleteResult, err error) { + items := make([]ResourceSku, 0) + + resp, err := c.ResourceSkusList(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 = ResourceSkusListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/cognitive/2023-10-01-preview/skus/model_resourcesku.go b/resource-manager/cognitive/2023-10-01-preview/skus/model_resourcesku.go new file mode 100644 index 00000000000..0087fbe50af --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/skus/model_resourcesku.go @@ -0,0 +1,13 @@ +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 ResourceSku struct { + Kind *string `json:"kind,omitempty"` + Locations *[]string `json:"locations,omitempty"` + Name *string `json:"name,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Restrictions *[]ResourceSkuRestrictions `json:"restrictions,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/skus/model_resourceskurestrictioninfo.go b/resource-manager/cognitive/2023-10-01-preview/skus/model_resourceskurestrictioninfo.go new file mode 100644 index 00000000000..07289816676 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/skus/model_resourceskurestrictioninfo.go @@ -0,0 +1,13 @@ +package skus + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/zones" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSkuRestrictionInfo struct { + Locations *[]string `json:"locations,omitempty"` + Zones *zones.Schema `json:"zones,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/skus/model_resourceskurestrictions.go b/resource-manager/cognitive/2023-10-01-preview/skus/model_resourceskurestrictions.go new file mode 100644 index 00000000000..dab4792223d --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/skus/model_resourceskurestrictions.go @@ -0,0 +1,11 @@ +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 ResourceSkuRestrictions struct { + ReasonCode *ResourceSkuRestrictionsReasonCode `json:"reasonCode,omitempty"` + RestrictionInfo *ResourceSkuRestrictionInfo `json:"restrictionInfo,omitempty"` + Type *ResourceSkuRestrictionsType `json:"type,omitempty"` + Values *[]string `json:"values,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/skus/predicates.go b/resource-manager/cognitive/2023-10-01-preview/skus/predicates.go new file mode 100644 index 00000000000..a77c2f3056a --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/skus/predicates.go @@ -0,0 +1,32 @@ +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 ResourceSkuOperationPredicate struct { + Kind *string + Name *string + ResourceType *string + Tier *string +} + +func (p ResourceSkuOperationPredicate) Matches(input ResourceSku) bool { + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.ResourceType != nil && (input.ResourceType == nil || *p.ResourceType != *input.ResourceType) { + return false + } + + if p.Tier != nil && (input.Tier == nil || *p.Tier != *input.Tier) { + return false + } + + return true +} diff --git a/resource-manager/cognitive/2023-10-01-preview/skus/version.go b/resource-manager/cognitive/2023-10-01-preview/skus/version.go new file mode 100644 index 00000000000..6c0e10d1131 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/skus/%s", defaultApiVersion) +} diff --git a/resource-manager/cognitive/2023-10-01-preview/usages/README.md b/resource-manager/cognitive/2023-10-01-preview/usages/README.md new file mode 100644 index 00000000000..9984040d01c --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/usages/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/usages` Documentation + +The `usages` SDK allows for interaction with the Azure Resource Manager Service `cognitive` (API Version `2023-10-01-preview`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2023-10-01-preview/usages" +``` + + +### Client Initialization + +```go +client := usages.NewUsagesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `UsagesClient.List` + +```go +ctx := context.TODO() +id := usages.NewLocationID("12345678-1234-9876-4563-123456789012", "locationValue") + +// alternatively `client.List(ctx, id, usages.DefaultListOperationOptions())` can be used to do batched pagination +items, err := client.ListComplete(ctx, id, usages.DefaultListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/cognitive/2023-10-01-preview/usages/client.go b/resource-manager/cognitive/2023-10-01-preview/usages/client.go new file mode 100644 index 00000000000..772d6a5be35 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/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/cognitive/2023-10-01-preview/usages/constants.go b/resource-manager/cognitive/2023-10-01-preview/usages/constants.go new file mode 100644 index 00000000000..e786b8d8aaa --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/usages/constants.go @@ -0,0 +1,113 @@ +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 QuotaUsageStatus string + +const ( + QuotaUsageStatusBlocked QuotaUsageStatus = "Blocked" + QuotaUsageStatusInOverage QuotaUsageStatus = "InOverage" + QuotaUsageStatusIncluded QuotaUsageStatus = "Included" + QuotaUsageStatusUnknown QuotaUsageStatus = "Unknown" +) + +func PossibleValuesForQuotaUsageStatus() []string { + return []string{ + string(QuotaUsageStatusBlocked), + string(QuotaUsageStatusInOverage), + string(QuotaUsageStatusIncluded), + string(QuotaUsageStatusUnknown), + } +} + +func (s *QuotaUsageStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseQuotaUsageStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseQuotaUsageStatus(input string) (*QuotaUsageStatus, error) { + vals := map[string]QuotaUsageStatus{ + "blocked": QuotaUsageStatusBlocked, + "inoverage": QuotaUsageStatusInOverage, + "included": QuotaUsageStatusIncluded, + "unknown": QuotaUsageStatusUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := QuotaUsageStatus(input) + return &out, nil +} + +type UnitType string + +const ( + UnitTypeBytes UnitType = "Bytes" + UnitTypeBytesPerSecond UnitType = "BytesPerSecond" + UnitTypeCount UnitType = "Count" + UnitTypeCountPerSecond UnitType = "CountPerSecond" + UnitTypeMilliseconds UnitType = "Milliseconds" + UnitTypePercent UnitType = "Percent" + UnitTypeSeconds UnitType = "Seconds" +) + +func PossibleValuesForUnitType() []string { + return []string{ + string(UnitTypeBytes), + string(UnitTypeBytesPerSecond), + string(UnitTypeCount), + string(UnitTypeCountPerSecond), + string(UnitTypeMilliseconds), + string(UnitTypePercent), + string(UnitTypeSeconds), + } +} + +func (s *UnitType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseUnitType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseUnitType(input string) (*UnitType, error) { + vals := map[string]UnitType{ + "bytes": UnitTypeBytes, + "bytespersecond": UnitTypeBytesPerSecond, + "count": UnitTypeCount, + "countpersecond": UnitTypeCountPerSecond, + "milliseconds": UnitTypeMilliseconds, + "percent": UnitTypePercent, + "seconds": UnitTypeSeconds, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := UnitType(input) + return &out, nil +} diff --git a/resource-manager/cognitive/2023-10-01-preview/usages/id_location.go b/resource-manager/cognitive/2023-10-01-preview/usages/id_location.go new file mode 100644 index 00000000000..ca9a9089750 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/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.CognitiveServices/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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + 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/cognitive/2023-10-01-preview/usages/id_location_test.go b/resource-manager/cognitive/2023-10-01-preview/usages/id_location_test.go new file mode 100644 index 00000000000..db8900f8edc --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/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.CognitiveServices/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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/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.CognitiveServices/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.CognitiveServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/locations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/lOcAtIoNs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.CognitiveServices/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.CognitiveServices/locations/locationValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/pRoViDeRs/mIcRoSoFt.cOgNiTiVeSeRvIcEs/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.cOgNiTiVeSeRvIcEs/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/cognitive/2023-10-01-preview/usages/method_list.go b/resource-manager/cognitive/2023-10-01-preview/usages/method_list.go new file mode 100644 index 00000000000..b1c8cb4341e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/usages/method_list.go @@ -0,0 +1,119 @@ +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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Usage +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Usage +} + +type ListOperationOptions struct { + Filter *string +} + +func DefaultListOperationOptions() ListOperationOptions { + return ListOperationOptions{} +} + +func (o ListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o ListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + return &out +} + +// List ... +func (c UsagesClient) List(ctx context.Context, id LocationId, 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/usages", 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 *[]Usage `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 UsagesClient) ListComplete(ctx context.Context, id LocationId, options ListOperationOptions) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, options, UsageOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c UsagesClient) ListCompleteMatchingPredicate(ctx context.Context, id LocationId, options ListOperationOptions, predicate UsageOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Usage, 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/cognitive/2023-10-01-preview/usages/model_metricname.go b/resource-manager/cognitive/2023-10-01-preview/usages/model_metricname.go new file mode 100644 index 00000000000..3de7eccbf4e --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/usages/model_metricname.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 MetricName struct { + LocalizedValue *string `json:"localizedValue,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/usages/model_usage.go b/resource-manager/cognitive/2023-10-01-preview/usages/model_usage.go new file mode 100644 index 00000000000..35f4587aaf2 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/usages/model_usage.go @@ -0,0 +1,14 @@ +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 *float64 `json:"currentValue,omitempty"` + Limit *float64 `json:"limit,omitempty"` + Name *MetricName `json:"name,omitempty"` + NextResetTime *string `json:"nextResetTime,omitempty"` + QuotaPeriod *string `json:"quotaPeriod,omitempty"` + Status *QuotaUsageStatus `json:"status,omitempty"` + Unit *UnitType `json:"unit,omitempty"` +} diff --git a/resource-manager/cognitive/2023-10-01-preview/usages/predicates.go b/resource-manager/cognitive/2023-10-01-preview/usages/predicates.go new file mode 100644 index 00000000000..7cbeca39890 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/usages/predicates.go @@ -0,0 +1,32 @@ +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 *float64 + Limit *float64 + NextResetTime *string + QuotaPeriod *string +} + +func (p UsageOperationPredicate) Matches(input Usage) bool { + + if p.CurrentValue != nil && (input.CurrentValue == nil || *p.CurrentValue != *input.CurrentValue) { + return false + } + + if p.Limit != nil && (input.Limit == nil || *p.Limit != *input.Limit) { + return false + } + + if p.NextResetTime != nil && (input.NextResetTime == nil || *p.NextResetTime != *input.NextResetTime) { + return false + } + + if p.QuotaPeriod != nil && (input.QuotaPeriod == nil || *p.QuotaPeriod != *input.QuotaPeriod) { + return false + } + + return true +} diff --git a/resource-manager/cognitive/2023-10-01-preview/usages/version.go b/resource-manager/cognitive/2023-10-01-preview/usages/version.go new file mode 100644 index 00000000000..b0245054e86 --- /dev/null +++ b/resource-manager/cognitive/2023-10-01-preview/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 = "2023-10-01-preview" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/usages/%s", defaultApiVersion) +}