Esempio n. 1
0
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/admin/certificates";

                var request = new HttpRequestMessage
                {
                    Method = HttpMethod.Post
                };

                request.Content = new BlittableJsonContent(stream =>
                {
                    using (var writer = new BlittableJsonTextWriter(ctx, stream))
                    {
                        writer.WriteStartObject();

                        writer.WritePropertyName(nameof(CertificateDefinition.Name));
                        writer.WriteString(_name.ToString());
                        writer.WriteComma();
                        writer.WritePropertyName(nameof(SecurityClearance));
                        writer.WriteString(_clearance.ToString());
                        writer.WriteComma();

                        if (_password != null)
                        {
                            writer.WritePropertyName(nameof(CertificateDefinition.Password));
                            writer.WriteString(_password);
                            writer.WriteComma();
                        }

                        writer.WritePropertyName(nameof(CertificateDefinition.Permissions));
                        writer.WriteStartObject();
                        bool first = true;
                        foreach (var kvp in _permissions)
                        {
                            if (first == false)
                            {
                                writer.WriteComma();
                            }
                            first = false;

                            writer.WriteString(kvp.Key);
                            writer.WriteComma();
                            writer.WriteString(kvp.Value.ToString());
                        }
                        writer.WriteEndObject();

                        writer.WriteEndObject();
                    }
                });

                return(request);
            }
            public override HttpRequestMessage CreateRequest(JsonOperationContext ctx, ServerNode node, out string url)
            {
                url = $"{node.Url}/admin/certificates";

                var request = new HttpRequestMessage
                {
                    Method  = HttpMethod.Put,
                    Content = new BlittableJsonContent(stream =>
                    {
                        using (var writer = new BlittableJsonTextWriter(ctx, stream))
                        {
                            writer.WriteStartObject();
                            writer.WritePropertyName(nameof(CertificateDefinition.Name));
                            writer.WriteString(_name.ToString());
                            writer.WriteComma();
                            writer.WritePropertyName(nameof(CertificateDefinition.Certificate));
                            writer.WriteString(Convert.ToBase64String(_certificate.Export(X509ContentType.Cert)));
                            writer.WriteComma();
                            writer.WritePropertyName(nameof(CertificateDefinition.SecurityClearance));
                            writer.WriteString(_clearance.ToString());
                            writer.WriteComma();

                            writer.WritePropertyName(nameof(CertificateDefinition.Permissions));
                            writer.WriteStartObject();
                            bool first = true;
                            foreach (var kvp in _permissions)
                            {
                                if (first == false)
                                {
                                    writer.WriteComma();
                                }
                                first = false;

                                writer.WriteString(kvp.Key);
                                writer.WriteComma();
                                writer.WriteString(kvp.Value == DatabaseAccess.ReadWrite ? nameof(DatabaseAccess.ReadWrite) : nameof(DatabaseAccess.Admin));
                            }

                            writer.WriteEndObject();
                            writer.WriteEndObject();
                        }
                    })
                };

                return(request);
            }