diff --git a/internal/jujuapi/jimm.go b/internal/jujuapi/jimm.go index 39768247d..f52551eea 100644 --- a/internal/jujuapi/jimm.go +++ b/internal/jujuapi/jimm.go @@ -22,6 +22,7 @@ import ( ofganames "github.com/canonical/jimm/v3/internal/openfga/names" "github.com/canonical/jimm/v3/pkg/api/params" apiparams "github.com/canonical/jimm/v3/pkg/api/params" + "github.com/canonical/jimm/v3/version" ) func init() { @@ -55,6 +56,7 @@ func init() { updateServiceAccountCredentials := rpc.Method(r.UpdateServiceAccountCredentials) listServiceAccountCredentials := rpc.Method(r.ListServiceAccountCredentials) grantServiceAccountAccess := rpc.Method(r.GrantServiceAccountAccess) + version := rpc.Method(r.Version) // JIMM Generic RPC r.AddMethod("JIMM", 4, "AddController", addControllerMethod) @@ -89,6 +91,7 @@ func init() { r.AddMethod("JIMM", 4, "UpdateServiceAccountCredentials", updateServiceAccountCredentials) r.AddMethod("JIMM", 4, "ListServiceAccountCredentials", listServiceAccountCredentials) r.AddMethod("JIMM", 4, "GrantServiceAccountAccess", grantServiceAccountAccess) + r.AddMethod("JIMM", 4, "Version", version) return []int{4} } @@ -503,3 +506,12 @@ func (r *controllerRoot) MigrateModel(ctx context.Context, args apiparams.Migrat Results: results, }, nil } + +// Version is a method on the JIMM facade that returns information on the version of JIMM. +func (r *controllerRoot) Version(ctx context.Context) (apiparams.VersionResponse, error) { + versionInfo := apiparams.VersionResponse{ + Version: version.VersionInfo.Version, + Commit: version.VersionInfo.GitCommit, + } + return versionInfo, nil +} diff --git a/internal/jujuapi/jimm_test.go b/internal/jujuapi/jimm_test.go index 140c97705..c45077ced 100644 --- a/internal/jujuapi/jimm_test.go +++ b/internal/jujuapi/jimm_test.go @@ -888,3 +888,13 @@ func (s *jimmSuite) TestJimmModelMigrationNonSuperuser(c *gc.C) { item := res.Results[0] c.Assert(item.Error.Message, gc.Matches, "unauthorized access") } + +func (s *jimmSuite) TestVersion(c *gc.C) { + conn := s.open(c, nil, "bob") + defer conn.Close() + client := api.NewClient(conn) + versionInfo, err := client.Version() + c.Assert(err, gc.IsNil) + c.Assert(versionInfo.Version, gc.Not(gc.Equals), "") + c.Assert(versionInfo.Commit, gc.Not(gc.Equals), "") +} diff --git a/pkg/api/client.go b/pkg/api/client.go index a736e515e..75b002e78 100644 --- a/pkg/api/client.go +++ b/pkg/api/client.go @@ -223,3 +223,10 @@ func (c *Client) UpdateServiceAccountCredentials(req *params.UpdateServiceAccoun func (c *Client) GrantServiceAccountAccess(req *params.GrantServiceAccountAccess) error { return c.caller.APICall("JIMM", 4, "", "GrantServiceAccountAccess", req, nil) } + +// Version returns version info of the controller. +func (c *Client) Version() (params.VersionResponse, error) { + var response params.VersionResponse + err := c.caller.APICall("JIMM", 4, "", "Version", nil, &response) + return response, err +} diff --git a/pkg/api/params/params.go b/pkg/api/params/params.go index 4f917f30f..7098f64a4 100644 --- a/pkg/api/params/params.go +++ b/pkg/api/params/params.go @@ -497,3 +497,9 @@ type WhoamiResponse struct { DisplayName string `json:"display-name" yaml:"display-name"` Email string `json:"email" yaml:"email"` } + +// VersionResponse holds the response for a version call. +type VersionResponse struct { + Version string `json:"version" yaml:"version"` + Commit string `json:"commit" yaml:"commit"` +}