예제 #1
0
        public void SetPrivateKey()
        {
            JObject result = GetJsonContent();
            string  key    = result == null ? null : result.Value <string>(KeyParameterName);

            if (result == null || String.IsNullOrEmpty(key))
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentNullException(KeyParameterName)));
            }

            using (_tracer.Step("SSHKeyController.SetPrivateKey"))
            {
                _sshKeyLock.LockOrWait(() =>
                {
                    try
                    {
                        _sshKeyManager.SetPrivateKey(key);
                    }
                    catch (ArgumentException ex)
                    {
                        throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
                    }
                    catch (InvalidOperationException ex)
                    {
                        throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Conflict, ex));
                    }
                }, TimeSpan.FromSeconds(5));
            }
        }
예제 #2
0
        public void SetPrivateKey()
        {
            string key;

            if (IsContentType("application/json"))
            {
                JObject result = GetJsonContent();
                key = result == null ? null : result.Value <string>(KeyParameterName);
            }
            else
            {
                // any other content-type assuming the content is key
                // curl http://server/sshkey -X PUT --upload-file /c/temp/id_rsa
                key = Request.Content.ReadAsStringAsync().Result;
            }

            if (String.IsNullOrEmpty(key))
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, new ArgumentNullException(KeyParameterName)));
            }

            using (_tracer.Step("SSHKeyController.SetPrivateKey"))
            {
                _sshKeyLock.LockOrWait(() =>
                {
                    try
                    {
                        _sshKeyManager.SetPrivateKey(key);
                    }
                    catch (ArgumentException ex)
                    {
                        throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
                    }
                    catch (InvalidOperationException ex)
                    {
                        throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Conflict, ex));
                    }
                }, TimeSpan.FromSeconds(5));
            }
        }