Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system to import functions from remote #136

Closed
wants to merge 1 commit into from
Closed

Conversation

pyrech
Copy link
Member

@pyrech pyrech commented Jun 25, 2023

For now, only import from GitHub repositories is supported.

use function Castor\import;

import('github://<user>/<repository>/<path to php file to import>@<version>');

A trust system is embedded to avoid malicious remote execution and ask users if they allow to import remote functions.

image

See the documentation for how it works: https://github.com/jolicode/castor/blob/remote-imports/doc/15-remote.md

Future ideas:

  • Make use of this feature in docker-starter to be able to provide optional infrastructure parts:
import('github://jolicode/docker-starter/worker')
  • Provide some "standard" library of common tasks we used at JoliCode:
import('github://jolicode/docker-starter/v4/.castor/qa.php')

@pyrech pyrech force-pushed the remote-imports branch 4 times, most recently from f1fad0e to 0bcf1c5 Compare June 25, 2023 12:40
Copy link
Member

@lyrixx lyrixx left a comment

Choose a reason for hiding this comment

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

Very cool

doc/13-remote.md Outdated Show resolved Hide resolved
src/GlobalHelper.php Outdated Show resolved Hide resolved
src/PlatformUtil.php Outdated Show resolved Hide resolved
src/Remote/Exception/NotTrusted.php Outdated Show resolved Hide resolved
src/Remote/Import.php Outdated Show resolved Hide resolved
src/Remote/Import.php Outdated Show resolved Hide resolved
src/Remote/Import.php Outdated Show resolved Hide resolved
@@ -9,7 +9,7 @@ class ArgsAnotherArgsTest extends TaskTestCase
// args:another-args
public function test(): void
{
$process = $this->runTask(['args:another-args', 'FIXME(required)', '--test2', 1]);
$process = $this->runTask(['args:another-args', 'FIXME(required)', '--test2', 1, '--no-trust']);
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to not update all tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Did not find a way, so I'm open to any suggestions

@pyrech pyrech force-pushed the remote-imports branch 7 times, most recently from d661b23 to d6d36ad Compare June 26, 2023 10:00
@pyrech pyrech added the enhancement New feature or request label Jun 26, 2023
@pyrech pyrech force-pushed the remote-imports branch 4 times, most recently from 37c0429 to b0e455f Compare June 30, 2023 14:09
@lyrixx
Copy link
Member

lyrixx commented Jul 13, 2023

I would put all the code in a vendor directly (like vendor/.castor, like that there is no need to hook in the stub generation, and we can ship more than some code!

function, formatted like this:

```
github://<user>/<repository>/<path of the php file to import>@<version>
Copy link
Member

Choose a reason for hiding this comment

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

We should document what version could be. A branch? A tag? A commit hash?

@TheoD02
Copy link
Contributor

TheoD02 commented Jan 17, 2024

Hey,

Not a lot of movement here? ^^
What's the status of this PR? What's the reason for this long inactivity ? What's left to do?😄

I'm waiting for this PR to split the common code to share it with different projects 😁

@pyrech
Copy link
Member Author

pyrech commented Jan 17, 2024

For the record we sometimes talk internally about this feature we all want. But we do not fully agree on some details, mainly where to store the downloaded files. I hope we can find a solution soon but not sure it will find its way before the release of the v1

@lyrixx
Copy link
Member

lyrixx commented Feb 15, 2024

We had a very good talk with @pyrech and @joelwurtz and here the ADR

The goal is to generate a composer.json, then use composer to download everything.

Default usage, package is published on packagist.org

import('composer://jolicode/jolitypo');

Add this to composer.json

{
    "require": {
        "jolicode/castor": "*",
    }
}

Then execute at runtime

require_once PathHelper::getRoot() . '/.castor/vendor/autoload.php';

More complex usage

import('composer://jolicode/jolitypo',
    file: 'path/to/file.php',
    version: 'v1.2.34',
);

Add this to composer.json

{
    "require": {
        "jolicode/castor": "v1.2.34",
    }
}

Then execute at runtime

require_once PathHelper::getRoot() . '/.castor/vendor/autoload.php';
require_once PathHelper::getRoot() . '/.castor/vendor/jolicode/jolitypo/path/to/file.php';

Package that is not published on packagist.org

import('composer://jolicode/jolitypo',
    file: 'path/to/file.php',
    version: 'v1.2.34',
    vcs: 'https://github.com/jolicode/jolitypo.git',
);

Add this to composer.json

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/jolicode/jolitypo.git"
        }
    ],
    "require": {
        "jolicode/castor": "v1.2.34",
    }
}

Then execute at runtime

require_once PathHelper::getRoot() . '/.castor/vendor/autoload.php';
require_once PathHelper::getRoot() . '/.castor/vendor/jolicode/jolitypo/path/to/file.php';

Not a package

import('package://what/you-want',
    file: 'path/to/file.php',
    // version: 'dev-main', // Not allowed here
    source: [
        "url" =>  "https://github.com/soyuka/php-wasm.git",
        "type" => "git",
        "reference" => "main"
    ],
);

Add this to composer.json

{
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "what/you-want",
                "version": "dev-main",
                "source": {
                    "url": "https://github.com/soyuka/php-wasm.git",
                    "type": "git",
                    "reference": "main"
                }
            }
        },

    ],
    "require": {
        "what/you-want": "*",
    }
}

Then execute at runtime

require_once PathHelper::getRoot() . '/.castor/vendor/autoload.php';

@pyrech
Copy link
Member Author

pyrech commented Feb 26, 2024

Closing in favor of #297

@pyrech pyrech closed this Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants