adjust alias generation
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
56f5871d8e
commit
e13d26f8c1
@ -47,7 +47,7 @@ export interface AliasesParams extends Params<AliasesQuery> {
|
|||||||
export class AliasesService<ServiceParams extends AliasesParams = AliasesParams>
|
export class AliasesService<ServiceParams extends AliasesParams = AliasesParams>
|
||||||
implements ServiceInterface<Alias, AliasesData, ServiceParams, AliasesPatch>
|
implements ServiceInterface<Alias, AliasesData, ServiceParams, AliasesPatch>
|
||||||
{
|
{
|
||||||
constructor(public options: AliasesServiceOptions) {}
|
constructor(public options: AliasesServiceOptions) { }
|
||||||
|
|
||||||
async find(params: ServiceParams): Promise<Alias[]> {
|
async find(params: ServiceParams): Promise<Alias[]> {
|
||||||
const userId = await this.getUserIdByEmailAddress(params);
|
const userId = await this.getUserIdByEmailAddress(params);
|
||||||
@ -61,21 +61,22 @@ export class AliasesService<ServiceParams extends AliasesParams = AliasesParams>
|
|||||||
params: ServiceParams,
|
params: ServiceParams,
|
||||||
): Promise<Alias | Alias[]> {
|
): Promise<Alias | Alias[]> {
|
||||||
const userId = await this.getUserIdByEmailAddress(params);
|
const userId = await this.getUserIdByEmailAddress(params);
|
||||||
const aliasFirstPart = faker.animal
|
|
||||||
.crocodilia()
|
|
||||||
.replace(/\D/g, "")
|
|
||||||
.replace(/\s/g, "")
|
|
||||||
.slice(0, 10);
|
|
||||||
|
|
||||||
const aliasSecondPart = faker.git.commitSha({ length: 5 });
|
const randomString = faker.git.commitSha({ length: 4 });
|
||||||
const alias = `${aliasFirstPart}-${aliasSecondPart}@${config.get(
|
|
||||||
"wildDuck.domain",
|
// Replace all non-alphanumeric characters with nothing and spaces with dashes
|
||||||
)}`;
|
const alias =
|
||||||
|
`${faker.color.human()}-${faker.animal.snake()}-${randomString}`
|
||||||
|
.replace(/\s+/g, "-")
|
||||||
|
.replace(/[^a-zA-Z0-9-]/g, "")
|
||||||
|
.toLowerCase();
|
||||||
|
|
||||||
|
const emailDomain = config.get("wildDuck.domain");
|
||||||
|
|
||||||
const createResult = await wildDuckClient.post<CreateAddressResponse>(
|
const createResult = await wildDuckClient.post<CreateAddressResponse>(
|
||||||
`/users/${userId}/addresses`,
|
`/users/${userId}/addresses`,
|
||||||
{
|
{
|
||||||
address: alias,
|
address: `${alias}@${emailDomain}`,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -116,7 +117,7 @@ export class AliasesService<ServiceParams extends AliasesParams = AliasesParams>
|
|||||||
const allowedDomain: string = config.get("wildDuck.domain");
|
const allowedDomain: string = config.get("wildDuck.domain");
|
||||||
|
|
||||||
// If address does not match the allowed domain, throw an error
|
// If address does not match the allowed domain, throw an error
|
||||||
if (!addressInfoResponse.address.endsWith(allowedDomain)) {
|
if (!allowedDomain || !addressInfoResponse.address.endsWith(allowedDomain)) {
|
||||||
throw new BadRequest("Unable to delete address");
|
throw new BadRequest("Unable to delete address");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user