Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defines the Information Service on top of Kong's Root endpoint #65

Merged
merged 19 commits into from
Jul 1, 2021
Merged
Changes from 8 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
53 changes: 53 additions & 0 deletions kong/information.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package kong

import (
"context"
"encoding/json"
"strings"
)

type Info struct {
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Configuration struct {
Database string `json:"database,omitempty" yaml:"database,omitempty"`
Portal bool `json:"portal,omitempty" yaml:"portal,omitempty"`
RBAC string `json:"rbac,omitempty" yaml:"rbac,omitempty"`
} `json:"configuration,omitempty" yaml:"configuration,omitempty"`
}
mmorel-35 marked this conversation as resolved.
Show resolved Hide resolved

// IsEnterprise check if Kong is enterprise edition
func (s *Info) IsEnterprise() bool {
return strings.Contains(s.Version, "enterprise")
}
mmorel-35 marked this conversation as resolved.
Show resolved Hide resolved

// IsInMemory check if Kong is in memory
func (s *Info) IsInMemory() bool {
return "off" == s.Configuration.Database
}

// IsRBACEnabled check if RBAC are enabled
func (s *Info) IsRBACEnabled() bool {
return "on" == s.Configuration.RBAC
}
mmorel-35 marked this conversation as resolved.
Show resolved Hide resolved

// IsPortalEnabled check if the portal is enabled
func (s *Info) IsPortalEnabled() bool {
return s.Configuration.Portal
}
mmorel-35 marked this conversation as resolved.
Show resolved Hide resolved

func (c *Client) Info(ctx context.Context) (*Info, error) {
mmorel-35 marked this conversation as resolved.
Show resolved Hide resolved
information, err := c.Root(ctx)
if err != nil {
return nil, err
}
bytes, err := json.Marshal(information)
if err != nil {
return nil, err
}
var info Info
err = json.Unmarshal(bytes, &info)
if err != nil {
return nil, err
}
mmorel-35 marked this conversation as resolved.
Show resolved Hide resolved
return &info, nil
}