|
| 1 | +// Copyright © 2024-Present The Serverless Workflow Specification Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"), |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +namespace ServerlessWorkflow.Sdk.Builders; |
| 15 | + |
| 16 | +/// <summary> |
| 17 | +/// Represents the default implementation of the <see cref="IDigestAuthenticationSchemeDefinitionBuilder"/> interface |
| 18 | +/// </summary> |
| 19 | +public class DigestAuthenticationSchemeDefinitionBuilder |
| 20 | + : AuthenticationSchemeDefinitionBuilder<DigestAuthenticationSchemeDefinition>, IDigestAuthenticationSchemeDefinitionBuilder |
| 21 | +{ |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// Gets/sets the username to use |
| 25 | + /// </summary> |
| 26 | + protected string? Username { get; set; } |
| 27 | + |
| 28 | + /// <summary> |
| 29 | + /// Gets/sets the password to use |
| 30 | + /// </summary> |
| 31 | + protected string? Password { get; set; } |
| 32 | + |
| 33 | + /// <inheritdoc/> |
| 34 | + public virtual IDigestAuthenticationSchemeDefinitionBuilder WithUsername(string username) |
| 35 | + { |
| 36 | + ArgumentException.ThrowIfNullOrWhiteSpace(username); |
| 37 | + this.Username = username; |
| 38 | + return this; |
| 39 | + } |
| 40 | + |
| 41 | + /// <inheritdoc/> |
| 42 | + public virtual IDigestAuthenticationSchemeDefinitionBuilder WithPassword(string password) |
| 43 | + { |
| 44 | + ArgumentException.ThrowIfNullOrWhiteSpace(password); |
| 45 | + this.Password = password; |
| 46 | + return this; |
| 47 | + } |
| 48 | + |
| 49 | + /// <inheritdoc/> |
| 50 | + public override DigestAuthenticationSchemeDefinition Build() |
| 51 | + { |
| 52 | + if (string.IsNullOrWhiteSpace(this.Username)) throw new NullReferenceException("The username must be set"); |
| 53 | + if (string.IsNullOrWhiteSpace(this.Password)) throw new NullReferenceException("The password must be set"); |
| 54 | + return new() |
| 55 | + { |
| 56 | + Use = this.Secret, |
| 57 | + Username = this.Username, |
| 58 | + Password = this.Password |
| 59 | + }; |
| 60 | + } |
| 61 | + |
| 62 | + AuthenticationSchemeDefinition IAuthenticationSchemeDefinitionBuilder.Build() => this.Build(); |
| 63 | + |
| 64 | +} |
0 commit comments