2023-03-07 05:37:08 -05:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
package openstack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/role"
|
2023-03-07 05:37:25 -05:00
|
|
|
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
|
|
|
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
|
|
|
|
"github.com/gophercloud/gophercloud/pagination"
|
2023-03-07 05:37:08 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type stubIMDSClient struct {
|
|
|
|
providerIDResult string
|
|
|
|
providerIDErr error
|
|
|
|
nameResult string
|
|
|
|
nameErr error
|
|
|
|
projectIDResult string
|
|
|
|
projectIDErr error
|
|
|
|
uidResult string
|
|
|
|
uidErr error
|
|
|
|
initSecretHashResult string
|
|
|
|
initSecretHashErr error
|
|
|
|
roleResult role.Role
|
|
|
|
roleErr error
|
|
|
|
vpcIPResult string
|
|
|
|
vpcIPErr error
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (c *stubIMDSClient) providerID(_ context.Context) (string, error) {
|
2023-03-07 05:37:08 -05:00
|
|
|
return c.providerIDResult, c.providerIDErr
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (c *stubIMDSClient) name(_ context.Context) (string, error) {
|
2023-03-07 05:37:08 -05:00
|
|
|
return c.nameResult, c.nameErr
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (c *stubIMDSClient) projectID(_ context.Context) (string, error) {
|
2023-03-07 05:37:08 -05:00
|
|
|
return c.projectIDResult, c.projectIDErr
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (c *stubIMDSClient) uid(_ context.Context) (string, error) {
|
2023-03-07 05:37:08 -05:00
|
|
|
return c.uidResult, c.uidErr
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (c *stubIMDSClient) initSecretHash(_ context.Context) (string, error) {
|
2023-03-07 05:37:08 -05:00
|
|
|
return c.initSecretHashResult, c.initSecretHashErr
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (c *stubIMDSClient) role(_ context.Context) (role.Role, error) {
|
2023-03-07 05:37:08 -05:00
|
|
|
return c.roleResult, c.roleErr
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (c *stubIMDSClient) vpcIP(_ context.Context) (string, error) {
|
2023-03-07 05:37:08 -05:00
|
|
|
return c.vpcIPResult, c.vpcIPErr
|
|
|
|
}
|
2023-03-07 05:37:25 -05:00
|
|
|
|
|
|
|
type stubServersClient struct {
|
|
|
|
serversPager stubPager
|
|
|
|
subnetsPager stubPager
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (c *stubServersClient) ListServers(_ servers.ListOptsBuilder) pagerAPI {
|
2023-03-07 05:37:25 -05:00
|
|
|
return &c.serversPager
|
|
|
|
}
|
|
|
|
|
2023-03-20 06:03:36 -04:00
|
|
|
func (c *stubServersClient) ListSubnets(_ subnets.ListOpts) pagerAPI {
|
2023-03-07 05:37:25 -05:00
|
|
|
return &c.subnetsPager
|
|
|
|
}
|
|
|
|
|
|
|
|
type stubPager struct {
|
|
|
|
page pagination.Page
|
|
|
|
allPagesErr error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *stubPager) AllPages() (pagination.Page, error) {
|
|
|
|
return p.page, p.allPagesErr
|
|
|
|
}
|