Skip to content

Commit 8b56cf6

Browse files
committed
Merge pull request #502 from sharwell/cdn-review
Fix build errors and consistency issues in CDN implementation
2 parents c16a59a + 49bfb33 commit 8b56cf6

File tree

6 files changed

+45
-49
lines changed

6 files changed

+45
-49
lines changed

src/OpenStack.Net/OpenStack.Net.netcore45.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<NTVersion>$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion@CurrentVersion)</NTVersion>
2424
<IsWindows81 Condition="'$(NTVersion)' == '6.3'">True</IsWindows81>
2525
<TargetPlatformVersion Condition="'$(IsWindows81)' == 'True'">8.1</TargetPlatformVersion>
26-
<TargetFrameworkVersion Condition="'$(IsWindows81)' == 'True'"/>
26+
<TargetFrameworkVersion Condition="'$(IsWindows81)' == 'True'" />
2727
</PropertyGroup>
2828
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2929
<DebugSymbols>true</DebugSymbols>
@@ -118,10 +118,12 @@
118118
<Compile Include="OpenStack\Security\Authentication\NamespaceDoc.cs" />
119119
<Compile Include="OpenStack\Security\Authentication\PassThroughAuthenticationService.cs" />
120120
<Compile Include="OpenStack\Services\ContentDelivery\V1\AddFlavorApiCall.cs" />
121+
<Compile Include="OpenStack\Services\ContentDelivery\V1\AddOperation.cs" />
121122
<Compile Include="OpenStack\Services\ContentDelivery\V1\AddServiceApiCall.cs" />
122123
<Compile Include="OpenStack\Services\ContentDelivery\V1\ContentDeliveryClient.cs" />
123124
<Compile Include="OpenStack\Services\ContentDelivery\V1\ContentDeliveryServiceExtensionDefinition`1.cs" />
124125
<Compile Include="OpenStack\Services\ContentDelivery\V1\ContentDeliveryServiceExtensions.cs" />
126+
<Compile Include="OpenStack\Services\ContentDelivery\V1\CopyOperation.cs" />
125127
<Compile Include="OpenStack\Services\ContentDelivery\V1\Flavor.cs" />
126128
<Compile Include="OpenStack\Services\ContentDelivery\V1\FlavorData.cs" />
127129
<Compile Include="OpenStack\Services\ContentDelivery\V1\FlavorId.cs" />
@@ -133,13 +135,20 @@
133135
<Compile Include="OpenStack\Services\ContentDelivery\V1\GetServiceApiCall.cs" />
134136
<Compile Include="OpenStack\Services\ContentDelivery\V1\GetSubsystemHealthApiCall.cs" />
135137
<Compile Include="OpenStack\Services\ContentDelivery\V1\IContentDeliveryService.cs" />
138+
<Compile Include="OpenStack\Services\ContentDelivery\V1\JsonDiffer.cs" />
139+
<Compile Include="OpenStack\Services\ContentDelivery\V1\JsonPointer.cs" />
136140
<Compile Include="OpenStack\Services\ContentDelivery\V1\ListFlavorsApiCall.cs" />
137141
<Compile Include="OpenStack\Services\ContentDelivery\V1\ListServicesApiCall.cs" />
138142
<Compile Include="OpenStack\Services\ContentDelivery\V1\ListServicesExtensions.cs" />
143+
<Compile Include="OpenStack\Services\ContentDelivery\V1\MoveOperation.cs" />
144+
<Compile Include="OpenStack\Services\ContentDelivery\V1\Operation.cs" />
145+
<Compile Include="OpenStack\Services\ContentDelivery\V1\PatchDocument.cs" />
139146
<Compile Include="OpenStack\Services\ContentDelivery\V1\PingApiCall.cs" />
140147
<Compile Include="OpenStack\Services\ContentDelivery\V1\RemoveAssetApiCall.cs" />
141148
<Compile Include="OpenStack\Services\ContentDelivery\V1\RemoveFlavorApiCall.cs" />
149+
<Compile Include="OpenStack\Services\ContentDelivery\V1\RemoveOperation.cs" />
142150
<Compile Include="OpenStack\Services\ContentDelivery\V1\RemoveServiceApiCall.cs" />
151+
<Compile Include="OpenStack\Services\ContentDelivery\V1\ReplaceOperation.cs" />
143152
<Compile Include="OpenStack\Services\ContentDelivery\V1\Service.cs" />
144153
<Compile Include="OpenStack\Services\ContentDelivery\V1\ServiceCache.cs" />
145154
<Compile Include="OpenStack\Services\ContentDelivery\V1\ServiceCacheRule.cs" />
@@ -154,6 +163,7 @@
154163
<Compile Include="OpenStack\Services\ContentDelivery\V1\ServiceRestrictionRule.cs" />
155164
<Compile Include="OpenStack\Services\ContentDelivery\V1\ServiceStatus.cs" />
156165
<Compile Include="OpenStack\Services\ContentDelivery\V1\SubsystemId.cs" />
166+
<Compile Include="OpenStack\Services\ContentDelivery\V1\TestOperation.cs" />
157167
<Compile Include="OpenStack\Services\ContentDelivery\V1\UpdateServiceApiCall.cs" />
158168
<Compile Include="OpenStack\Services\Identity\ApiStatus.cs" />
159169
<Compile Include="OpenStack\Services\Identity\ApiVersion.cs" />

src/OpenStack.Net/OpenStack/Services/ContentDelivery/V1/ContentDeliveryClient.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public virtual Task<GetHomeApiCall> PrepareGetHomeAsync(CancellationToken cancel
5757
UriTemplate template = new UriTemplate(string.Empty);
5858
Dictionary<string, string> parameters = new Dictionary<string, string>();
5959
return GetBaseUriAsync(cancellationToken)
60-
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
60+
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
6161
.Select(task => new GetHomeApiCall(CreateJsonApiCall<HomeDocument>(task.Result)));
6262
}
6363

@@ -79,7 +79,7 @@ public virtual Task<PingApiCall> PreparePingAsync(CancellationToken cancellation
7979
UriTemplate template = new UriTemplate("ping");
8080
Dictionary<string, string> parameters = new Dictionary<string, string>();
8181
return GetBaseUriAsync(cancellationToken)
82-
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
82+
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
8383
//.Select(RemoveAcceptHeader) **DLS**
8484
.Select(task => new PingApiCall(CreateBasicApiCall(task.Result)));
8585
}
@@ -174,44 +174,44 @@ public virtual Task<UpdateServiceApiCall> PrepareUpdateServiceAsync(ServiceId se
174174
if (serviceId == null)
175175
throw new ArgumentNullException("serviceId");
176176

177-
178-
179177
// At this point, the serviceData parameter contains the NEW (AFTER) version
180178
// of the service data. Now, we need to retrieve the current (BEFORE) version,
181179
// then use those to calculate the difference, i.e. the JSON Patch document.
182-
CancellationToken cn = new CancellationToken();
183-
var getServiceTask = ContentDeliveryServiceExtensions.GetServiceAsync(this, serviceId, cn);
184-
getServiceTask.Wait();
185-
ServiceData originalServiceData = getServiceTask.Result;
186-
187-
180+
return this.GetServiceAsync(serviceId, cancellationToken)
181+
.Then(task => PrepareUpdateServiceFromExistingAsync(serviceId, updatedServiceData, task.Result, cancellationToken));
182+
}
188183

184+
protected virtual Task<UpdateServiceApiCall> PrepareUpdateServiceFromExistingAsync(ServiceId serviceId, ServiceData updatedServiceData, ServiceData originalServiceData, CancellationToken cancellationToken)
185+
{
189186
// Here's a serious HACK: Because the current ServiceData includes properties
190187
// that are not part of a new instance of ServiceData (such as "Id", "Status" and others)
191188
// we need to create a new instance using the data from the current ServiceData object.
192189
// That way, when we perform the "DIFF" operation to calculate the JSon Patch object,
193190
// the extra properties won't interfere.
194191
ServiceData tempServiceData = new ServiceData(originalServiceData.Name, originalServiceData.FlavorId, originalServiceData.Domains, originalServiceData.Origins, originalServiceData.CachingRules, originalServiceData.Restrictions);
195192

196-
197-
198193
// Calculate the Json Patch document
199194
var beforeUpdate = JToken.Parse(JsonConvert.SerializeObject(tempServiceData));
200195
var afterUpdate = JToken.Parse(JsonConvert.SerializeObject(updatedServiceData));
201196
var patchDoc = new JsonDiffer().Diff(beforeUpdate, afterUpdate);
202197

203-
204198
// Another Hack: For some reason (TODO: which needs to be investigated and fixed),
205199
// we need to deserialize the document in order for it to render a proper Json object.
206200
var jsonPatchDocument = JsonConvert.DeserializeObject(patchDoc.ToString());
207201

208-
209202
// Now we can call the PATCH method to update the ServiceData on the server.
210203
UriTemplate template = new UriTemplate("services/{service_id}");
211204
Dictionary<string, string> parameters = new Dictionary<string, string> { { "service_id", serviceId.Value } };
205+
212206
return GetBaseUriAsync(cancellationToken)
213-
.Then(PrepareRequestAsyncFunc(new HttpMethod("PATCH"), "application/json-patch+json", template, parameters, jsonPatchDocument, cancellationToken))
214-
.Select(task => new UpdateServiceApiCall(CreateBasicApiCall(task.Result)));
207+
.Then(PrepareRequestAsyncFunc(new HttpMethod("PATCH"), template, parameters, jsonPatchDocument, cancellationToken))
208+
.Select(
209+
task =>
210+
{
211+
HttpRequestMessage requestMessage = task.Result;
212+
requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json-patch+json");
213+
return new UpdateServiceApiCall(CreateBasicApiCall(requestMessage));
214+
});
215215
}
216216

217217
/// <inheritdoc/>

src/OpenStack.Net/OpenStack/Services/IHttpService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public interface IHttpService : IDisposable
3838
/// <para>-or-</para>
3939
/// <para>If <paramref name="parameters"/> is <see langword="null"/>.</para>
4040
/// </exception>
41-
Func<Task<Uri>, Task<HttpRequestMessage>> PrepareRequestAsyncFunc<T>(HttpMethod method, UriTemplate template, IDictionary<string, T> parameters, CancellationToken cancellationToken, string mediaType);
41+
Func<Task<Uri>, Task<HttpRequestMessage>> PrepareRequestAsyncFunc<T>(HttpMethod method, UriTemplate template, IDictionary<string, T> parameters, CancellationToken cancellationToken);
4242

4343
/// <summary>
4444
/// Creates a task continuation function responsible for creating an <see cref="HttpRequestMessage"/> for use in
@@ -66,7 +66,7 @@ public interface IHttpService : IDisposable
6666
/// <para>-or-</para>
6767
/// <para>If <paramref name="parameters"/> is <see langword="null"/>.</para>
6868
/// </exception>
69-
Func<Task<Uri>, Task<HttpRequestMessage>> PrepareRequestAsyncFunc<T, TBody>(HttpMethod method, UriTemplate template, IDictionary<string, T> parameters, TBody body, CancellationToken cancellationToken, string mediaType);
69+
Func<Task<Uri>, Task<HttpRequestMessage>> PrepareRequestAsyncFunc<T, TBody>(HttpMethod method, UriTemplate template, IDictionary<string, T> parameters, TBody body, CancellationToken cancellationToken);
7070

7171
/// <summary>
7272
/// Gets the base absolute URI to use for making asynchronous HTTP API calls to this service.

src/OpenStack.Net/OpenStack/Services/Identity/BaseIdentityClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public virtual Task<ListApiVersionsApiCall> PrepareListApiVersionsAsync(Cancella
141141
};
142142

143143
return GetBaseUriAsync(cancellationToken)
144-
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
144+
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
145145
.Select(task => new ListApiVersionsApiCall(CreateCustomApiCall(task.Result, HttpCompletionOption.ResponseContentRead, deserializeResult)));
146146
}
147147

@@ -152,7 +152,7 @@ public virtual Task<GetApiVersionApiCall> PrepareGetApiVersionAsync(ApiVersionId
152152
Dictionary<string, string> parameters = new Dictionary<string, string> { { "version_id", apiVersionId.Value } };
153153

154154
return GetBaseUriAsync(cancellationToken)
155-
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
155+
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
156156
.Select(task => new GetApiVersionApiCall(CreateJsonApiCall<ApiVersionResponse>(task.Result)));
157157
}
158158

src/OpenStack.Net/OpenStack/Services/Identity/V2/IdentityClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public virtual Task<ListExtensionsApiCall> PrepareListExtensionsAsync(Cancellati
127127
};
128128

129129
return GetBaseUriAsync(cancellationToken)
130-
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
130+
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
131131
.Select(task => new ListExtensionsApiCall(CreateCustomApiCall(task.Result, HttpCompletionOption.ResponseContentRead, deserializeResult)));
132132
}
133133

@@ -141,7 +141,7 @@ public virtual Task<GetExtensionApiCall> PrepareGetExtensionAsync(ExtensionAlias
141141
Dictionary<string, string> parameters = new Dictionary<string, string> { { "alias", alias.Value } };
142142

143143
return GetBaseUriAsync(cancellationToken)
144-
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
144+
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
145145
.Select(task => new GetExtensionApiCall(CreateJsonApiCall<ExtensionResponse>(task.Result)));
146146
}
147147

@@ -152,7 +152,7 @@ public virtual Task<AuthenticateApiCall> PrepareAuthenticateAsync(Authentication
152152
Dictionary<string, string> parameters = new Dictionary<string, string>();
153153

154154
return GetBaseUriAsync(cancellationToken)
155-
.Then(PrepareRequestAsyncFunc(HttpMethod.Post, template, parameters, request, cancellationToken, "application/json"))
155+
.Then(PrepareRequestAsyncFunc(HttpMethod.Post, template, parameters, request, cancellationToken))
156156
.Select(task => new AuthenticateApiCall(CreateJsonApiCall<AccessResponse>(task.Result)));
157157
}
158158

@@ -208,7 +208,7 @@ public virtual Task<ListTenantsApiCall> PrepareListTenantsAsync(CancellationToke
208208
};
209209

210210
return GetBaseUriAsync(cancellationToken)
211-
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken, "application/json"))
211+
.Then(PrepareRequestAsyncFunc(HttpMethod.Get, template, parameters, cancellationToken))
212212
.Select(task => new ListTenantsApiCall(CreateCustomApiCall(task.Result, HttpCompletionOption.ResponseContentRead, deserializeResult)));
213213
}
214214

0 commit comments

Comments
 (0)