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

feat(rest.packages.provider): add endpoint for .dp upload #4894

Merged
merged 24 commits into from
Oct 30, 2023

Conversation

mattdibi
Copy link
Contributor

@mattdibi mattdibi commented Oct 12, 2023

This PR follows #4868 and adds the endpoint for .dp file upload. It leverages multipart/form-data under the hood.

Can be tested using:

export ADDRESS=<addr>
export USERNAME=<user>
export PASSWORD=<pass>

and then:

curl -X POST -k -u $USER:$PASSWORD --header 'Content-Type: multipart/form-data' --form 'file=@"/path/to/org.eclipse.kura.ai.triton.server-1.2.0.dp"' https://$ADDRESS/services/deploy/v2/_upload -v

Roadmap:

@mattdibi mattdibi marked this pull request as draft October 12, 2023 15:23
@mattdibi mattdibi force-pushed the experimental/dp_upload_v2 branch from c4af0be to dc857ad Compare October 27, 2023 10:02
@mattdibi mattdibi requested a review from nicolatimeus October 27, 2023 15:57
@mattdibi mattdibi marked this pull request as ready for review October 27, 2023 15:57
@nicolatimeus
Copy link
Contributor

I've tested this with the browser and the new session REST APIs using the following snippet, it seems to work fine.

<!doctype html>
<html>
<body>
    <input id="username" />
    <input id="password" />

    <form id="upload-form">
        <input type="file" id="dp-upload" name="file"/>
    </form>

    <button id="upload-button">Login and Upload</button>

    <div id="output"></div>
    <script>
        var username = document.getElementById('username');
        var password = document.getElementById('password');
        var uploadForm = document.getElementById("upload-form");
        var uploadButton = document.getElementById("upload-button");
        var output = document.getElementById('output');
        function print(msg) {
            const p = document.createElement('p');
            p.textContent = msg
            output.append(p)
        }
        async function doLogin() {
            await fetch('/services/session/v1/login/password', {
                method: 'POST',
                headers: {
                    "Content-Type": "application/json",
                    Accept: "application/json"
                },
                body: JSON.stringify({
                    username: username.value,
                    password: password.value
                })
            });
            const response = await fetch('/services/session/v1/xsrfToken', {
                method: 'GET',
                headers: {
                    Accept: "application/json"
                }
            });
            return (await response.json()).xsrfToken;
        }
        async function doUpload(xsrfToken) {
            const formData = new FormData(uploadForm);
            const response = await fetch("/services/deploy/v2/_upload", {
                method: 'POST',
                headers: {
                    'X-XSRF-Token': xsrfToken
                },
                body: formData,
            })
            return response.status
        }
        uploadButton.addEventListener('click', async () => {
            print('uploading...')
            const xsrfToken = await doLogin();
            const status = await doUpload(xsrfToken);
            print('uploading... done. got status ' + status)
        });
    </script>
</body>
</html>

@MMaiero MMaiero merged commit d74484b into eclipse-kura:develop Oct 30, 2023
1 check passed
@mattdibi mattdibi deleted the experimental/dp_upload_v2 branch October 30, 2023 16:19
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.

3 participants