Esempio n. 1
0
        public Function Add(string clientName)
        {
            ReturnType rt = new ReturnType();

            Logger.log("info", "Attempting to create client: " + clientName);

            ChefRequest cr = new ChefRequest();

            Dictionary<string, string> dictClient = new Dictionary<string, string>()
            {
                { "name", clientName },
                { "admin", "false" }
            };

            string json = JsonConvert.SerializeObject(dictClient, Formatting.Indented);
            string response = cr.Post(ChefConfig.Validator, "clients", json);
            if (response.Contains("409") && response.Contains("Conflict"))
            {
                rt.Result = 3;
                rt.Message = "Client already exists.";
                return rt;
            }
            else if (response.Contains("BEGIN RSA PRIVATE KEY"))
            {
                KeyHelper kh = new KeyHelper();
                rt = kh.Format(response);
                return rt;
            }
            else
            {
                rt.Result = 4;
                rt.Message = "Error creating Client, API response: " + response;
                return rt;
            }
        }