/// <summary> /// Gets the role name from the <see cref="StreamAccessKinds"/> and the stream name. /// </summary> /// <param name="singleStreamAccessKind">Single <see cref="StreamAccessKinds"/>.</param> /// <param name="streamName">Name of the stream.</param> /// <returns>Name of role.</returns> public static string GetRoleNameFromStreamAccessKind( StreamAccessKinds singleStreamAccessKind, string streamName) { var streamAccessKindsIndividualItems = singleStreamAccessKind.GetIndividualFlags(); streamAccessKindsIndividualItems.Count.MustForArg(nameof(streamAccessKindsIndividualItems)).BeEqualTo(1, "Can only convert a single flag to a role name."); var roleName = streamAccessKindsIndividualItems.Single().ToString(); var result = Invariant($@"{streamName}-{roleName}"); return(result); }
/// <summary> /// Initializes a new instance of the <see cref="CreateStreamUserOp"/> class. /// </summary> /// <param name="loginName">The login name of the user.</param> /// <param name="userName">The username of the user.</param> /// <param name="clearTextPassword">The clear text password.</param> /// <param name="streamAccessKinds"><see cref="Database.Domain.StreamAccessKinds"/> to grant access for.</param> /// <param name="shouldCreateLogin">A value indicating whether or not to create the login or look it up.</param> public CreateStreamUserOp( string loginName, string userName, string clearTextPassword, StreamAccessKinds streamAccessKinds, bool shouldCreateLogin) { userName.MustForArg(nameof(userName)).NotBeNullNorWhiteSpace().And().BeAlphanumeric(new[] { '-' }); streamAccessKinds.MustForArg(nameof(streamAccessKinds)).NotBeEqualTo(Database.Domain.StreamAccessKinds.None); if (shouldCreateLogin) { clearTextPassword.MustForArg(nameof(clearTextPassword)).NotBeNullNorWhiteSpace(); } else { loginName.MustForArg(nameof(loginName)).NotBeNullNorWhiteSpace(); } if (!string.IsNullOrWhiteSpace(loginName)) { loginName.MustForArg(nameof(loginName)).BeAlphanumeric(new[] { '-' }); } var individualStreamAccessKinds = streamAccessKinds.GetIndividualFlags <StreamAccessKinds>(); if (individualStreamAccessKinds.Except(CreateStreamUserOp.SupportedStreamAccessKinds).Any()) { var supportedValuesString = SupportedStreamAccessKinds.Select(_ => _.ToString()).ToDelimitedString(","); var providedValuesString = individualStreamAccessKinds.Select(_ => _.ToString()).ToDelimitedString(","); throw new ArgumentException(Invariant($"Unsupported access type provided; supported: '{supportedValuesString}', provided: '{providedValuesString}'."), nameof(streamAccessKinds)); } this.LoginName = loginName; this.UserName = userName; this.ClearTextPassword = clearTextPassword; this.StreamAccessKinds = streamAccessKinds; this.ShouldCreateLogin = shouldCreateLogin; }