Skip to content

Commit

Permalink
add version method to JIMM facade (#1356)
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 authored Sep 9, 2024
1 parent 4d88a29 commit 293cb73
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/jujuapi/jimm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}
}
Expand Down Expand Up @@ -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
}
10 changes: 10 additions & 0 deletions internal/jujuapi/jimm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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), "")
}
7 changes: 7 additions & 0 deletions pkg/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions pkg/api/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit 293cb73

Please sign in to comment.