Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Nov 2, 2024
1 parent a94ccd1 commit 303f263
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions internal/authz/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type Superuser struct {
}

func (*Superuser) CanAccessSite(action rbac.Action) bool { return true }
func (*Superuser) CanAccessTeam(rbac.Action, string) bool { return true }
func (*Superuser) CanAccessTeam(rbac.Action, resource.ID) bool { return true }
func (*Superuser) CanAccessOrganization(rbac.Action, string) bool { return true }
func (*Superuser) CanAccessWorkspace(rbac.Action, WorkspacePolicy) bool { return true }
func (s *Superuser) Organizations() []string { return nil }
Expand All @@ -102,7 +102,7 @@ type Nobody struct {
}

func (*Nobody) CanAccessSite(action rbac.Action) bool { return false }
func (*Nobody) CanAccessTeam(rbac.Action, string) bool { return false }
func (*Nobody) CanAccessTeam(rbac.Action, resource.ID) bool { return false }
func (*Nobody) CanAccessOrganization(rbac.Action, string) bool { return false }
func (*Nobody) CanAccessWorkspace(rbac.Action, WorkspacePolicy) bool { return false }
func (s *Nobody) Organizations() []string { return nil }
Expand Down
3 changes: 2 additions & 1 deletion internal/configversion/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/gorilla/mux"
otfapi "github.com/leg100/otf/internal/api"
"github.com/leg100/otf/internal/http/decode"
"github.com/leg100/otf/internal/resource"
"github.com/leg100/otf/internal/tfeapi"
)

Expand All @@ -25,7 +26,7 @@ func (a *api) download(w http.ResponseWriter, r *http.Request) {
tfeapi.Error(w, err)
return
}
resp, err := a.DownloadConfig(r.Context(), id)
resp, err := a.DownloadConfig(r.Context(), resource.ID{Kind: Kind, ID: id})
if err != nil {
tfeapi.Error(w, err)
return
Expand Down
5 changes: 3 additions & 2 deletions internal/configversion/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/url"

otfapi "github.com/leg100/otf/internal/api"
"github.com/leg100/otf/internal/resource"
)

type Client struct {
Expand All @@ -17,8 +18,8 @@ type Client struct {
}

// DownloadConfig downloads a configuration version tarball. Only configuration versions in the uploaded state may be downloaded.
func (c *Client) DownloadConfig(ctx context.Context, cvID resource.ID ([]byte, error) {
u := fmt.Sprintf("configuration-versions/%s/download", url.QueryEscape(cvID))
func (c *Client) DownloadConfig(ctx context.Context, cvID resource.ID) ([]byte, error) {
u := fmt.Sprintf("configuration-versions/%s/download", url.QueryEscape(cvID.String()))
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions internal/configversion/configuration_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type (
Speculative bool
Status ConfigurationStatus
StatusTimestamps []ConfigurationVersionStatusTimestamp
WorkspaceID string
WorkspaceID resource.ID
IngressAttributes *IngressAttributes
}

Expand Down Expand Up @@ -71,10 +71,10 @@ type (
// version. Either ID *or* WorkspaceID must be specfiied.
ConfigurationVersionGetOptions struct {
// ID of config version to retrieve
ID *string
ID *resource.ID

// Get latest config version for this workspace ID
WorkspaceID *string
WorkspaceID *resource.ID

// A list of relations to include
Include *string `schema:"include"`
Expand Down Expand Up @@ -112,7 +112,7 @@ type (
)

// NewConfigurationVersion creates a ConfigurationVersion object from scratch
func NewConfigurationVersion(workspaceID string, opts CreateOptions) (*ConfigurationVersion, error) {
func NewConfigurationVersion(workspaceID resource.ID, opts CreateOptions) (*ConfigurationVersion, error) {
cv := ConfigurationVersion{
ID: resource.NewID(Kind),
CreatedAt: internal.CurrentTimestamp(nil),
Expand Down
10 changes: 5 additions & 5 deletions internal/configversion/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (db *pgdb) UploadConfigurationVersion(ctx context.Context, id resource.ID,
})
}

func (db *pgdb) ListConfigurationVersions(ctx context.Context, workspaceid resource.ID, opts ListOptions) (*resource.Page[*ConfigurationVersion], error) {
func (db *pgdb) ListConfigurationVersions(ctx context.Context, workspaceID resource.ID, opts ListOptions) (*resource.Page[*ConfigurationVersion], error) {
q := db.Querier(ctx)
rows, err := q.FindConfigurationVersionsByWorkspaceID(ctx, sqlc.FindConfigurationVersionsByWorkspaceIDParams{
WorkspaceID: sql.String(workspaceID.String()),
Expand All @@ -102,13 +102,13 @@ func (db *pgdb) ListConfigurationVersions(ctx context.Context, workspaceid resou
func (db *pgdb) GetConfigurationVersion(ctx context.Context, opts ConfigurationVersionGetOptions) (*ConfigurationVersion, error) {
q := db.Querier(ctx)
if opts.ID != nil {
result, err := q.FindConfigurationVersionByID(ctx, sql.String(*opts.ID.String()))
result, err := q.FindConfigurationVersionByID(ctx, sql.String(opts.ID.String()))
if err != nil {
return nil, sql.Error(err)
}
return pgRow(result).toConfigVersion(), nil
} else if opts.WorkspaceID != nil {
result, err := q.FindConfigurationVersionLatestByWorkspaceID(ctx, sql.String(*opts.WorkspaceID.String()))
result, err := q.FindConfigurationVersionLatestByWorkspaceID(ctx, sql.String(opts.WorkspaceID.String()))
if err != nil {
return nil, sql.Error(err)
}
Expand All @@ -119,15 +119,15 @@ func (db *pgdb) GetConfigurationVersion(ctx context.Context, opts ConfigurationV
}

func (db *pgdb) GetConfig(ctx context.Context, id resource.ID) ([]byte, error) {
cfg, err := db.Querier(ctx).DownloadConfigurationVersion(ctx, sql.String(id))
cfg, err := db.Querier(ctx).DownloadConfigurationVersion(ctx, sql.String(id.String()))
if err != nil {
return nil, sql.Error(err)
}
return cfg, nil
}

func (db *pgdb) DeleteConfigurationVersion(ctx context.Context, id resource.ID) error {
_, err := db.Querier(ctx).DeleteConfigurationVersionByID(ctx, sql.String(id))
_, err := db.Querier(ctx).DeleteConfigurationVersionByID(ctx, sql.String(id.String()))
if err != nil {
return sql.Error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/configversion/tfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type tfe struct {
// tfeConfigsClient gives the tfe handlers access to config version services
type tfeClient interface {
Create(ctx context.Context, workspaceid resource.ID, opts CreateOptions) (*ConfigurationVersion, error)
Get(ctx context.Context, id resource.ID (*ConfigurationVersion, error)
Get(ctx context.Context, id resource.ID) (*ConfigurationVersion, error)
GetLatest(ctx context.Context, workspaceID resource.ID) (*ConfigurationVersion, error)
List(ctx context.Context, workspaceID resource.ID, opts ListOptions) (*resource.Page[*ConfigurationVersion], error)
Delete(ctx context.Context, cvID resource.ID) error
Expand Down
2 changes: 1 addition & 1 deletion internal/organization/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (u *OrganizationToken) CanAccessSite(action rbac.Action) bool {
return false
}

func (u *OrganizationToken) CanAccessTeam(rbac.Action, string) bool {
func (u *OrganizationToken) CanAccessTeam(rbac.Action, resource.ID) bool {
// only be used for organization-scoped resources.
return false
}
Expand Down
2 changes: 1 addition & 1 deletion internal/runner/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (j *Job) CanAccessWorkspace(action rbac.Action, policy authz.WorkspacePolic
return false
}

func (j *Job) CanAccessTeam(rbac.Action, string) bool {
func (j *Job) CanAccessTeam(rbac.Action, resource.ID) bool {
// Can't access team level actions
return false
}
Expand Down
2 changes: 1 addition & 1 deletion internal/runner/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (*RunnerMeta) CanAccessSite(action rbac.Action) bool {
return false
}

func (*RunnerMeta) CanAccessTeam(rbac.Action, string) bool {
func (*RunnerMeta) CanAccessTeam(rbac.Action, resource.ID) bool {
return false
}

Expand Down

0 comments on commit 303f263

Please sign in to comment.