Beispiel #1
0
 /// <summary>
 /// Bind the service instance.
 /// </summary>
 /// <param name="service">The service instance.</param>
 /// <param name="binding">Binding information.</param>
 private static void Bind(ProvisionedService service, ServiceBinding binding)
 {
     if (!WindowsUsersAndGroups.ExistsUser(binding.User))
     {
         CreateInstanceUser(service.Name, binding.User, binding.Password);
         AddInstanceUserToGroup(service.Name, binding.User);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Binds a shared directory to an app.
        /// </summary>
        /// <param name="name">The name of the service.</param>
        /// <param name="bindOptions">Binding options.</param>
        /// <param name="credentials">Already existing credentials.</param>
        /// <returns>
        /// A new set of credentials used for binding.
        /// </returns>
        protected override ServiceCredentials Bind(string name, Dictionary<string, object> bindOptions, ServiceCredentials credentials)
        {
            Logger.Debug(Strings.SqlNodeBindServiceDebugMessage, name, JsonConvertibleObject.SerializeToJson(bindOptions));

            ProvisionedService service = ProvisionedService.GetService(name);
            if (service == null)
            {
                throw new FileServiceErrorException(FileServiceErrorException.FileServiceConfigNotFound, name);
            }

            string user = null;
            string password = null;

            if (credentials != null)
            {
                user = credentials.User;
                password = credentials.Password;
            }
            else
            {
                user = "******" + Credentials.GenerateCredential();
                password = "******" + Credentials.GenerateCredential();
            }

            var binding = new ServiceBinding
                {
                    User = user,
                    Password = password
                };

            Bind(service, binding);

            service.Bindings.Add(binding);

            if (!ProvisionedService.Save())
            {
                Logger.Error(Strings.SqlNodeCannotSaveProvisionedServicesErrorMessage, credentials == null ? string.Empty : credentials.SerializeToJson());
                throw new FileServiceErrorException(FileServiceErrorException.FileServiceLocalDBError);
            }

            ServiceCredentials response = this.GenerateCredential(name, user, password, service.Port.Value);

            Logger.Debug(Strings.SqlNodeBindResponseDebugMessage, response.SerializeToJson());
            this.bindingServed += 1;

            return response;
        }