* New .NET SDK - PR into dev (#25)

* Add .NET Core build action

* Update README.md

* Copy //Build client code

* Change dotnet version

* Adjust the workdir for build action

* Remove test step from the worklow file

* Adjust workflow again

* Moving globaljson

* Rename namespaces

* Rename namespaces

* Add test step

* Wrong repo

* Updated .NET SDK version

* Bring generated SDK from OAS in

* Change .NET version

* add generated

* Use new resource ID

* Getting closer to SDK

* add .net sdk minor version fix

* Update README.md

* Update dotnet-core.yml

* Update dotnet-core.yml

* addressed code review comments

* Moved implementation to use AAD v2.0

* Update workflow to kick off build on dev branch

* Set to allow for dev and master

Co-authored-by: Ercenk Keresteci <ercenk@microsoft.com>
Co-authored-by: Scott Seely <scseely@microsoft.com>

* Updated the code generation and split the clients (#27)

* read-tree for Azure.Core.TestFramework

* Checkpoint

* checkpoint 2

* Split OAS doc

* Add extensions after OAS split

* Clean autorest.md

* updated NuGet packages

* Merge into one assembly (#29)

* Merge into one assembly

* Added test instructions

* FIx typo

* Modified code generation logic, and refreshed SDK for resourceUri in metering. (#33)

* Covering the case for no subscriptions

* renamed sdk folder to client for consistency

* Rename SDK to client library continued.

Co-authored-by: Ercenk Keresteci <ercenk@microsoft.com>
Co-authored-by: Scott Seely <scseely@microsoft.com>
This commit is contained in:
Ercenk Keresteci 2020-11-18 09:24:58 -08:00 коммит произвёл GitHub
Родитель 267d50b6b2
Коммит feba06f0e9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
78 изменённых файлов: 744 добавлений и 2179 удалений

4
.github/workflows/dotnet-core.yml поставляемый
Просмотреть файл

@ -23,11 +23,11 @@ jobs:
dotnet-version: 3.1.*
- name: Build
run: dotnet build --configuration Debug
working-directory: ./sdk
working-directory: ./client
- name: test
run: dotnet test
env:
TenantId: ${{secrets.TENANTID}}
ClientId: ${{secrets.CLIENTID}}
clientSecret: ${{secrets.CLIENTSECRET}}
working-directory: ./sdk
working-directory: ./client

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -26,16 +26,23 @@ namespace Microsoft.Marketplace.Metering.Models
/// <summary>
/// Initializes a new instance of the UsageEvent class.
/// </summary>
/// <param name="resourceId">Subscription ID for the event</param>
/// <param name="resourceId">subscriptionId property value for SaaS
/// offer subscriptions; resourceUsageId property on the managed
/// application resource for managed application offers. For managed
/// applications, only use one of resourceId or resourceUri.</param>
/// <param name="resourceUri">Resource URI for the managed app. Used
/// with managed applications. Only use resourceUri or resourceId, but
/// never both.</param>
/// <param name="quantity">Number of units consumed</param>
/// <param name="dimension">Dimension identifier</param>
/// <param name="effectiveStartTime">Time in UTC when the usage event
/// occurred</param>
/// <param name="planId">Plan associated with the purchased
/// offer</param>
public UsageEvent(System.Guid? resourceId = default(System.Guid?), long? quantity = default(long?), string dimension = default(string), System.DateTime? effectiveStartTime = default(System.DateTime?), string planId = default(string))
public UsageEvent(System.Guid? resourceId = default(System.Guid?), string resourceUri = default(string), long? quantity = default(long?), string dimension = default(string), System.DateTime? effectiveStartTime = default(System.DateTime?), string planId = default(string))
{
ResourceId = resourceId;
ResourceUri = resourceUri;
Quantity = quantity;
Dimension = dimension;
EffectiveStartTime = effectiveStartTime;
@ -49,11 +56,21 @@ namespace Microsoft.Marketplace.Metering.Models
partial void CustomInit();
/// <summary>
/// Gets or sets subscription ID for the event
/// Gets or sets subscriptionId property value for SaaS offer
/// subscriptions; resourceUsageId property on the managed application
/// resource for managed application offers. For managed applications,
/// only use one of resourceId or resourceUri.
/// </summary>
[JsonProperty(PropertyName = "resourceId")]
public System.Guid? ResourceId { get; set; }
/// <summary>
/// Gets or sets resource URI for the managed app. Used with managed
/// applications. Only use resourceUri or resourceId, but never both.
/// </summary>
[JsonProperty(PropertyName = "resourceUri")]
public string ResourceUri { get; set; }
/// <summary>
/// Gets or sets number of units consumed
/// </summary>

Просмотреть файл

@ -36,17 +36,20 @@ namespace Microsoft.Marketplace.Metering.Models
/// UTC</param>
/// <param name="resourceId">Identifier of the resource against which
/// usage is emitted</param>
/// <param name="resourceUri">Identifier of the managed app resource
/// against which usage is emitted</param>
/// <param name="dimension">Dimension identifier</param>
/// <param name="effectiveStartTime">Time in UTC when the usage event
/// occurred</param>
/// <param name="planId">Plan associated with the purchased
/// offer</param>
public UsageEventConflictResponseAdditionalInfo(System.Guid? usageEventId = default(System.Guid?), string status = default(string), System.DateTime? messageTime = default(System.DateTime?), System.Guid? resourceId = default(System.Guid?), long? quantity = default(long?), string dimension = default(string), System.DateTime? effectiveStartTime = default(System.DateTime?), System.Guid? planId = default(System.Guid?))
public UsageEventConflictResponseAdditionalInfo(System.Guid? usageEventId = default(System.Guid?), string status = default(string), System.DateTime? messageTime = default(System.DateTime?), System.Guid? resourceId = default(System.Guid?), string resourceUri = default(string), long? quantity = default(long?), string dimension = default(string), System.DateTime? effectiveStartTime = default(System.DateTime?), System.Guid? planId = default(System.Guid?))
{
UsageEventId = usageEventId;
Status = status;
MessageTime = messageTime;
ResourceId = resourceId;
ResourceUri = resourceUri;
Quantity = quantity;
Dimension = dimension;
EffectiveStartTime = effectiveStartTime;
@ -85,6 +88,13 @@ namespace Microsoft.Marketplace.Metering.Models
[JsonProperty(PropertyName = "resourceId")]
public System.Guid? ResourceId { get; set; }
/// <summary>
/// Gets or sets identifier of the managed app resource against which
/// usage is emitted
/// </summary>
[JsonProperty(PropertyName = "resourceUri")]
public string ResourceUri { get; set; }
/// <summary>
/// </summary>
[JsonProperty(PropertyName = "quantity")]

Просмотреть файл

@ -36,18 +36,21 @@ namespace Microsoft.Marketplace.Metering.Models
/// UTC</param>
/// <param name="resourceId">Identifier of the resource against which
/// usage is emitted</param>
/// <param name="resourceUri">Identifier of the managed app resource
/// against which usage is emitted</param>
/// <param name="quantity">Number of units consumed</param>
/// <param name="dimension">Dimension identifier</param>
/// <param name="effectiveStartTime">Time in UTC when the usage event
/// occurred</param>
/// <param name="planId">Plan associated with the purchased
/// offer</param>
public UsageEventOkResponse(System.Guid? usageEventId = default(System.Guid?), UsageEventStatusEnum? status = default(UsageEventStatusEnum?), System.DateTime? messageTime = default(System.DateTime?), System.Guid? resourceId = default(System.Guid?), long? quantity = default(long?), string dimension = default(string), System.DateTime? effectiveStartTime = default(System.DateTime?), string planId = default(string))
public UsageEventOkResponse(System.Guid? usageEventId = default(System.Guid?), UsageEventStatusEnum? status = default(UsageEventStatusEnum?), System.DateTime? messageTime = default(System.DateTime?), System.Guid? resourceId = default(System.Guid?), string resourceUri = default(string), long? quantity = default(long?), string dimension = default(string), System.DateTime? effectiveStartTime = default(System.DateTime?), string planId = default(string))
{
UsageEventId = usageEventId;
Status = status;
MessageTime = messageTime;
ResourceId = resourceId;
ResourceUri = resourceUri;
Quantity = quantity;
Dimension = dimension;
EffectiveStartTime = effectiveStartTime;
@ -87,6 +90,13 @@ namespace Microsoft.Marketplace.Metering.Models
[JsonProperty(PropertyName = "resourceId")]
public System.Guid? ResourceId { get; set; }
/// <summary>
/// Gets or sets identifier of the managed app resource against which
/// usage is emitted
/// </summary>
[JsonProperty(PropertyName = "resourceUri")]
public string ResourceUri { get; set; }
/// <summary>
/// Gets or sets number of units consumed
/// </summary>

Просмотреть файл

@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.Marketplace.Metering.Models
{
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;
public partial class UsageEvent
{
/// <summary>
/// Check to make sure either resourceUri or resourceId is used but not both before calling the API.
/// ResourceId is available only for SaaS offers. Managed application offers can use ResourceId or ResourceUri.
/// </summary>
/// <param name="context">Streaming context.</param>
[OnSerializing]
internal void CheckPayload(StreamingContext context)
{
if (this.ResourceId.HasValue && !string.IsNullOrEmpty(this.ResourceUri))
{
throw new ApplicationException("Cannot set resourceId and resourceUri at the same time. Please use ResourceId only if the offer is a SaaS offer. If the offer is a managed application offer, you use either ResourceId or ResourceUri.");
}
}
}
}

Просмотреть файл

@ -28,6 +28,10 @@ namespace Microsoft.Marketplace.SaaS
{
var subscriptions = new List<Subscription>();
var page = await fulfillment.ListSubscriptionsAsync(null, null, null, cancellationToken).ConfigureAwait(false);
if (page == null){
return subscriptions;
}
subscriptions.AddRange(page);
while (page.NextPageLink != default)

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -1,372 +0,0 @@
{
"openapi": "3.0.2",
"servers": [
{
"description": "Marketplace Metering APIs, version 1",
"url": "https://marketplaceapi.microsoft.com/api"
}
],
"info": {
"version": "2018-08-31",
"title": "Metering API",
"x-ms-code-generation-settings": {
"name": "MarketplaceMeteringClient",
"header": "MIT",
"internalConstructors": true,
"useDateTimeOffset": false
},
"description": "With the commercial marketplace metering service, you can create software as a service (SaaS) and managed application offers which charge according to non-standard units. Before publishing an offer to the commercial marketplace, you define the billing dimensions such as bandwidth, tickets, or emails processed. Customers then pay according to their consumption of these dimensions, with your system informing Microsoft via the commercial marketplace metering service API of billable events."
},
"security": [
{
"azure_auth": ["user_impersonation"]
}
],
"paths": {
"/usageEvent": {
"post": {
"summary": "Posts a single usage event to the marketplace metering service API.",
"description": "Posts a single usage event to the marketplace metering service API.",
"operationId": "MeteringOperations_PostUsageEvent",
"tags": ["MarketplaceMeter"],
"parameters": [
{
"in": "query",
"name": "api-version",
"schema": {
"$ref": "#/components/schemas/ApiVersion"
},
"required": true,
"description": "Version of the API."
},
{
"in": "header",
"name": "x-ms-requestid",
"x-ms-client-name": "requestId",
"description": "A unique string value for tracking the request from the client, preferably a GUID. If this value isn't provided, one will be generated and provided in the response headers.",
"schema": {
"type": "string",
"format": "uuid"
},
"required": false
},
{
"in": "header",
"name": "x-ms-correlationid",
"x-ms-client-name": "correlationId",
"description": "A unique string value for operation on the client. This parameter correlates all events from client operation with events on the server side. If this value isn't provided, one will be generated and provided in the response headers.",
"schema": {
"type": "string",
"format": "uuid"
},
"required": false
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UsageEvent"
}
}
}
},
"responses": {
"200": {
"description": "OK.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UsageEventOkResponse"
}
}
}
},
"400": {
"description": "Bad request, missing or invalid data provided or expired."
},
"403": {
"description": "User is unauthorized to make this call."
},
"409": {
"description": "Conflict, when we receive the usage call for the usage resource ID, and effective usage, which already exists. The response will contain additionalInfo field that contains info about the accepted message."
}
}
}
},
"/batchUsageEvent": {
"post": {
"summary": "Posts a set of usage events to the marketplace metering service API.",
"description": "The batch usage event API allows you to emit usage events for more than one purchased entity at once. The batch usage event request references the metering services dimension defined by the publisher when publishing the offer.",
"operationId": "MeteringOperations_PostBatchUsageEvent",
"tags": ["MarketplaceMeter"],
"parameters": [
{
"in": "query",
"name": "api-version",
"schema": {
"$ref": "#/components/schemas/ApiVersion"
},
"required": true,
"description": "Version of the API."
},
{
"in": "header",
"name": "x-ms-requestid",
"x-ms-client-name": "requestId",
"description": "A unique string value for tracking the request from the client, preferably a GUID. If this value isn't provided, one will be generated and provided in the response headers.",
"schema": {
"type": "string",
"format": "uuid"
},
"required": false
},
{
"in": "header",
"name": "x-ms-correlationid",
"x-ms-client-name": "correlationId",
"description": "A unique string value for operation on the client. This parameter correlates all events from client operation with events on the server side. If this value isn't provided, one will be generated and provided in the response headers.",
"schema": {
"type": "string",
"format": "uuid"
},
"required": false
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BatchUsageEvent"
}
}
}
},
"responses": {
"200": {
"description": "OK.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BatchUsageEventOkResponse"
}
}
}
},
"400": {
"description": "Bad request, missing or invalid data provided or expired."
},
"403": {
"description": "User is unauthorized to make this call."
}
}
}
}
},
"components": {
"securitySchemes": {
"azure_auth": {
"type": "oauth2",
"description": "Azure Active Directory OAuth2 Flow",
"flows": {
"clientCredentials": {
"tokenUrl": "https://login.microsoftonline.com/{your-app-tenant-id}/oauth2/token"
}
}
}
},
"schemas": {
"ApiVersion": {
"type": "string",
"description": "The request must send the following parameters as a URL Encoded form; grant_type - client_credentials; resource - 62d94f6c-d599-489b-a797-3e10e42fbe22; client_id - AAD Registered App Client ID; client_secret - AAD Registered App Client Secret",
"enum": ["2018-08-31", "2018-09-15"],
"default": "2018-08-31"
},
"UsageEvent": {
"type": "object",
"properties": {
"resourceId": {
"type": "string",
"format": "uuid",
"description": "Subscription ID for the event"
},
"quantity": {
"type": "integer",
"format": "int64",
"description": "Number of units consumed"
},
"dimension": {
"type": "string",
"description": "Dimension identifier"
},
"effectiveStartTime": {
"type": "string",
"format": "date-time",
"description": "Time in UTC when the usage event occurred"
},
"planId": {
"type": "string",
"description": "Plan associated with the purchased offer"
}
}
},
"BatchUsageEvent": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UsageEvent"
},
"minItems": 1,
"maxItems": 25
},
"UsageEventOkResponse": {
"type": "object",
"properties": {
"usageEventId": {
"description": "Unique identifier associated with the usage event",
"type": "string",
"format": "uuid"
},
"status": {
"description": "Status of the operation.",
"type": "string",
"enum": [
"Accepted",
"Expired",
"Duplicate",
"Error",
"ResourceNotFound",
"ResourceNotAuthorized",
"InvalidDimension|BadArgument"
],
"x-ms-enum": {
"name": "UsageEventStatusEnum",
"modelAsString": false
}
},
"messageTime": {
"description": "Time this message was created in UTC",
"type": "string",
"format": "date-time"
},
"resourceId": {
"description": "Identifier of the resource against which usage is emitted",
"type": "string",
"format": "uuid"
},
"quantity": {
"description": "Number of units consumed",
"type": "integer",
"format": "int64"
},
"dimension": {
"type": "string",
"description": "Dimension identifier"
},
"effectiveStartTime": {
"description": "Time in UTC when the usage event occurred",
"type": "string",
"format": "date-time"
},
"planId": {
"type": "string",
"description": "Plan associated with the purchased offer"
}
}
},
"BatchUsageEventOkResponse": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UsageEventOkResponse"
}
},
"UsageEventConflictResponse": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"additionalInfo": {
"type": "object",
"properties": {
"usageEventId": {
"description": "Unique identifier associated with the usage event",
"type": "string",
"format": "uuid"
},
"status": {
"description": "Accepted|NotProcessed|Expired",
"type": "string",
"enum": ["Accepted", "NotProcessed", "Expired"]
},
"messageTime": {
"description": "Time this message was created in UTC",
"type": "string",
"format": "date-time"
},
"resourceId": {
"description": "Identifier of the resource against which usage is emitted",
"type": "string",
"format": "uuid"
},
"quantity": {
"type": "integer",
"format": "int64"
},
"dimension": {
"description": "Dimension identifier",
"type": "string"
},
"effectiveStartTime": {
"description": "Time in UTC when the usage event occurred",
"type": "string",
"format": "date-time"
},
"planId": {
"description": "Plan associated with the purchased offer",
"type": "string",
"format": "uuid"
}
}
}
}
},
"UsageEventBadRequestResponse": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
},
"target": {
"type": "string"
},
"details": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UsageEventBadRequestResponseDetail"
}
}
}
},
"UsageEventBadRequestResponseDetail": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
},
"target": {
"type": "string"
}
}
}
}
}
}

Просмотреть файл

@ -1,53 +0,0 @@
# SaaS
> see https://aka.ms/autorest
This is the AutoRest configuration file for ContainerRegistry.
---
## Getting Started
To build the SDK for ContainerRegistry, simply [Install AutoRest](https://aka.ms/autorest/install) and in this folder, run:
> `autorest`
To see additional help and options, run:
> `autorest --help`
---
## Configuration
### Basic Information
These are the global settings for the ContainerRegistry API.
``` yaml
openapi-type: arm
```
```yaml
input-file:
- ./2018-08-31/meteringapi.v1.json
```
# Code Generation
## C#
These settings apply only when `--csharp` is specified on the command line.
Please also specify `--csharp-sdks-folder=<path to "SDKs" directory of your azure-sdk-for-net clone>`.
``` yaml $(csharp)
csharp:
azure-arm: true
enable-xml: true
license-header: MICROSOFT_MIT_NO_VERSION
namespace: Microsoft.Marketplace.Metering
payload-flattening-threshold: 3
public-clients: true
output-folder: $(csharp-sdks-folder)/src/Microsoft.Marketplace.Metering/Generated
clear-output-folder: true
```

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,53 +0,0 @@
# SaaS
> see https://aka.ms/autorest
This is the AutoRest configuration file for ContainerRegistry.
---
## Getting Started
To build the SDK for ContainerRegistry, simply [Install AutoRest](https://aka.ms/autorest/install) and in this folder, run:
> `autorest`
To see additional help and options, run:
> `autorest --help`
---
## Configuration
### Basic Information
These are the global settings for the ContainerRegistry API.
``` yaml
openapi-type: arm
```
```yaml
input-file:
- ./2018-08-31/saasapi.v2.json
```
# Code Generation
## C#
These settings apply only when `--csharp` is specified on the command line.
Please also specify `--csharp-sdks-folder=<path to "SDKs" directory of your azure-sdk-for-net clone>`.
``` yaml $(csharp)
csharp:
azure-arm: true
enable-xml: true
license-header: MICROSOFT_MIT_NO_VERSION
namespace: Microsoft.Marketplace.SaaS
payload-flattening-threshold: 3
public-clients: true
output-folder: $(csharp-sdks-folder)/src/Microsoft.Marketplace.SaaS/Generated
clear-output-folder: true
```

Просмотреть файл

@ -24,6 +24,4 @@ ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
RUN git clone https://github.com/Azure/azure-marketplace-openapi.git
ENTRYPOINT [ "/bin/bash", "-c", "npx autorest ./azure-marketplace-openapi/$SDK/autorest.md --v3 --csharp --csharp-sdks-folder=/out --add-credentials" ]
ENTRYPOINT [ "/bin/bash", "-c", "/scripts/generate.sh" ]

Просмотреть файл

@ -1,6 +1,6 @@
docker build -t microsoft/autorest .
docker build -t marketplacedotnet/autorest .
docker run --rm --name autorest -v "%cd%"/../sdk:/out -e SDK=Microsoft.Marketplace.SaaS microsoft/autorest
docker run --rm --name autorest -v "%cd%"/scripts:/scripts -v "%cd%"/../client:/out -e CLIENT=Microsoft.Marketplace.SaaS marketplacedotnet/autorest
docker run --rm --name autorest -v "%cd%"/../sdk:/out -e SDK=Microsoft.Marketplace.Metering microsoft/autorest
docker run --rm --name autorest -v "%cd%"/scripts:/scripts -v "%cd%"/../client:/out -e CLIENT=Microsoft.Marketplace.Metering marketplacedotnet/autorest

Просмотреть файл

@ -0,0 +1,5 @@
#!/bin/bash
git clone https://github.com/Azure/azure-marketplace-openapi.git
npx autorest ./azure-marketplace-openapi/$CLIENT/autorest.md --v3 --csharp --csharp-sdks-folder=/out --add-credentials

Просмотреть файл

@ -1,9 +0,0 @@
git checkout dev
git remote add azuresdk ..\azure-sdk-for-net\
git fetch azuresdk
git merge -s ours --no-commit azuresdk/master
git read-tree --prefix=sdk/tests/Azure.Core.TestFramework -u azuresdk/master:sdk/core/Azure.Core.TestFramework
git read-tree --prefix=sdk/tests/core/Azure.Core/src/Shared -u azuresdk/master:sdk/core/Azure.Core/src/Shared
git commit -a -m "read-tree for Azure.Core.TestFramework"