Skip to content

Commit

Permalink
v0.1.13
Browse files Browse the repository at this point in the history
[Bot] push changes from Files.com
  • Loading branch information
files-opensource-bot committed Jul 20, 2024
1 parent 9ce310d commit 2bdb465
Show file tree
Hide file tree
Showing 17 changed files with 781 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ terraform {
required_providers {
files = {
source = "Files-com/files"
version = "0.1.12"
version = "0.1.13"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion _VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.12
0.1.13
33 changes: 33 additions & 0 deletions docs/data-sources/file_comment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "files_file_comment Data Source - files"
subcategory: ""
description: |-
File Comments are comments attached to a file by a user.
---

# files_file_comment (Data Source)

File Comments are comments attached to a file by a user.

## Example Usage

```terraform
data "files_file_comment" "example_file_comment" {
id = 1
path = "path"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `id` (Number) File Comment ID
- `path` (String) File path.

### Read-Only

- `body` (String) Comment body.
- `reactions` (Dynamic) Reactions to this comment.
47 changes: 47 additions & 0 deletions docs/data-sources/group_user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "files_group_user Data Source - files"
subcategory: ""
description: |-
A GroupUser describes the membership of a User within a Group.
Creating GroupUsers
GroupUsers can be created via the normal create action. When using the update action, if the
GroupUser record does not exist for the given user/group IDs it will be created.
---

# files_group_user (Data Source)

A GroupUser describes the membership of a User within a Group.



## Creating GroupUsers

GroupUsers can be created via the normal `create` action. When using the `update` action, if the

GroupUser record does not exist for the given user/group IDs it will be created.

## Example Usage

```terraform
data "files_group_user" "example_group_user" {
id = 1
group_id = 1
user_id = 1
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `id` (Number) Group User ID.

### Read-Only

- `admin` (Boolean) Is this user an administrator of this group?
- `group_id` (Number) Group ID
- `group_name` (String) Group name
- `user_id` (Number) User ID
- `usernames` (List of String) A list of usernames for users in this group
3 changes: 2 additions & 1 deletion docs/data-sources/lock.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Files.com's WebDAV offering and desktop app does leverage this locking API.

```terraform
data "files_lock" "example_lock" {
path = "path"
path = "path"
token = "token"
}
```

Expand Down
41 changes: 41 additions & 0 deletions docs/data-sources/permission.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "files_permission Data Source - files"
subcategory: ""
description: |-
Permission objects represent the grant of permissions to a user or group.
They are specific to a path and can be either recursive or nonrecursive into the subfolders of that path.
---

# files_permission (Data Source)

Permission objects represent the grant of permissions to a user or group.



They are specific to a path and can be either recursive or nonrecursive into the subfolders of that path.

## Example Usage

```terraform
data "files_permission" "example_permission" {
id = 1
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `id` (Number) Permission ID

### Read-Only

- `group_id` (Number) Group ID
- `group_name` (String) Group name if applicable
- `path` (String) Folder path This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters.
- `permission` (String) Permission type
- `recursive` (Boolean) Does this permission apply to subfolders?
- `user_id` (Number) User ID
- `username` (String) User's username
39 changes: 39 additions & 0 deletions docs/data-sources/request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "files_request Data Source - files"
subcategory: ""
description: |-
A Request represents a file that should be uploaded by a specific user or group.
Requests can either be manually created and managed, or managed automatically by an Automation.
---

# files_request (Data Source)

A Request represents a file that *should* be uploaded by a specific user or group.



Requests can either be manually created and managed, or managed automatically by an Automation.

## Example Usage

```terraform
data "files_request" "example_request" {
id = 1
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `id` (Number) Request ID

### Read-Only

- `automation_id` (String) ID of automation that created request
- `destination` (String) Destination filename
- `path` (String) Folder path This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters.
- `source` (String) Source filename, if applicable
- `user_display_name` (String) User making the request (if applicable)
4 changes: 4 additions & 0 deletions examples/data-sources/files_file_comment/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "files_file_comment" "example_file_comment" {
id = 1
path = "path"
}
5 changes: 5 additions & 0 deletions examples/data-sources/files_group_user/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
data "files_group_user" "example_group_user" {
id = 1
group_id = 1
user_id = 1
}
3 changes: 2 additions & 1 deletion examples/data-sources/files_lock/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
data "files_lock" "example_lock" {
path = "path"
path = "path"
token = "token"
}
3 changes: 3 additions & 0 deletions examples/data-sources/files_permission/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "files_permission" "example_permission" {
id = 1
}
3 changes: 3 additions & 0 deletions examples/data-sources/files_request/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "files_request" "example_request" {
id = 1
}
140 changes: 140 additions & 0 deletions internal/provider/file_comment_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package provider

import (
"context"
"fmt"

files_sdk "github.com/Files-com/files-sdk-go/v3"
file_comment "github.com/Files-com/files-sdk-go/v3/filecomment"
"github.com/Files-com/terraform-provider-files/lib"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/types"
)

var (
_ datasource.DataSource = &fileCommentDataSource{}
_ datasource.DataSourceWithConfigure = &fileCommentDataSource{}
)

func NewFileCommentDataSource() datasource.DataSource {
return &fileCommentDataSource{}
}

type fileCommentDataSource struct {
client *file_comment.Client
}

type fileCommentDataSourceModel struct {
Id types.Int64 `tfsdk:"id"`
Body types.String `tfsdk:"body"`
Reactions types.Dynamic `tfsdk:"reactions"`
Path types.String `tfsdk:"path"`
}

func (r *fileCommentDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if req.ProviderData == nil {
return
}

sdk_config, ok := req.ProviderData.(files_sdk.Config)

if !ok {
resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type",
fmt.Sprintf("Expected files_sdk.Config, got: %T. Please report this issue to the provider developers.", req.ProviderData),
)

return
}

r.client = &file_comment.Client{Config: sdk_config}
}

func (r *fileCommentDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_file_comment"
}

func (r *fileCommentDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "File Comments are comments attached to a file by a user.",
Attributes: map[string]schema.Attribute{
"id": schema.Int64Attribute{
Description: "File Comment ID",
Required: true,
},
"body": schema.StringAttribute{
Description: "Comment body.",
Computed: true,
},
"reactions": schema.DynamicAttribute{
Description: "Reactions to this comment.",
Computed: true,
},
"path": schema.StringAttribute{
Description: "File path.",
Required: true,
},
},
}
}

func (r *fileCommentDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data fileCommentDataSourceModel
diags := req.Config.Get(ctx, &data)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

paramsFileCommentListFor := files_sdk.FileCommentListForParams{}
paramsFileCommentListFor.Path = data.Path.ValueString()

fileCommentIt, err := r.client.ListFor(paramsFileCommentListFor, files_sdk.WithContext(ctx))
if err != nil {
resp.Diagnostics.AddError(
"Error Reading Files FileComment",
"Could not read file_comment id "+fmt.Sprint(data.Id.ValueInt64())+": "+err.Error(),
)
return
}

var fileComment *files_sdk.FileComment
for fileCommentIt.Next() {
entry := fileCommentIt.FileComment()
if entry.Id == data.Id.ValueInt64() {
fileComment = &entry
break
}
}

if fileComment == nil {
resp.Diagnostics.AddError(
"Error Reading Files FileComment",
"Could not find file_comment id "+fmt.Sprint(data.Id.ValueInt64()),
)
return
}

diags = r.populateDataSourceModel(ctx, *fileComment, &data)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

diags = resp.State.Set(ctx, data)
resp.Diagnostics.Append(diags...)
}

func (r *fileCommentDataSource) populateDataSourceModel(ctx context.Context, fileComment files_sdk.FileComment, state *fileCommentDataSourceModel) (diags diag.Diagnostics) {
var propDiags diag.Diagnostics

state.Id = types.Int64Value(fileComment.Id)
state.Body = types.StringValue(fileComment.Body)
state.Reactions, propDiags = lib.ToDynamic(ctx, path.Root("reactions"), fileComment.Reactions, state.Reactions.UnderlyingValue())
diags.Append(propDiags...)

return
}
Loading

0 comments on commit 2bdb465

Please sign in to comment.