Skip to content

ref: Decouple functionality from the registry#168

Merged
iker-barriocanal merged 22 commits into
masterfrom
registry-refactor
Jan 25, 2021
Merged

ref: Decouple functionality from the registry#168
iker-barriocanal merged 22 commits into
masterfrom
registry-refactor

Conversation

@iker-barriocanal

@iker-barriocanal iker-barriocanal commented Jan 20, 2021

Copy link
Copy Markdown
Contributor

This PR is not adding any functionality, but refactoring the registry target to decouple some functionality, so that there are more pieces with smaller responsibility each.

Currently the target aws-lambda-layer, after creating new layers, only logs to console the layer's ARNs; but we want to have the data of the created new layers in the registry. However, only the registry target is able to write there. In order to have the targets independent between them, the goal is to make the aws-lambda-layer target able to write to the registry, so that it doesn’t need to interact with the registry target. This PR is focused on the refactoring part of that small feature. Besides aws-lambda-layer, additional serverless targets might be created in the future.

Aiming to leave the codebase a bit better and make the code more readable and usable, additional refactoring has been made not to have the registry target do that many things. Thus, some functionality the registry target does has been broken down into other modules (again, some of the modules won't be used in the new feature of the aws-lambda-layer target, and will only be used by the registry target for now).

This refactoring of decoupling functionality from the registry target (src/targets/registry) includes:

  • Checksums. Casting and getting the artifact checksums are available in the src/utils/checksums module.
  • Symlinks. Creating symlinks is now achievable in the src/utils/symlink module.
  • Getting package paths. Getting the path of a package given its type and the canonical name is now implemented in the src/utils/packagePath module.
  • Canonical parsing. Parsing the canonical name of a package to a list of directories is now also implemented in the src/utils/packagePath module.
  • Getting the package manifest and updating a manifest's symlinks are now two functions acting as utils for the registry target, in the src/utils/registry directory.

@HazAT

HazAT commented Jan 20, 2021

Copy link
Copy Markdown
Member

I didn't look at the code yet but just FYI it would be nice if we can maybe also fix that.
#167

@tonyo

tonyo commented Jan 20, 2021

Copy link
Copy Markdown
Contributor

@HazAT Please check the comment here #167 (comment)
I believe that issue deserves a separate discussion/fix.

@iker-barriocanal
iker-barriocanal marked this pull request as ready for review January 20, 2021 15:00

@tonyo tonyo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the things that were extracted seem too tied to the registry target still, which makes them less reusable or general-purpose (for example, functions addPackageVersionToRegistry and createSymlinks). I don't have good suggestions how to decouple them better, but let's at least move all these new modules to the registry submodule (so it'll be utils/registry), to illustrate that they're not really useful outside interacting with the release registry.

For functions that are more generic (e.g., git operations), please check if we already use similar snippets in other files, and whether it makes sense to start using your new util functions or not.

Comment thread src/utils/gitTasks.ts Outdated
Comment thread src/utils/gitTasks.ts Outdated
Comment thread src/utils/packagePath.ts Outdated
Comment thread src/utils/packagePath.ts Outdated
@BYK

BYK commented Jan 21, 2021

Copy link
Copy Markdown
Member

@iker-barriocanal it would also be great to tie this to some existing issues or planned future work to ensure this is not refactoring for refactoring sake. This seems like a pretty large change and I'd love to have a very good reason behind it before taking the risk.

@iker-barriocanal

Copy link
Copy Markdown
Contributor Author

@BYK at the moment, updates on the registry are done through the registry target. However, when new AWS Lambda layers are created, their information also needs to be added (see getsentry/sentry-release-registry#30). It's easier to avoid code duplication if some functionality is decoupled.

@iker-barriocanal

Copy link
Copy Markdown
Contributor Author

@tonyo some of the things can (and will) be more easily be used by other modules (e.g. symlink), even if they are only used by the registry atm.

Other modules (e.g. utils/checksum, utils/packagePath and utils/registry) are also only used by the registry now, and in fact not planning to use them shortly; but I also wanted to decouple responsibilities and not have that many things done in the same file, since I feel it's easier to read and in general to deal with. Open to bring these back, though.

@iker-barriocanal
iker-barriocanal requested review from BYK and removed request for HazAT January 25, 2021 12:51

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some nits but LGTM and can be merged as is.

Comment thread src/utils/packagePath.ts Outdated
Comment thread src/utils/packagePath.ts Outdated
Comment thread src/utils/packagePath.ts
* @param canonicalName Registry canonical name
* @returns A list of directories
*/
export function parseCanonical(canonicalName: string): string[] {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/utils/checksum.ts
if (!checksums) {
return [];
}
if (!Array.isArray(checksums)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be checked via TypeScript?

Comment thread src/utils/checksum.ts
Comment on lines +40 to +41
!Object.values(HashAlgorithm).includes(item.algorithm) ||
!Object.values(HashOutputFormat).includes(item.format)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move these out of the loop:

const VALID_ALGORITHMS = new Set(Object.values(HashAlgorithm));
const VALID_OUTPUT_FORMATS = new Set(Object.values(HashOutputFormat));

@iker-barriocanal
iker-barriocanal merged commit caeef36 into master Jan 25, 2021
@iker-barriocanal
iker-barriocanal deleted the registry-refactor branch January 25, 2021 14:55
BYK added a commit that referenced this pull request Jun 23, 2026
## Summary

Resolves **10 open Dependabot alerts** across 5 CVEs and dismisses 2
low-severity esbuild alerts as tolerable risk.

### Alerts Fixed

| Alert(s) | Package | Severity | CVE | Fix |
|----------|---------|----------|-----|-----|
| #180, #181 | `tar` | Medium | GHSA-vmf3-w455-68vh | Bump direct pin
`7.5.11` -> `7.5.16` |
| #178, #179 | `form-data` | High | GHSA-hmw2-7cc7-3qxx |
`pnpm.overrides` for `4.0.6` (v4) and `2.5.6` (v2) |
| #172, #176 | `vite` (root) | High + Medium | GHSA-fx2h-pf6j-xcff,
GHSA-v6wh-96g9-6wx3 | Add as direct devDep `^7.3.5` + override |
| #173, #177 | `vite` (docs) | High + Medium | same | `pnpm.overrides`
in docs |
| #174, #175 | `astro` | High + Medium | GHSA-2pvr-wf23-7pc7,
GHSA-jrpj-wcv7-9fh9 | `pnpm update` -> `6.4.8` |

### Alerts Dismissed (tolerable_risk)

| Alert(s) | Package | Severity | Reason |
|----------|---------|----------|--------|
| #167, #168 | `esbuild` | Low | GHSA-g7r4-m6w7-qqqr - Windows
dev-server only vulnerability. Craft is a CLI tool, docs is a static
site. Transitive dep of `[email protected]` which pins `esbuild@^0.27.0` -
cannot fix without vite 8 major bump. |

## Changes

### Root project (`package.json`)
- `tar`: `7.5.11` -> `7.5.16` (direct pin bump)
- `vite`: added as devDependency at `^7.3.5` (was only transitive via
vitest)
- `pnpm.overrides`: added `form-data@>=4: ^4.0.6`, `form-data@<3:
^2.5.6`, `vite: ^7.3.5`

### Docs project (`docs/package.json`)
- `astro`: resolved `5.16.11` -> `6.4.8` (specifier `^6.1.10` allowed
it)
- `@astrojs/starlight`: resolved `0.37.3` -> `0.38.3`
- `pnpm.overrides`: added `vite: ^7.3.5`

## Verification

- `pnpm build` - passed
- `pnpm test` - 1025 passed, 1 skipped
- `pnpm lint` - 0 errors
- `pnpm docs:build` - 27 pages built successfully
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants