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
6 changes: 3 additions & 3 deletions cloud/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func templateString(indent, ljust int, delim, key string, value any) string {

for _, template := range templates {

buf.WriteString(fmt.Sprintf("%s%s = [\n", strings.Repeat("\t", indent), pad(key, ljust)))
fmt.Fprintf(&buf, "%s%s = [\n", strings.Repeat("\t", indent), pad(key, ljust))

kps := make([]keyValuePair, 0, len(template))
length := 0
Expand All @@ -152,7 +152,7 @@ func templateString(indent, ljust int, delim, key string, value any) string {
buf.WriteString(templateString(indent+1, length, delim, pad(kps[i].key, length), kps[i].value))
}

buf.WriteString(fmt.Sprintf("%s]\n", strings.Repeat("\t", indent)))
fmt.Fprintf(&buf, "%s]\n", strings.Repeat("\t", indent))

}

Expand Down Expand Up @@ -259,7 +259,7 @@ func newTemplate(t any) map[string]any { //nolint:gocognit
}

func simpleValue(v reflect.Value) any {
if v.Kind() == reflect.Ptr {
if v.Kind() == reflect.Pointer {
if v.IsNil() {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions deprecated/v2/cloud/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func templateString(indent, ljust int, delim, key string, value any) string {

for _, template := range templates {

buf.WriteString(fmt.Sprintf("%s%s = [\n", strings.Repeat("\t", indent), pad(key, ljust)))
fmt.Fprintf(&buf, "%s%s = [\n", strings.Repeat("\t", indent), pad(key, ljust))

kps := make([]keyValuePair, 0, len(template))
length := 0
Expand All @@ -138,7 +138,7 @@ func templateString(indent, ljust int, delim, key string, value any) string {
buf.WriteString(templateString(indent+1, length, delim, pad(kps[i].key, length), kps[i].value))
}

buf.WriteString(fmt.Sprintf("%s]\n", strings.Repeat("\t", indent)))
fmt.Fprintf(&buf, "%s]\n", strings.Repeat("\t", indent))

}

Expand Down
24 changes: 12 additions & 12 deletions deprecated/v2/snapshot/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,56 @@ type AutoRequest struct {

// ID return the ID of the request.
func (a AutoRequest) ID() uint {
return a.requestBase.id
return a.id
}

// Scheduled returns the time the request was scheduled.
func (a AutoRequest) Scheduled() time.Time {
return a.requestBase.scheduled
return a.scheduled
}

// Started returns the time the request was started.
func (a AutoRequest) Started() time.Time {
return a.requestBase.started
return a.started
}

// Finished returns the time the request was finished.
func (a AutoRequest) Finished() time.Time {
return a.requestBase.finished
return a.finished
}

// Schedule returns the request's snapshot schedule.
func (a AutoRequest) Schedule() Schedule {
return a.requestBase.schedule
return a.schedule
}

// SetID sets the ID of the request.
func (a *AutoRequest) SetID(id uint) Request {
a.requestBase.id = id
a.id = id
return a
}

// SetScheduled sets the scheduled time of the request.
func (a *AutoRequest) SetScheduled(t time.Time) Request {
a.requestBase.scheduled = t
a.scheduled = t
return a
}

// SetStarted sets the started time of the request.
func (a *AutoRequest) SetStarted(t time.Time) Request {
a.requestBase.started = t
a.started = t
return a
}

// SetFinished sets the finished time of the request.
func (a *AutoRequest) SetFinished(t time.Time) Request {
a.requestBase.finished = t
a.finished = t
return a
}

// SetSchedule sets the request's snapshot schedule.
func (a *AutoRequest) SetSchedule(s Schedule) Request {
a.requestBase.schedule = s
a.schedule = s
return a
}

Expand All @@ -80,8 +80,8 @@ func (a AutoRequest) VMID() int {
// Tag returns the Tag that will be used when processing the request.
func (a AutoRequest) Tag() Tag {
tag := Tag{
Period: a.requestBase.schedule.Period(),
Time: a.requestBase.scheduled,
Period: a.schedule.Period(),
Time: a.scheduled,
VM: -1,
Version: 2,
}
Expand Down
24 changes: 12 additions & 12 deletions deprecated/v2/snapshot/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,56 @@ type ManualRequest struct {

// ID return the ID of the request.
func (m ManualRequest) ID() uint {
return m.requestBase.id
return m.id
}

// Scheduled returns the time the request was scheduled.
func (m ManualRequest) Scheduled() time.Time {
return m.requestBase.scheduled
return m.scheduled
}

// Started returns the time the request was started.
func (m ManualRequest) Started() time.Time {
return m.requestBase.started
return m.started
}

// Finished returns the time the request was finished.
func (m ManualRequest) Finished() time.Time {
return m.requestBase.finished
return m.finished
}

// Schedule returns the request's snapshot schedule.
func (m ManualRequest) Schedule() Schedule {
return m.requestBase.schedule
return m.schedule
}

// SetID sets the ID of the request.
func (m *ManualRequest) SetID(id uint) Request {
m.requestBase.id = id
m.id = id
return m
}

// SetScheduled sets the scheduled time of the request.
func (m *ManualRequest) SetScheduled(t time.Time) Request {
m.requestBase.scheduled = t
m.scheduled = t
return m
}

// SetStarted sets the started time of the request.
func (m *ManualRequest) SetStarted(t time.Time) Request {
m.requestBase.started = t
m.started = t
return m
}

// SetFinished sets the finished time of the request.
func (m *ManualRequest) SetFinished(t time.Time) Request {
m.requestBase.finished = t
m.finished = t
return m
}

// SetSchedule sets the request's snapshot schedule.
func (m *ManualRequest) SetSchedule(s Schedule) Request {
m.requestBase.schedule = s
m.schedule = s
return m
}

Expand All @@ -71,8 +71,8 @@ func (m ManualRequest) VMID() int { return m.VM }
// Tag returns the Tag that will be used when processing the request.
func (m ManualRequest) Tag() Tag {
return Tag{
Period: m.requestBase.schedule.Period(),
Time: m.requestBase.scheduled,
Period: m.schedule.Period(),
Time: m.scheduled,
RBD: m.RBDName,
Version: 3,
}
Expand Down
12 changes: 6 additions & 6 deletions deprecated/v2/snapshot/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ func (s *Schedule) setHourly(when string) error {
return err
}

if !(minute >= 0 && minute <= 59) {
if minute < 0 || minute > 59 {
return fmt.Errorf("invalid minute %d", minute)
}

Expand Down Expand Up @@ -845,7 +845,7 @@ func (s *Schedule) setDaily(when string) error {
return err
}

if !(hour >= 0 && hour <= 23) {
if hour < 0 || hour > 23 {
return fmt.Errorf("invalid hour %d", hour)
}

Expand Down Expand Up @@ -884,7 +884,7 @@ func (s *Schedule) setWeekly(when string) error {
}
}

if !(day >= time.Sunday && day <= time.Saturday) {
if day < time.Sunday || day > time.Saturday {
return fmt.Errorf("invalid day %v", day)
}

Expand Down Expand Up @@ -913,7 +913,7 @@ func (s *Schedule) setMonthly(when string) error {
return err
}

if !(day >= 1 && day <= 31) {
if day < 1 || day > 31 {
return fmt.Errorf("invalid day %d", day)
}

Expand Down Expand Up @@ -971,7 +971,7 @@ func (s *Schedule) setYearly(when string) error {
}

if month != 0 {
if !(month >= time.January && month <= time.December) {
if month < time.January || month > time.December {
return fmt.Errorf("invalid month %v", month)
}

Expand All @@ -981,7 +981,7 @@ func (s *Schedule) setYearly(when string) error {
}

if yearday != 0 {
if !(yearday >= 1 && yearday <= 366) {
if yearday < 1 || yearday > 366 {
return fmt.Errorf("invalid yearday %d", yearday)
}

Expand Down
26 changes: 26 additions & 0 deletions fed/fed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Package fed holds types and services for the federation endpoints.
package fed

// PathPrefix is the root path for federation API endpoints.
const PathPrefix = "fed"

// FederateInfoPath is the path for get-federate-info endpoint.
const FederateInfoPath = "get-federate-info"

// FederationPath is the path for get-federation endpoint.
const FederationPath = "get-federation"

// RemoveFederatePath is the path for remove-federate endpoint.
const RemoveFederatePath = "remove-federate"

// AddNewFederatePath is the path for add-new-federate endpoint.
const AddNewFederatePath = "add-new-federate"

// AuthorizeFederationPath is the path for authorize-federation endpoint.
const AuthorizeFederationPath = "authorize-federation"

// ClusterOverviewPath is the path for cluster/overview endpoint.
const ClusterOverviewPath = "cluster/overview"

// FederateLoginPath is the path for federate-login endpoint.
const FederateLoginPath = "federate-login"
67 changes: 67 additions & 0 deletions fed/service_fed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package fed

import (
"context"

"github.com/softiron/manifold-api/client"
"github.com/softiron/manifold-api/internal/api"
)

// Service owns the /fed methods.
type Service struct {
*service
}

type service struct {
*client.Client
root string
}

// NewService returns a new Service for federation operations.
func NewService(c *client.Client, path string) *Service {
s := &service{Client: c, root: path}

return &Service{
service: s,
}
}

// path returns a URL path with the correct prefix appended.
func (s service) path(dirs ...interface{}) string {
return api.Path(s.root, PathPrefix, dirs...)
}

// GetFederateInfo returns federate information.
func (s Service) GetFederateInfo(ctx context.Context) error {
p := s.path(FederateInfoPath)

return s.Get(ctx, p, nil)
}

// GetFederation returns federation information.
func (s Service) GetFederation(ctx context.Context) error {
p := s.path(FederationPath)

return s.Get(ctx, p, nil)
}

// RemoveFederate removes a federate.
func (s Service) RemoveFederate(ctx context.Context) error {
p := s.path(RemoveFederatePath)

return s.Post(ctx, p, nil, nil)
}

// AddNewFederate adds a new federate.
func (s Service) AddNewFederate(ctx context.Context) error {
p := s.path(AddNewFederatePath)

return s.Post(ctx, p, nil, nil)
}

// AuthorizeFederation authorizes federation.
func (s Service) AuthorizeFederation(ctx context.Context) error {
p := s.path(AuthorizeFederationPath)

return s.Post(ctx, p, nil, nil)
}
35 changes: 35 additions & 0 deletions management/management.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Package management holds types and services for the /v3-preview/management endpoints.
package management

// PathPrefix is the root path for management API endpoints.
const PathPrefix = "management"

// FactPath is the path for fact-related endpoints.
const FactPath = "fact"

// ClusterNamePath is the path for cluster-name endpoint.
const ClusterNamePath = "cluster-name"

// SSHBannerPath is the path for ssh-banner endpoint.
const SSHBannerPath = "ssh-banner"

// LicensePath is the path for license endpoint.
const LicensePath = "license"

// StorageVLANPath is the path for storage-vlan endpoint.
const StorageVLANPath = "storage-vlan"

// ComputeVLANPath is the path for compute-vlan endpoint.
const ComputeVLANPath = "compute-vlan"

// DashboardNetworkPath is the path for dashboard-network endpoint.
const DashboardNetworkPath = "dashboard-network"

// DashboardVLANPath is the path for dashboard-vlan endpoint.
const DashboardVLANPath = "dashboard-vlan"

// TopologyPath is the path for topology endpoint.
const TopologyPath = "topology"

// SSHPath is the path for ssh keys endpoint.
const SSHPath = "ssh"
Loading
Loading