You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "Maxxx873 (via GitHub)" <gi...@apache.org> on 2024/06/09 20:47:40 UTC
[PR] JAMES-3946 Add a DropLists postgresql backend [james-project]
Maxxx873 opened a new pull request, #2290:
URL: https://github.com/apache/james-project/pull/2290
(no comment)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-3946 Add a DropLists postgresql backend [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa merged PR #2290:
URL: https://github.com/apache/james-project/pull/2290
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-3946 Add a DropLists postgresql backend [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on PR #2290:
URL: https://github.com/apache/james-project/pull/2290#issuecomment-2175252185
And here we go!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-3946 Add a DropLists postgresql backend [james-project]
Posted by "chibenwa (via GitHub)" <gi...@apache.org>.
chibenwa commented on PR #2290:
URL: https://github.com/apache/james-project/pull/2290#issuecomment-2173619429
It would be wonderful to get the CI to validate the latest diff.
I relaunched a build.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-3946 Add a DropLists postgresql backend [james-project]
Posted by "Maxxx873 (via GitHub)" <gi...@apache.org>.
Maxxx873 commented on code in PR #2290:
URL: https://github.com/apache/james-project/pull/2290#discussion_r1636858376
##########
server/data/data-postgres/src/main/java/org/apache/james/droplists/postgres/PostgresDropList.java:
##########
@@ -0,0 +1,127 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.droplists.postgres;
+
+import static org.apache.james.backends.postgres.utils.PostgresExecutor.DEFAULT_INJECT;
+import static org.apache.james.droplists.api.DeniedEntityType.DOMAIN;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.DENIED_ENTITY;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.DENIED_ENTITY_TYPE;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.DROPLIST_ID;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.OWNER;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.OWNER_SCOPE;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.TABLE_NAME;
+
+import java.util.List;
+import java.util.UUID;
+
+import jakarta.inject.Inject;
+import jakarta.inject.Named;
+import jakarta.mail.internet.AddressException;
+
+import org.apache.james.backends.postgres.utils.PostgresExecutor;
+import org.apache.james.core.Domain;
+import org.apache.james.core.MailAddress;
+import org.apache.james.droplists.api.DropList;
+import org.apache.james.droplists.api.DropListEntry;
+import org.apache.james.droplists.api.OwnerScope;
+import org.jooq.Record;
+
+import com.google.common.base.Preconditions;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public class PostgresDropList implements DropList {
+ private final PostgresExecutor postgresExecutor;
+
+ @Inject
+ public PostgresDropList(@Named(DEFAULT_INJECT) PostgresExecutor postgresExecutor) {
+ this.postgresExecutor = postgresExecutor;
+ }
+
+ @Override
+ public Mono<Void> add(DropListEntry entry) {
+ Preconditions.checkArgument(entry != null);
+ String specifiedOwner = entry.getOwnerScope().equals(OwnerScope.GLOBAL) ? "" : entry.getOwner();
+ return postgresExecutor.executeVoid(dslContext ->
+ Mono.from(dslContext.insertInto(TABLE_NAME, DROPLIST_ID, OWNER_SCOPE, OWNER, DENIED_ENTITY_TYPE, DENIED_ENTITY)
+ .values(UUID.randomUUID(),
+ entry.getOwnerScope().name(),
+ specifiedOwner,
+ entry.getDeniedEntityType().name(),
+ entry.getDeniedEntity())
+ )
+ );
+ }
+
+ @Override
+ public Mono<Void> remove(DropListEntry entry) {
+ Preconditions.checkArgument(entry != null);
+ return postgresExecutor.executeVoid(dsl -> Mono.from(dsl.deleteFrom(TABLE_NAME)
+ .where(OWNER_SCOPE.eq(entry.getOwnerScope().name()))
+ .and(OWNER.eq(entry.getOwner()))
+ .and(DENIED_ENTITY.eq(entry.getDeniedEntity()))));
+ }
+
+ @Override
+ public Flux<DropListEntry> list(OwnerScope ownerScope, String owner) {
+ Preconditions.checkArgument(ownerScope != null);
+ Preconditions.checkArgument(owner != null);
+ return postgresExecutor.executeRows(dsl -> Flux.from(dsl.selectFrom(TABLE_NAME)
+ .where(OWNER_SCOPE.eq(ownerScope.name()))
+ .and(OWNER.eq(owner))))
Review Comment:
thank you for your valuable comments!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-3946 Add a DropLists postgresql backend [james-project]
Posted by "quantranhong1999 (via GitHub)" <gi...@apache.org>.
quantranhong1999 commented on code in PR #2290:
URL: https://github.com/apache/james-project/pull/2290#discussion_r1635783861
##########
server/data/data-postgres/src/main/java/org/apache/james/droplists/postgres/PostgresDropList.java:
##########
@@ -0,0 +1,127 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.droplists.postgres;
+
+import static org.apache.james.backends.postgres.utils.PostgresExecutor.DEFAULT_INJECT;
+import static org.apache.james.droplists.api.DeniedEntityType.DOMAIN;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.DENIED_ENTITY;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.DENIED_ENTITY_TYPE;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.DROPLIST_ID;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.OWNER;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.OWNER_SCOPE;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.TABLE_NAME;
+
+import java.util.List;
+import java.util.UUID;
+
+import jakarta.inject.Inject;
+import jakarta.inject.Named;
+import jakarta.mail.internet.AddressException;
+
+import org.apache.james.backends.postgres.utils.PostgresExecutor;
+import org.apache.james.core.Domain;
+import org.apache.james.core.MailAddress;
+import org.apache.james.droplists.api.DropList;
+import org.apache.james.droplists.api.DropListEntry;
+import org.apache.james.droplists.api.OwnerScope;
+import org.jooq.Record;
+
+import com.google.common.base.Preconditions;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public class PostgresDropList implements DropList {
+ private final PostgresExecutor postgresExecutor;
+
+ @Inject
+ public PostgresDropList(@Named(DEFAULT_INJECT) PostgresExecutor postgresExecutor) {
+ this.postgresExecutor = postgresExecutor;
+ }
+
+ @Override
+ public Mono<Void> add(DropListEntry entry) {
+ Preconditions.checkArgument(entry != null);
+ String specifiedOwner = entry.getOwnerScope().equals(OwnerScope.GLOBAL) ? "" : entry.getOwner();
+ return postgresExecutor.executeVoid(dslContext ->
+ Mono.from(dslContext.insertInto(TABLE_NAME, DROPLIST_ID, OWNER_SCOPE, OWNER, DENIED_ENTITY_TYPE, DENIED_ENTITY)
+ .values(UUID.randomUUID(),
+ entry.getOwnerScope().name(),
+ specifiedOwner,
+ entry.getDeniedEntityType().name(),
+ entry.getDeniedEntity())
+ )
+ );
+ }
+
+ @Override
+ public Mono<Void> remove(DropListEntry entry) {
+ Preconditions.checkArgument(entry != null);
+ return postgresExecutor.executeVoid(dsl -> Mono.from(dsl.deleteFrom(TABLE_NAME)
+ .where(OWNER_SCOPE.eq(entry.getOwnerScope().name()))
+ .and(OWNER.eq(entry.getOwner()))
+ .and(DENIED_ENTITY.eq(entry.getDeniedEntity()))));
+ }
+
+ @Override
+ public Flux<DropListEntry> list(OwnerScope ownerScope, String owner) {
+ Preconditions.checkArgument(ownerScope != null);
+ Preconditions.checkArgument(owner != null);
+ return postgresExecutor.executeRows(dsl -> Flux.from(dsl.selectFrom(TABLE_NAME)
+ .where(OWNER_SCOPE.eq(ownerScope.name()))
+ .and(OWNER.eq(owner))))
Review Comment:
We should add an index for (OWNER_SCOPE, OWNER) IMO.
Maybe another one for (OWNER_SCOPE, OWNER, DENIED_ENTITY)
##########
server/data/data-postgres/src/main/java/org/apache/james/droplists/postgres/PostgresDropListModule.java:
##########
@@ -0,0 +1,57 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.droplists.postgres;
+
+import java.util.UUID;
+
+import org.apache.james.backends.postgres.PostgresModule;
+import org.apache.james.backends.postgres.PostgresTable;
+import org.jooq.Field;
+import org.jooq.Record;
+import org.jooq.Table;
+import org.jooq.impl.DSL;
+import org.jooq.impl.SQLDataType;
+
+public interface PostgresDropListModule {
+ interface PostgresDropListsTable {
+ Table<Record> TABLE_NAME = DSL.table("droplist");
+
+ Field<UUID> DROPLIST_ID = DSL.field("droplist_id", SQLDataType.UUID.notNull());
+ Field<String> OWNER_SCOPE = DSL.field("owner_scope", SQLDataType.VARCHAR);
+ Field<String> OWNER = DSL.field("owner", SQLDataType.VARCHAR);
+ Field<String> DENIED_ENTITY_TYPE = DSL.field("denied_entity_type", SQLDataType.VARCHAR);
+ Field<String> DENIED_ENTITY = DSL.field("denied_entity", SQLDataType.VARCHAR);
+
+ PostgresTable TABLE = PostgresTable.name(TABLE_NAME.getName())
+ .createTableStep(((dsl, tableName) -> dsl.createTableIfNotExists(tableName)
+ .column(DROPLIST_ID)
+ .column(OWNER_SCOPE)
+ .column(OWNER)
+ .column(DENIED_ENTITY_TYPE)
+ .column(DENIED_ENTITY)
+ .constraint(DSL.primaryKey(DROPLIST_ID))))
+ .supportsRowLevelSecurity()
Review Comment:
We likely should disable RLS here (can we extract the domain (RLS column) from the owner input?)
##########
server/data/data-postgres/src/main/java/org/apache/james/droplists/postgres/PostgresDropList.java:
##########
@@ -0,0 +1,127 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.droplists.postgres;
+
+import static org.apache.james.backends.postgres.utils.PostgresExecutor.DEFAULT_INJECT;
+import static org.apache.james.droplists.api.DeniedEntityType.DOMAIN;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.DENIED_ENTITY;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.DENIED_ENTITY_TYPE;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.DROPLIST_ID;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.OWNER;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.OWNER_SCOPE;
+import static org.apache.james.droplists.postgres.PostgresDropListModule.PostgresDropListsTable.TABLE_NAME;
+
+import java.util.List;
+import java.util.UUID;
+
+import jakarta.inject.Inject;
+import jakarta.inject.Named;
+import jakarta.mail.internet.AddressException;
+
+import org.apache.james.backends.postgres.utils.PostgresExecutor;
+import org.apache.james.core.Domain;
+import org.apache.james.core.MailAddress;
+import org.apache.james.droplists.api.DropList;
+import org.apache.james.droplists.api.DropListEntry;
+import org.apache.james.droplists.api.OwnerScope;
+import org.jooq.Record;
+
+import com.google.common.base.Preconditions;
+
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public class PostgresDropList implements DropList {
+ private final PostgresExecutor postgresExecutor;
+
+ @Inject
+ public PostgresDropList(@Named(DEFAULT_INJECT) PostgresExecutor postgresExecutor) {
+ this.postgresExecutor = postgresExecutor;
Review Comment:
If we enable RLS, we can not use the `@Named(DEFAULT_INJECT) PostgresExecutor postgresExecutor`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
Re: [PR] JAMES-3946 Add a DropLists postgresql backend [james-project]
Posted by "Maxxx873 (via GitHub)" <gi...@apache.org>.
Maxxx873 commented on PR #2290:
URL: https://github.com/apache/james-project/pull/2290#issuecomment-2173311553
Can we merge this or does anything need to be improved?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org