Skip to content

Commit

Permalink
fix(License): ensure license works
Browse files Browse the repository at this point in the history
  • Loading branch information
MingboPeng committed Jan 12, 2024
1 parent 4c108bb commit c3d62d3
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/PollinationSDK.Tests/Api/LicenseTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System.IO;
using System.Linq;

namespace PollinationSDK.Test
Expand Down Expand Up @@ -26,6 +27,15 @@ public void GetLicenseKeyTest()
var key = Utilities.GetValidLicenseKey("rhino_plugin");
Assert.IsTrue(!string.IsNullOrEmpty(key));
}

[Test]
public void DeserializeLicense()
{
var f = Path.GetFullPath(@"../../../TestSample/licensePublic.json");
var json = System.IO.File.ReadAllText(f);
var l = LicensePublic.FromJson(json);
Assert.IsNotNull(l);
}
}

}
26 changes: 26 additions & 0 deletions src/PollinationSDK.Tests/TestSample/licensePublic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": "7832b8b1-xxxx-xxxx-xxxx-8ee6253b0aab",
"created_at": "2023-12-11T00:26:25.877353+00:00",
"updated_at": "2023-12-25T03:00:27.492802+00:00",
"key": "5A87B3-XXXXXX-XXXXXX-XXXXXX-XXXXXX-666F6E",
"revoked": false,
"suspended": false,
"total_activations": 0,
"total_deactivations": 0,
"validity": 0,
"allowed_activations": 20,
"type": "hosted-floating",
"server_sync_grace_period": 86400,
"server_sync_interval": 3600,
"lease_duration": 3630,
"product_id": "95e61f3a-xxxx-xxxx-xxxx-5aaa9321ba23",
"notes": null,
"metadata": [
{
"id": "f38f378d-xxxx-xxxx-xxxx-5ca758a917e2",
"key": "pollination/account-id",
"value": "1da45dba-xxxx-xxxx-xxxx-b5df2f28e3bd",
"visible": false
}
]
}
6 changes: 3 additions & 3 deletions src/PollinationSDK/Model/License.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ protected License()
/// <param name="url">A URL to the license used for the package..</param>
public License
(
string name, // Required parameters
//string name, // Required parameters
Dictionary<string, string> annotations= default, string url= default// Optional parameters
) : base()// BaseClass
{
// to ensure "name" is required (not null)
this.Name = name ?? throw new ArgumentNullException("name is a required property for License and cannot be null");
//this.Name = name ?? throw new ArgumentNullException("name is a required property for License and cannot be null");
this.Annotations = annotations;
this.Url = url;

Expand All @@ -71,7 +71,7 @@ public License
/// The license name used for the package.
/// </summary>
/// <value>The license name used for the package.</value>
[DataMember(Name = "name", IsRequired = true)]
[DataMember(Name = "name")]
public string Name { get; set; }
/// <summary>
/// An optional dictionary to add annotations to inputs. These annotations will be used by the client side libraries.
Expand Down
252 changes: 252 additions & 0 deletions src/PollinationSDK/Model/LicenseMetaData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
/*
* pollination-server
*
* Pollination Server OpenAPI Definition
*
* Contact: [email protected]
* Generated by: https://github.com/openapitools/openapi-generator.git
*/

using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.ComponentModel.DataAnnotations;


namespace PollinationSDK
{
/// <summary>
/// Metadata
/// </summary>
[DataContract(Name = "LicenseMetadata")]
public partial class LicenseMetadata : CryptlexBase, IEquatable<LicenseMetadata>, IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="Metadata" /> class.
/// </summary>
[JsonConstructorAttribute]
protected LicenseMetadata()
{
// Set non-required readonly properties with defaultValue
this.Type = "LicenseMetadata";
}

/// <summary>
/// Initializes a new instance of the <see cref="Metadata" /> class.
/// </summary>
/// <param name="key">key (required).</param>
/// <param name="value">value (required).</param>
/// <param name="id">id.</param>
/// <param name="visible">visible (default to false).</param>
public LicenseMetadata
(
string key, string value, // Required parameters
string id = default, bool visible = false // Optional parameters
) : base()// BaseClass
{
// to ensure "key" is required (not null)
this.Key = key ?? throw new ArgumentNullException("key is a required property for Metadata and cannot be null");
// to ensure "value" is required (not null)
this.Value = value ?? throw new ArgumentNullException("value is a required property for Metadata and cannot be null");
this.Id = id;
this.Visible = visible;

// Set non-required readonly properties with defaultValue
this.Type = "LicenseMetadata";
}

//============================================== is ReadOnly
/// <summary>
/// Gets or Sets Type
/// </summary>
[DataMember(Name = "type", EmitDefaultValue = true)]
public override string Type { get; protected set; } = "LicenseMetadata";

/// <summary>
/// Gets or Sets Key
/// </summary>
[DataMember(Name = "key", IsRequired = true, EmitDefaultValue = false)]
public string Key { get; set; }
/// <summary>
/// Gets or Sets Value
/// </summary>
[DataMember(Name = "value", IsRequired = true, EmitDefaultValue = false)]
public string Value { get; set; }
/// <summary>
/// Gets or Sets Id
/// </summary>
[DataMember(Name = "id", EmitDefaultValue = false)]
public string Id { get; set; }
/// <summary>
/// Gets or Sets Visible
/// </summary>
[DataMember(Name = "visible", EmitDefaultValue = true)]
public bool Visible { get; set; } = false;

/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
return "LicenseMetadata";
}

/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString(bool detailed)
{
if (!detailed)
return this.ToString();

var sb = new StringBuilder();
sb.Append("LicenseMetadata:\n");
sb.Append(" Type: ").Append(Type).Append("\n");
sb.Append(" Key: ").Append(Key).Append("\n");
sb.Append(" Value: ").Append(Value).Append("\n");
sb.Append(" Id: ").Append(Id).Append("\n");
sb.Append(" Visible: ").Append(Visible).Append("\n");
return sb.ToString();
}

/// <summary>
/// Returns the object from JSON string
/// </summary>
/// <returns>Metadata object</returns>
public static LicenseMetadata FromJson(string json)
{
var obj = JsonConvert.DeserializeObject<LicenseMetadata>(json, JsonSetting.AnyOfConvertSetting);
if (obj == null)
return null;
return obj.Type.ToLower() == obj.GetType().Name.ToLower() ? obj : null;
}

/// <summary>
/// Creates a new instance with the same properties.
/// </summary>
/// <returns>Metadata object</returns>
public virtual LicenseMetadata DuplicateMetadata()
{
return FromJson(this.ToJson());
}

/// <summary>
/// Creates a new instance with the same properties.
/// </summary>
/// <returns>OpenAPIGenBaseModel</returns>
public override OpenAPIGenBaseModel Duplicate()
{
return DuplicateMetadata();
}

/// <summary>
/// Creates a new instance with the same properties.
/// </summary>
/// <returns>OpenAPIGenBaseModel</returns>
public override CryptlexBase DuplicateCryptlexBase()
{
return DuplicateMetadata();
}

/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="input">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object input)
{
input = input is AnyOf anyOf ? anyOf.Obj : input;
return this.Equals(input as LicenseMetadata);
}

/// <summary>
/// Returns true if Metadata instances are equal
/// </summary>
/// <param name="input">Instance of Metadata to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(LicenseMetadata input)
{
if (input == null)
return false;
return base.Equals(input) &&
(
this.Key == input.Key ||
(this.Key != null &&
this.Key.Equals(input.Key))
) && base.Equals(input) &&
(
this.Value == input.Value ||
(this.Value != null &&
this.Value.Equals(input.Value))
) && base.Equals(input) &&
(
this.Id == input.Id ||
(this.Id != null &&
this.Id.Equals(input.Id))
) && base.Equals(input) &&
(
this.Visible == input.Visible ||
(this.Visible != null &&
this.Visible.Equals(input.Visible))
) && base.Equals(input) &&
(
this.Type == input.Type ||
(this.Type != null &&
this.Type.Equals(input.Type))
);
}

/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hashCode = base.GetHashCode();
if (this.Key != null)
hashCode = hashCode * 59 + this.Key.GetHashCode();
if (this.Value != null)
hashCode = hashCode * 59 + this.Value.GetHashCode();
if (this.Id != null)
hashCode = hashCode * 59 + this.Id.GetHashCode();
if (this.Visible != null)
hashCode = hashCode * 59 + this.Visible.GetHashCode();
if (this.Type != null)
hashCode = hashCode * 59 + this.Type.GetHashCode();
return hashCode;
}
}

/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
foreach (var x in base.BaseValidate(validationContext)) yield return x;


// Type (string) pattern
Regex regexType = new Regex(@"^LicenseMetadata", RegexOptions.CultureInvariant);
if (false == regexType.Match(this.Type).Success)
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Type, must match a pattern of " + regexType, new[] { "Type" });
}

yield break;
}
}
}
12 changes: 6 additions & 6 deletions src/PollinationSDK/Model/LicensePublic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public partial class LicensePublic : License, IEquatable<LicensePublic>, IValida
/// <summary>
/// Gets or Sets Type
/// </summary>
[DataMember(Name="license_type")]
public LicenseType LicenseType { get; set; }
[DataMember(Name = "license_type")]
public LicenseType LicenseType { get; set; } = LicenseType.HostedFloating;
/// <summary>
/// Initializes a new instance of the <see cref="LicensePublic" /> class.
/// </summary>
Expand Down Expand Up @@ -68,9 +68,9 @@ protected LicensePublic()
/// <param name="url">A URL to the license used for the package..</param>
public LicensePublic
(
string name, string id, DateTime createdAt, DateTime updatedAt, string key, bool revoked, bool suspended, int totalActivations, int totalDeactivations, int validity, int allowedActivations, int serverSyncGracePeriod, int serverSyncInterval, int leaseDuration, string productId, List<Metadata> metadata, LicenseType type, // Required parameters
string id, DateTime createdAt, DateTime updatedAt, string key, bool revoked, bool suspended, int totalActivations, int totalDeactivations, int validity, int allowedActivations, int serverSyncGracePeriod, int serverSyncInterval, int leaseDuration, string productId, List<LicenseMetadata> metadata, LicenseType type, // Required parameters
Dictionary<string, string> annotations= default, string url= default, string notes= default// Optional parameters
) : base(name: name, annotations: annotations, url: url )// BaseClass
) : base( annotations: annotations, url: url )// BaseClass
{
// to ensure "id" is required (not null)
this.Id = id ?? throw new ArgumentNullException("id is a required property for LicensePublic and cannot be null");
Expand Down Expand Up @@ -173,7 +173,7 @@ public LicensePublic
/// Gets or Sets Metadata
/// </summary>
[DataMember(Name = "metadata", IsRequired = true)]
public List<Metadata> Metadata { get; set; }
public List<LicenseMetadata> Metadata { get; set; }
/// <summary>
/// Gets or Sets Notes
/// </summary>
Expand Down Expand Up @@ -232,7 +232,7 @@ public static LicensePublic FromJson(string json)
var obj = JsonConvert.DeserializeObject<LicensePublic>(json, JsonSetting.AnyOfConvertSetting);
if (obj == null)
return null;
return obj.Type.ToLower() == obj.GetType().Name.ToLower() ? obj : null;
return obj;
}

/// <summary>
Expand Down

0 comments on commit c3d62d3

Please sign in to comment.