diff --git a/api/license.go b/api/license.go index 5e2ddc9b..383ed2b7 100644 --- a/api/license.go +++ b/api/license.go @@ -11,24 +11,6 @@ type Licenses struct { type License interface { ExpiresAt() string IssuedAt() string - LicenseType() string -} - -type TrialLicense struct { - ExpiresAtVal string - IssuedAtVal string -} - -func (l TrialLicense) LicenseType() string { - return "trial" -} - -func (l TrialLicense) IssuedAt() string { - return l.IssuedAtVal -} - -func (l TrialLicense) ExpiresAt() string { - return l.ExpiresAtVal } type OnPremLicense struct { @@ -47,10 +29,6 @@ func (l OnPremLicense) ExpiresAt() string { return l.ExpiresAtVal } -func (l OnPremLicense) LicenseType() string { - return "onprem" -} - func (c *Client) Licenses() *Licenses { return &Licenses{client: c} } func (l *Licenses) Install(license string) error { @@ -69,7 +47,7 @@ func (l *Licenses) Install(license string) error { func (l *Licenses) Get() (License, error) { var query struct { - License struct { + InstalledLicense struct { ExpiresAt string IssuedAt string OnPrem struct { @@ -86,21 +64,11 @@ func (l *Licenses) Get() (License, error) { return nil, err } - var license License - if query.License.OnPrem.ID == "" { - license = TrialLicense{ - ExpiresAtVal: query.License.ExpiresAt, - IssuedAtVal: query.License.IssuedAt, - } - } else { - license = OnPremLicense{ - ID: query.License.OnPrem.ID, - ExpiresAtVal: query.License.ExpiresAt, - IssuedAtVal: query.License.IssuedAt, - IssuedTo: query.License.OnPrem.Owner, - NumberOfSeats: query.License.OnPrem.MaxUsers, - } - } - - return license, nil + return OnPremLicense{ + ID: query.InstalledLicense.OnPrem.ID, + ExpiresAtVal: query.InstalledLicense.ExpiresAt, + IssuedAtVal: query.InstalledLicense.IssuedAt, + IssuedTo: query.InstalledLicense.OnPrem.Owner, + NumberOfSeats: query.InstalledLicense.OnPrem.MaxUsers, + }, nil } diff --git a/api/users.go b/api/users.go index 68038303..c369ea4c 100644 --- a/api/users.go +++ b/api/users.go @@ -68,7 +68,7 @@ func (u *Users) Get(username string) (User, error) { func (u *Users) Update(username string, changeset UserChangeSet) (User, error) { var mutation struct { - Result struct{ User User } `graphql:"updateUser(input: {username: $username, isRoot: $isRoot, fullName: $fullName, company: $company, countryCode: $countryCode, email: $email, picture: $picture})"` + Result struct{ User User } `graphql:"updateUser(input: {username: $username, company: $company, isRoot: $isRoot, fullName: $fullName, picture: $picture, email: $email, countryCode: $countryCode})"` } graphqlErr := u.client.Mutate(&mutation, userChangesetToVars(username, changeset)) @@ -78,12 +78,18 @@ func (u *Users) Update(username string, changeset UserChangeSet) (User, error) { func (u *Users) Add(username string, changeset UserChangeSet) (User, error) { var mutation struct { - Result struct{ User User } `graphql:"addUser(input: {username: $username, isRoot: $isRoot, fullName: $fullName, company: $company, countryCode: $countryCode, email: $email, picture: $picture})"` + Result struct { + // We have to make a selection, so just take __typename + Typename graphql.String `graphql:"__typename"` + } `graphql:"addUserV2(input: {username: $username, company: $company, isRoot: $isRoot, fullName: $fullName, picture: $picture, email: $email, countryCode: $countryCode})"` } graphqlErr := u.client.Mutate(&mutation, userChangesetToVars(username, changeset)) + if graphqlErr != nil { + return User{}, graphqlErr + } - return mutation.Result.User, graphqlErr + return u.Get(username) } func (u *Users) Remove(username string) (User, error) { diff --git a/cmd/humioctl/license.go b/cmd/humioctl/license.go index 3f5ea9d1..aa0fe207 100644 --- a/cmd/humioctl/license.go +++ b/cmd/humioctl/license.go @@ -38,8 +38,6 @@ func printLicenseInfo(cmd *cobra.Command, license api.License) { var data [][]string - data = append(data, []string{"License Type", license.LicenseType()}) - if onprem, ok := license.(api.OnPremLicense); ok { data = append(data, []string{"License ID", onprem.ID}) data = append(data, []string{"Issued To", onprem.IssuedTo}) diff --git a/cmd/humioctl/license_show.go b/cmd/humioctl/license_show.go index b0f04a4b..41e944bb 100644 --- a/cmd/humioctl/license_show.go +++ b/cmd/humioctl/license_show.go @@ -15,6 +15,8 @@ package main import ( + "errors" + "github.com/humio/cli/api" "github.com/spf13/cobra" ) @@ -26,6 +28,10 @@ func newLicenseShowCmd() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { client := NewApiClient(cmd) license, apiErr := client.Licenses().Get() + noLicense := api.OnPremLicense{} + if license == noLicense { + apiErr = errors.New("no license currently installed") + } exitOnError(cmd, apiErr, "error fetching the license") printLicenseInfo(cmd, license) cmd.Println()