这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 8 additions & 40 deletions api/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
}
12 changes: 9 additions & 3 deletions api/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions cmd/humioctl/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
6 changes: 6 additions & 0 deletions cmd/humioctl/license_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package main

import (
"errors"
"github.com/humio/cli/api"
"github.com/spf13/cobra"
)

Expand All @@ -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()
Expand Down