Skip to content

feat: implement s3 compatible charm endpoint#1890

Merged
kian99 merged 2 commits intocanonical:v3from
kian99:add-s3-handler
Mar 4, 2026
Merged

feat: implement s3 compatible charm endpoint#1890
kian99 merged 2 commits intocanonical:v3from
kian99:add-s3-handler

Conversation

@kian99
Copy link
Contributor

@kian99 kian99 commented Mar 3, 2026

Description

This PR implements the s3-compatible charm upload endpoint in JIMM that already existed in Juju. When uploading local charms the client 1st tries the s3-compatible endpoint then falls back to the legacy endpoint. I noticed during testing of local charm uploads with JIMM we always hit a 404 on the first try and fallback to the legacy endpoint.

In the Juju code the s3 compatible endpoint calls the same logic as the legacy endpoint so there is no real change in behaviour. The only benefit is that we mirror the same behaviour as a normal Juju controller in JIMM. See Juju's github.com/juju/juju/apiserver objectsCharmHandler.ServePut with docstring,

// ServePut serves the PUT method for the S3 API. This is the equivalent of the
// `PutObject` method in the AWS S3 API.
// Since juju's objects (S3) API only acts as a shim, this method will only
// rewrite the http request for it to be correctly processed by the legacy
// '/charms' handler.

We already have an integration test for uploading a local charm which uses the local charm client's AddLocalCharm method. This method sets up the client to first try the s3 endpoint then the legacy endpoint (see below) so we will already be testing the new endpoint alongside this change.

func NewLocalCharmClient(st base.APICallCloser) (*LocalCharmClient, error) {
	httpPutter, err := newHTTPPutter(st)
	if err != nil {
		return nil, errors.Trace(err)
	}
	s3Putter, err := newS3Putter(st)
	if err != nil {
		return nil, errors.Trace(err)
	}
	fallbackPutter, err := newFallbackPutter(s3Putter, httpPutter)
	if err != nil {
		return nil, errors.Trace(err)
	}
	frontend, backend := base.NewClientFacade(st, "Charms")
	return &LocalCharmClient{ClientFacade: frontend, facade: backend, charmPutter: fallbackPutter}, nil
}

Engineering checklist

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests

@kian99 kian99 requested a review from a team as a code owner March 3, 2026 11:55
mountHandler("/model/{uuid}/{type:charms|applications}", jimmhttp.NewHTTPProxyHandler(s.jimm.LoginManager, s.jimm.JujuManager))
// Uploading local charms (s3 compatible endpoint and legacy HTTP endpoint, respectively)
proxyHandler := jimmhttp.NewHTTPProxyHandler(s.jimm.LoginManager, s.jimm.JujuManager)
mountHandler("/model-{uuid}/charms/{charmref}", proxyHandler)
Copy link
Contributor

Choose a reason for hiding this comment

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

ah wow

Comment on lines +40 to +47
h := &HTTPProxyHandler{
Router: chi.NewRouter(),
authenicator: authenticator,
credentialStore: credentialStore,
}
h.SetupMiddleware()
h.Router.HandleFunc(ProxyEndpoints, h.ProxyHTTP)
return h
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you move it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling SetupMiddleware twice panics, which was being called each time we mounted the routes.

Copy link
Contributor

Choose a reason for hiding this comment

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

cool

Copy link
Collaborator

@alesstimec alesstimec left a comment

Choose a reason for hiding this comment

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

LGTM

@kian99 kian99 merged commit 26e9f32 into canonical:v3 Mar 4, 2026
8 checks passed
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