Skip to content

Commit 612fe3e

Browse files
committed
Merge pull request #427 from sharwell/AddSupportForAddingUrlToServiceCatalog
Preliminary support for OS-KSCATALOG operations
2 parents 92369f3 + 2415508 commit 612fe3e

9 files changed

Lines changed: 422 additions & 3 deletions

File tree

src/Documentation/SharedTokens.tokens

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
</para>
2828
</item>
2929

30+
<item id="NullIfNotIncluded">
31+
<para>-or-</para>
32+
<para>
33+
<see langword="null"/> if the underlying property was not included in the JSON representation of the object.
34+
</para>
35+
</item>
36+
3037
<!--
3138
The following items can only be used in <token> elements that appear in **MAML topics**.
3239
-->
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
namespace net.openstack.Core.Domain
2+
{
3+
using System;
4+
using System.Diagnostics;
5+
using Newtonsoft.Json;
6+
7+
/// <summary>
8+
/// This class models the JSON representation of an endpoint template resource in the OpenStack Identity Service V2.
9+
/// </summary>
10+
/// <remarks>
11+
/// <para>This object is part of the <c>OS-KSCATALOG</c> extension to the OpenStack Identity Service V2.</para>
12+
/// </remarks>
13+
/// <seealso href="http://developer.openstack.org/api-ref-identity-v2.html#os-kscatalog-ext">OS-KSCATALOG admin extension (Identity API v2.0 - OpenStack Complete API Reference)</seealso>
14+
/// <threadsafety static="true" instance="false"/>
15+
/// <preliminary/>
16+
[JsonObject(MemberSerialization.OptIn)]
17+
[DebuggerDisplay("{Id, nq}")]
18+
public class EndpointTemplate : ExtensibleJsonObject
19+
{
20+
/// <summary>
21+
/// This is the backing field for the <see cref="Id"/> property.
22+
/// </summary>
23+
[JsonProperty("id", DefaultValueHandling = DefaultValueHandling.Ignore)]
24+
private EndpointTemplateId _id;
25+
26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="EndpointTemplate"/> class
28+
/// during JSON deserialization.
29+
/// </summary>
30+
[JsonConstructor]
31+
protected EndpointTemplate()
32+
{
33+
}
34+
35+
/// <summary>
36+
/// Initializes a new instance of the <see cref="EndpointTemplate"/> class with the specified endpoint template
37+
/// identifier.
38+
/// </summary>
39+
/// <param name="id">The unique identifier of the endpoint template.</param>
40+
/// <exception cref="ArgumentNullException">If <paramref name="id"/> is <see langword="null"/>.</exception>
41+
public EndpointTemplate(EndpointTemplateId id)
42+
{
43+
if (id == null)
44+
throw new ArgumentNullException("id");
45+
46+
_id = id;
47+
}
48+
49+
/// <summary>
50+
/// Gets the unique identifier for the endpoint template.
51+
/// </summary>
52+
/// <value>
53+
/// <para>The unique identifier for the endpoint template.</para>
54+
/// <token>NullIfNotIncluded</token>
55+
/// </value>
56+
public EndpointTemplateId Id
57+
{
58+
get
59+
{
60+
return _id;
61+
}
62+
}
63+
}
64+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
namespace net.openstack.Core.Domain
2+
{
3+
using System;
4+
using net.openstack.Core;
5+
using Newtonsoft.Json;
6+
7+
/// <summary>
8+
/// Represents the unique identifier of an <see cref="EndpointTemplate"/>.
9+
/// </summary>
10+
/// <remarks>
11+
/// <para>This object is part of the <c>OS-KSCATALOG</c> extension to the OpenStack Identity Service V2.</para>
12+
/// </remarks>
13+
/// <seealso cref="EndpointTemplate.Id"/>
14+
/// <threadsafety static="true" instance="false"/>
15+
/// <preliminary/>
16+
[JsonConverter(typeof(EndpointTemplateId.Converter))]
17+
public sealed class EndpointTemplateId : ResourceIdentifier<EndpointTemplateId>
18+
{
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="EndpointTemplateId"/> class
21+
/// with the specified identifier value.
22+
/// </summary>
23+
/// <param name="id">The identifier value.</param>
24+
/// <exception cref="ArgumentNullException">If <paramref name="id"/> is <see langword="null"/>.</exception>
25+
/// <exception cref="ArgumentException">If <paramref name="id"/> is empty.</exception>
26+
public EndpointTemplateId(string id)
27+
: base(id)
28+
{
29+
}
30+
31+
/// <summary>
32+
/// Provides support for serializing and deserializing <see cref="EndpointTemplateId"/>
33+
/// objects to JSON string values.
34+
/// </summary>
35+
/// <threadsafety static="true" instance="false"/>
36+
private sealed class Converter : ConverterBase
37+
{
38+
/// <inheritdoc/>
39+
protected override EndpointTemplateId FromValue(string id)
40+
{
41+
return new EndpointTemplateId(id);
42+
}
43+
}
44+
}
45+
}

src/corelib/Providers/Rackspace/CloudIdentityProvider.cs

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
34
using System.Linq;
45
using System.Net;
56
using System.Threading.Tasks;
@@ -689,6 +690,172 @@ public virtual IEnumerable<Tenant> ListTenants(CloudIdentity identity)
689690
return response.Data.Tenants;
690691
}
691692

693+
/// <summary>
694+
/// Lists the endpoints in a tenant's service catalog.
695+
/// </summary>
696+
/// <remarks>
697+
/// <para>This call is part of the <c>OS-KSCATALOG</c> extension to the OpenStack Identity Service V2.</para>
698+
/// </remarks>
699+
/// <param name="tenantId">The tenant ID. This is obtained from <see cref="Tenant.Id"/></param>
700+
/// <param name="identity">The cloud identity to use for this request. If not specified, the <see cref="DefaultIdentity"/> for the current provider instance will be used.</param>
701+
/// <returns>A collection of <see cref="ExtendedEndpoint"/> objects containing endpoint details.</returns>
702+
/// <exception cref="ArgumentNullException">If <paramref name="tenantId"/> is <see langword="null"/>.</exception>
703+
/// <exception cref="ArgumentException">If <paramref name="tenantId"/> is empty.</exception>
704+
/// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception>
705+
/// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <see langword="null"/> and no default identity is available for the provider.</exception>
706+
/// <exception cref="ResponseException">If the authentication request failed or the token does not exist.</exception>
707+
/// <seealso href="http://developer.openstack.org/api-ref-identity-v2.html#os-kscatalog-ext">OS-KSCATALOG admin extension (Identity API v2.0 - OpenStack Complete API Reference)</seealso>
708+
/// <preliminary/>
709+
public virtual ReadOnlyCollection<ExtendedEndpoint> ListServiceCatalogEndpoints(string tenantId, CloudIdentity identity)
710+
{
711+
if (tenantId == null)
712+
throw new ArgumentNullException("tenantId");
713+
if (string.IsNullOrEmpty(tenantId))
714+
throw new ArgumentException("tenantId cannot be empty");
715+
716+
CheckIdentity(identity);
717+
718+
var response = ExecuteRESTRequest<ListEndpointsResponse>(identity, new Uri(UrlBase, string.Format("/v2.0/tenants/{0}/OS-KSCATALOG/endpoints", tenantId)), HttpMethod.GET);
719+
720+
if (response == null || response.Data == null || response.Data.Endpoints == null)
721+
return null;
722+
723+
return new ReadOnlyCollection<ExtendedEndpoint>(response.Data.Endpoints);
724+
}
725+
726+
/// <summary>
727+
/// Gets an endpoint by ID from the service catalog for a tenant.
728+
/// </summary>
729+
/// <remarks>
730+
/// <para>This call is part of the <c>OS-KSCATALOG</c> extension to the OpenStack Identity Service V2.</para>
731+
/// </remarks>
732+
/// <param name="tenantId">The tenant ID. This is obtained from <see cref="Tenant.Id"/></param>
733+
/// <param name="endpointId">The endpoint ID. This is obtained from <see cref="ExtendedEndpoint.Id"/></param>
734+
/// <param name="identity">The cloud identity to use for this request. If not specified, the <see cref="DefaultIdentity"/> for the current provider instance will be used.</param>
735+
/// <returns>An <see cref="ExtendedEndpoint"/> object containing the endpoint details.</returns>
736+
/// <exception cref="ArgumentNullException">
737+
/// <para>If <paramref name="tenantId"/> is <see langword="null"/>.</para>
738+
/// <para>-or-</para>
739+
/// <para>If <paramref name="endpointId"/> is <see langword="null"/>.</para>
740+
/// </exception>
741+
/// <exception cref="ArgumentException">
742+
/// <para>If <paramref name="tenantId"/> is empty.</para>
743+
/// <para>-or-</para>
744+
/// <para>If <paramref name="endpointId"/> is empty.</para>
745+
/// </exception>
746+
/// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception>
747+
/// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <see langword="null"/> and no default identity is available for the provider.</exception>
748+
/// <exception cref="ResponseException">If the authentication request failed or the token does not exist.</exception>
749+
/// <seealso href="http://developer.openstack.org/api-ref-identity-v2.html#os-kscatalog-ext">OS-KSCATALOG admin extension (Identity API v2.0 - OpenStack Complete API Reference)</seealso>
750+
/// <preliminary/>
751+
public virtual ExtendedEndpoint GetServiceCatalogEndpoint(string tenantId, string endpointId, CloudIdentity identity)
752+
{
753+
if (tenantId == null)
754+
throw new ArgumentNullException("tenantId");
755+
if (endpointId == null)
756+
throw new ArgumentNullException("endpointId");
757+
if (string.IsNullOrEmpty(tenantId))
758+
throw new ArgumentException("tenantId cannot be empty");
759+
if (string.IsNullOrEmpty(endpointId))
760+
throw new ArgumentException("endpointId cannot be empty");
761+
762+
CheckIdentity(identity);
763+
764+
var response = ExecuteRESTRequest<GetEndpointResponse>(identity, new Uri(UrlBase, string.Format("/v2.0/tenants/{0}/OS-KSCATALOG/endpoints/{1}", tenantId, endpointId)), HttpMethod.GET);
765+
766+
if (response == null || response.Data == null)
767+
return null;
768+
769+
return response.Data.Endpoint;
770+
}
771+
772+
/// <summary>
773+
/// Adds an endpoint to the service catalog for a tenant.
774+
/// </summary>
775+
/// <remarks>
776+
/// <para>This call is part of the <c>OS-KSCATALOG</c> extension to the OpenStack Identity Service V2.</para>
777+
/// </remarks>
778+
/// <param name="tenantId">The tenant ID. This is obtained from <see cref="Tenant.Id"/></param>
779+
/// <param name="endpointTemplateId">The endpoint template ID.</param>
780+
/// <param name="identity">The cloud identity to use for this request. If not specified, the <see cref="DefaultIdentity"/> for the current provider instance will be used.</param>
781+
/// <returns>An <see cref="ExtendedEndpoint"/> object containing the endpoint details.</returns>
782+
/// <exception cref="ArgumentNullException">
783+
/// <para>If <paramref name="tenantId"/> is <see langword="null"/>.</para>
784+
/// <para>-or-</para>
785+
/// <para>If <paramref name="endpointTemplateId"/> is <see langword="null"/>.</para>
786+
/// </exception>
787+
/// <exception cref="ArgumentException">If <paramref name="tenantId"/> is empty.</exception>
788+
/// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception>
789+
/// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <see langword="null"/> and no default identity is available for the provider.</exception>
790+
/// <exception cref="ResponseException">If the authentication request failed or the token does not exist.</exception>
791+
/// <seealso href="http://developer.openstack.org/api-ref-identity-v2.html#os-kscatalog-ext">OS-KSCATALOG admin extension (Identity API v2.0 - OpenStack Complete API Reference)</seealso>
792+
/// <preliminary/>
793+
public virtual ExtendedEndpoint AddServiceCatalogEndpoint(string tenantId, EndpointTemplateId endpointTemplateId, CloudIdentity identity)
794+
{
795+
if (tenantId == null)
796+
throw new ArgumentNullException("tenantId");
797+
if (endpointTemplateId == null)
798+
throw new ArgumentNullException("endpointTemplateId");
799+
if (string.IsNullOrEmpty(tenantId))
800+
throw new ArgumentException("tenantId cannot be empty");
801+
802+
CheckIdentity(identity);
803+
804+
var request = new AddServiceCatalogEndpointRequest(endpointTemplateId);
805+
var response = ExecuteRESTRequest<GetEndpointResponse>(identity, new Uri(UrlBase, string.Format("/v2.0/tenants/{0}/OS-KSCATALOG/endpoints", tenantId)), HttpMethod.POST, request);
806+
807+
if (response == null || response.Data == null)
808+
return null;
809+
810+
return response.Data.Endpoint;
811+
}
812+
813+
/// <summary>
814+
/// Removes an endpoint from the service catalog for a tenant.
815+
/// </summary>
816+
/// <remarks>
817+
/// <para>This call is part of the <c>OS-KSCATALOG</c> extension to the OpenStack Identity Service V2.</para>
818+
/// </remarks>
819+
/// <param name="tenantId">The tenant Id. This is obtained from <see cref="Tenant.Id"/></param>
820+
/// <param name="endpointId">The endpoint Id. This is obtained from <see cref="ExtendedEndpoint.Id"/></param>
821+
/// <param name="identity">The cloud identity to use for this request. If not specified, the <see cref="DefaultIdentity"/> for the current provider instance will be used.</param>
822+
/// <returns><see langword="true"/> if the endpoint was successfully deleted; otherwise, <see langword="false"/>.</returns>
823+
/// <exception cref="ArgumentNullException">
824+
/// <para>If <paramref name="tenantId"/> is <see langword="null"/>.</para>
825+
/// <para>-or-</para>
826+
/// <para>If <paramref name="endpointId"/> is <see langword="null"/>.</para>
827+
/// </exception>
828+
/// <exception cref="ArgumentException">
829+
/// <para>If <paramref name="tenantId"/> is empty.</para>
830+
/// <para>-or-</para>
831+
/// <para>If <paramref name="endpointId"/> is empty.</para>
832+
/// </exception>
833+
/// <exception cref="NotSupportedException">If the provider does not support the given <paramref name="identity"/> type.</exception>
834+
/// <exception cref="InvalidOperationException">If <paramref name="identity"/> is <see langword="null"/> and no default identity is available for the provider.</exception>
835+
/// <exception cref="ResponseException">If the authentication request failed or the token does not exist.</exception>
836+
/// <seealso href="http://developer.openstack.org/api-ref-identity-v2.html#os-kscatalog-ext">OS-KSCATALOG admin extension (Identity API v2.0 - OpenStack Complete API Reference)</seealso>
837+
/// <preliminary/>
838+
public virtual bool DeleteServiceCatalogEndpoint(string tenantId, string endpointId, CloudIdentity identity)
839+
{
840+
if (tenantId == null)
841+
throw new ArgumentNullException("tenantId");
842+
if (endpointId == null)
843+
throw new ArgumentNullException("endpointId");
844+
if (string.IsNullOrEmpty(tenantId))
845+
throw new ArgumentException("tenantId cannot be empty");
846+
if (string.IsNullOrEmpty(endpointId))
847+
throw new ArgumentException("endpointId cannot be empty");
848+
849+
CheckIdentity(identity);
850+
851+
var response = ExecuteRESTRequest(identity, new Uri(UrlBase, string.Format("/v2.0/tenants/{0}/OS-KSCATALOG/endpoints/{1}", tenantId, endpointId)), HttpMethod.DELETE);
852+
853+
if (response == null && response.StatusCode != HttpStatusCode.NoContent)
854+
return false;
855+
856+
return true;
857+
}
858+
692859
#endregion
693860

694861
#region Token and Authentication
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
namespace net.openstack.Providers.Rackspace.Objects.Request
2+
{
3+
using System;
4+
using net.openstack.Core.Domain;
5+
using Newtonsoft.Json;
6+
7+
/// <summary>
8+
/// This models the JSON request used for the <strong>Add endpoint</strong> HTTP API request in the OpenStack
9+
/// Identity Service V2.
10+
/// </summary>
11+
/// <remarks>
12+
/// <para>This object is part of the <c>OS-KSCATALOG</c> extension to the OpenStack Identity Service V2.</para>
13+
/// </remarks>
14+
/// <seealso href="http://developer.openstack.org/api-ref-identity-v2.html#os-kscatalog-ext">OS-KSCATALOG admin extension (Identity API v2.0 - OpenStack Complete API Reference)</seealso>
15+
/// <threadsafety static="true" instance="false"/>
16+
/// <preliminary/>
17+
[JsonObject(MemberSerialization.OptIn)]
18+
internal class AddServiceCatalogEndpointRequest
19+
{
20+
/// <summary>
21+
/// This is the backing field for the <see cref="EndpointTemplateId"/> property.
22+
/// </summary>
23+
/// <remarks>
24+
/// <para>This API call wraps the endpoint template identifier inside an "EndpointTemplateWithOnlyId"
25+
/// resource.</para>
26+
/// </remarks>
27+
[JsonProperty("OS-KSCATALOG:endpointTemplate", DefaultValueHandling = DefaultValueHandling.Ignore)]
28+
private EndpointTemplate _endpointTemplate;
29+
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="AddServiceCatalogEndpointRequest"/> class
32+
/// during JSON deserialization.
33+
/// </summary>
34+
[JsonConstructor]
35+
protected AddServiceCatalogEndpointRequest()
36+
{
37+
}
38+
39+
/// <summary>
40+
/// Initializes a new instance of the <see cref="AddServiceCatalogEndpointRequest"/> class with the specified
41+
/// endpoint template identifier.
42+
/// </summary>
43+
/// <param name="endpointTemplateId">
44+
/// The unique identifier of the endpoint template to use for the endpoint.
45+
/// </param>
46+
/// <exception cref="ArgumentNullException">
47+
/// If <paramref name="endpointTemplateId"/> is <see langword="null"/>.
48+
/// </exception>
49+
public AddServiceCatalogEndpointRequest(EndpointTemplateId endpointTemplateId)
50+
{
51+
if (endpointTemplateId == null)
52+
throw new ArgumentNullException("endpointTemplateId");
53+
54+
_endpointTemplate = new EndpointTemplate(endpointTemplateId);
55+
}
56+
57+
/// <summary>
58+
/// Gets the unique identifier of the endpoint template to use when creating the endpoint.
59+
/// </summary>
60+
/// <value>
61+
/// <para>The unique identifier of the endpoint template to use when creating the endpoint.</para>
62+
/// <token>NullIfNotIncluded</token>
63+
/// </value>
64+
public EndpointTemplateId EndpointTemplateId
65+
{
66+
get
67+
{
68+
if (_endpointTemplate == null)
69+
return null;
70+
71+
return _endpointTemplate.Id;
72+
}
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)