Skip to content

Commit

Permalink
chore: complete owner transfer and fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
pandatix committed Dec 9, 2023
1 parent 0e66bc8 commit 3373fd8
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 236 deletions.
47 changes: 14 additions & 33 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
module github.com/ctfer-io/tofu-provider-ctfd
module github.com/ctfer-io/terraform-provider-ctfd

go 1.21
go 1.21.3

require (
github.com/opentofu/terraform-plugin-framework v1.3.4
github.com/opentofu/terraform-plugin-go v0.18.0
github.com/opentofu/terraform-plugin-log v0.9.0
github.com/opentofu/terraform-plugin-testing v1.5.1
github.com/ctfer-io/go-ctfd v0.1.9
github.com/ctfer-io/go-ctfd v0.3.3
github.com/hashicorp/terraform-plugin-framework v1.4.2
github.com/hashicorp/terraform-plugin-go v0.19.0
github.com/hashicorp/terraform-plugin-log v0.9.0
)

require (
Expand All @@ -17,24 +16,11 @@ require (
github.com/cloudflare/circl v1.3.3 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/gorilla/schema v1.2.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
github.com/gorilla/schema v1.2.1 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-plugin v1.4.10 // indirect
github.com/hashicorp/go-plugin v1.5.1 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hc-install v0.5.2 // indirect
github.com/hashicorp/hcl/v2 v2.17.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.18.1 // indirect
github.com/hashicorp/terraform-json v0.17.1 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.28.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.1 // indirect
github.com/hashicorp/terraform-registry-address v0.2.2 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
Expand All @@ -49,15 +35,10 @@ require (
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/zclconf/go-cty v1.13.3 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.56.1 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
137 changes: 28 additions & 109 deletions go.sum

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions internal/provider/challenge/file_subresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"strconv"

"github.com/ctfer-io/go-ctfd/api"
"github.com/opentofu/terraform-plugin-framework/diag"
"github.com/opentofu/terraform-plugin-framework/resource/schema"
"github.com/opentofu/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/opentofu/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/opentofu/terraform-plugin-framework/types"
"github.com/opentofu/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
)

type FileSubresourceModel struct {
Expand Down Expand Up @@ -64,7 +64,7 @@ func FileSubresourceAttributes() map[string]schema.Attribute {
func (file *FileSubresourceModel) Read(ctx context.Context, diags diag.Diagnostics, client *api.Client) {
content, err := client.GetFileContent(&api.File{
Location: file.Location.ValueString(),
}, api.WithContext(ctx))
})
if err != nil {
diags.AddError(
"CTFd Error",
Expand All @@ -76,7 +76,7 @@ func (file *FileSubresourceModel) Read(ctx context.Context, diags diag.Diagnosti
file.PropagateContent(ctx, diags)
}

func (data *FileSubresourceModel) Create(ctx context.Context, diags diag.Diagnostics, client *api.Client, challengeID string) {
func (data *FileSubresourceModel) Create(ctx context.Context, diags diag.Diagnostics, client *api.Client, challengeID int) {
// Fetch raw or base64 content prior to creating it with raw
data.PropagateContent(ctx, diags)
if diags.HasError() {
Expand Down
16 changes: 8 additions & 8 deletions internal/provider/challenge/flag_subresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"strconv"

"github.com/ctfer-io/go-ctfd/api"
"github.com/opentofu/terraform-plugin-framework/diag"
"github.com/opentofu/terraform-plugin-framework/resource/schema"
"github.com/opentofu/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/opentofu/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/opentofu/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/opentofu/terraform-plugin-framework/types"
"github.com/opentofu/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
)

type FlagSubresourceModel struct {
Expand Down Expand Up @@ -50,7 +50,7 @@ func FlagSubresourceAttributes() map[string]schema.Attribute {
}
}

func (data *FlagSubresourceModel) Create(ctx context.Context, diags diag.Diagnostics, client *api.Client, challengeID string) {
func (data *FlagSubresourceModel) Create(ctx context.Context, diags diag.Diagnostics, client *api.Client, challengeID int) {
res, err := client.PostFlags(&api.PostFlagsParams{
Challenge: challengeID,
Content: data.Content.ValueString(),
Expand Down
16 changes: 8 additions & 8 deletions internal/provider/challenge/hint_subresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"strconv"

"github.com/ctfer-io/go-ctfd/api"
"github.com/opentofu/terraform-plugin-framework/diag"
"github.com/opentofu/terraform-plugin-framework/resource/schema"
"github.com/opentofu/terraform-plugin-framework/resource/schema/int64default"
"github.com/opentofu/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/opentofu/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/opentofu/terraform-plugin-framework/types"
"github.com/opentofu/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
)

// TODO requirements can be set manually, but can't be automatised. Hint may be a complete resource
Expand Down Expand Up @@ -48,7 +48,7 @@ func HintSubresourceAttributes() map[string]schema.Attribute {
}
}

func (data *HintSubresourceModel) Create(ctx context.Context, diags diag.Diagnostics, client *api.Client, challengeID string) {
func (data *HintSubresourceModel) Create(ctx context.Context, diags diag.Diagnostics, client *api.Client, challengeID int) {
preq := make([]int, 0, len(data.Requirements))
for _, req := range data.Requirements {
hintID, _ := strconv.Atoi(req.ValueString())
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/challenge/requirements_subresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package challenge

import (
"github.com/ctfer-io/terraform-provider-ctfd/internal/provider/utils"
"github.com/opentofu/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types"
)

var (
Expand Down
20 changes: 10 additions & 10 deletions internal/provider/challenge_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"github.com/ctfer-io/go-ctfd/api"
"github.com/ctfer-io/terraform-provider-ctfd/internal/provider/challenge"
"github.com/ctfer-io/terraform-provider-ctfd/internal/provider/utils"
"github.com/opentofu/terraform-plugin-framework/datasource"
"github.com/opentofu/terraform-plugin-framework/datasource/schema"
"github.com/opentofu/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)

var (
Expand Down Expand Up @@ -139,7 +139,7 @@ func (ch *challengeDataSource) Read(ctx context.Context, req datasource.ReadRequ

for _, chall := range challs {
// Fetch the challenge with all its information as the CTFd API is broken as fuck
chall, err := ch.client.GetChallenge(strconv.Itoa(chall.ID), api.WithContext(ctx))
chall, err := ch.client.GetChallenge(chall.ID, api.WithContext(ctx))
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Unable to Read CTFd Challenge %d", chall.ID),
Expand All @@ -149,7 +149,7 @@ func (ch *challengeDataSource) Read(ctx context.Context, req datasource.ReadRequ
}

// => Files
files, err := ch.client.GetChallengeFiles(strconv.Itoa(chall.ID))
files, err := ch.client.GetChallengeFiles(chall.ID)
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Unable to Read CTFd files of Challenge %d", chall.ID),
Expand All @@ -169,7 +169,7 @@ func (ch *challengeDataSource) Read(ctx context.Context, req datasource.ReadRequ
}

// => Flags
flags, err := ch.client.GetChallengeFlags(strconv.Itoa(chall.ID), api.WithContext(ctx))
flags, err := ch.client.GetChallengeFlags(chall.ID, api.WithContext(ctx))
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Unable to Read CTFd flags of Challenge %d", chall.ID),
Expand All @@ -189,7 +189,7 @@ func (ch *challengeDataSource) Read(ctx context.Context, req datasource.ReadRequ
}

// => Tags
tags, err := ch.client.GetChallengeTags(strconv.Itoa(chall.ID), api.WithContext(ctx))
tags, err := ch.client.GetChallengeTags(chall.ID, api.WithContext(ctx))
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Unable to Read CTFd tags of Challenge %d", chall.ID),
Expand All @@ -203,7 +203,7 @@ func (ch *challengeDataSource) Read(ctx context.Context, req datasource.ReadRequ
}

// => Topics
topics, err := ch.client.GetChallengeTopics(strconv.Itoa(chall.ID), api.WithContext(ctx))
topics, err := ch.client.GetChallengeTopics(chall.ID, api.WithContext(ctx))
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Unable to Read CTFd topics of Challenge %d", chall.ID),
Expand All @@ -217,7 +217,7 @@ func (ch *challengeDataSource) Read(ctx context.Context, req datasource.ReadRequ
}

// => Hints
hints, err := ch.client.GetChallengeHints(strconv.Itoa(chall.ID), api.WithContext(ctx))
hints, err := ch.client.GetChallengeHints(chall.ID, api.WithContext(ctx))
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Unable to Reac CTFd hints of Challenge %d", chall.ID),
Expand All @@ -244,7 +244,7 @@ func (ch *challengeDataSource) Read(ctx context.Context, req datasource.ReadRequ
Name: types.StringValue(chall.Name),
Category: types.StringValue(chall.Category),
Description: types.StringValue(chall.Description),
Value: utils.ToTFInt64(chall.Value),
Value: types.Int64Value(int64(chall.Value)),
Initial: utils.ToTFInt64(chall.Initial),
Decay: utils.ToTFInt64(chall.Decay),
Minimum: utils.ToTFInt64(chall.Minimum),
Expand Down
Loading

0 comments on commit 3373fd8

Please sign in to comment.