Skip to content

Commit

Permalink
feat: base implementation of infiscial-project-group resource
Browse files Browse the repository at this point in the history
  • Loading branch information
sheensantoscapadngan committed Sep 13, 2024
1 parent a15c47d commit 0a5d037
Show file tree
Hide file tree
Showing 5 changed files with 667 additions and 24 deletions.
149 changes: 125 additions & 24 deletions internal/client/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,21 +367,21 @@ type EncryptedSecret struct {

// create secrets.
type CreateSecretV3Request struct {
SecretName string `json:"secretName"`
WorkspaceID string `json:"workspaceId"`
Type string `json:"type"`
Environment string `json:"environment"`
SecretKeyCiphertext string `json:"secretKeyCiphertext"`
SecretKeyIV string `json:"secretKeyIV"`
SecretKeyTag string `json:"secretKeyTag"`
SecretValueCiphertext string `json:"secretValueCiphertext"`
SecretValueIV string `json:"secretValueIV"`
SecretValueTag string `json:"secretValueTag"`
SecretCommentCiphertext string `json:"secretCommentCiphertext"`
SecretCommentIV string `json:"secretCommentIV"`
SecretCommentTag string `json:"secretCommentTag"`
SecretPath string `json:"secretPath"`
TagIDs []string `json:"tags"`
SecretName string `json:"secretName"`
WorkspaceID string `json:"workspaceId"`
Type string `json:"type"`
Environment string `json:"environment"`
SecretKeyCiphertext string `json:"secretKeyCiphertext"`
SecretKeyIV string `json:"secretKeyIV"`
SecretKeyTag string `json:"secretKeyTag"`
SecretValueCiphertext string `json:"secretValueCiphertext"`
SecretValueIV string `json:"secretValueIV"`
SecretValueTag string `json:"secretValueTag"`
SecretCommentCiphertext string `json:"secretCommentCiphertext"`
SecretCommentIV string `json:"secretCommentIV"`
SecretCommentTag string `json:"secretCommentTag"`
SecretPath string `json:"secretPath"`
TagIDs []string `json:"tags"`
}

// delete secret by name api.
Expand All @@ -395,15 +395,15 @@ type DeleteSecretV3Request struct {

// update secret by name api.
type UpdateSecretByNameV3Request struct {
SecretName string `json:"secretName"`
WorkspaceID string `json:"workspaceId"`
Environment string `json:"environment"`
Type string `json:"type"`
SecretPath string `json:"secretPath"`
SecretValueCiphertext string `json:"secretValueCiphertext"`
SecretValueIV string `json:"secretValueIV"`
SecretValueTag string `json:"secretValueTag"`
TagIDs []string `json:"tags,omitempty"`
SecretName string `json:"secretName"`
WorkspaceID string `json:"workspaceId"`
Environment string `json:"environment"`
Type string `json:"type"`
SecretPath string `json:"secretPath"`
SecretValueCiphertext string `json:"secretValueCiphertext"`
SecretValueIV string `json:"secretValueIV"`
SecretValueTag string `json:"secretValueTag"`
TagIDs []string `json:"tags,omitempty"`
}

// get secret by name api.
Expand Down Expand Up @@ -493,6 +493,10 @@ type GetProjectRequest struct {
Slug string `json:"slug"`
}

type GetProjectByIdRequest struct {
ID string `json:"id"`
}

type UpdateProjectRequest struct {
Slug string `json:"slug"`
ProjectName string `json:"name"`
Expand Down Expand Up @@ -763,6 +767,103 @@ type GetProjectIdentitySpecificPrivilegeResponse struct {
Privilege ProjectIdentitySpecificPrivilege `json:"privilege"`
}

// group

Check failure on line 770 in internal/client/model.go

View workflow job for this annotation

GitHub Actions / Build

Comment should end in a period (godot)

Check failure on line 770 in internal/client/model.go

View workflow job for this annotation

GitHub Actions / Build

Comment should end in a period (godot)
type ProjectGroupRole struct {
ID string `json:"id"`
Role string `json:"role"`
CustomRoleSlug string `json:"customRoleSlug"`
CustomRoleId string `json:"customRoleId"`
IsTemporary bool `json:"isTemporary"`
TemporaryMode string `json:"temporaryMode"`
TemporaryRange string `json:"temporaryRange"`
TemporaryAccessStartTime time.Time `json:"temporaryAccessStartTime"`
TemporaryAccessEndTime time.Time `json:"temporaryAccessEndTime"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}

type ProjectGroup struct {
ID string `json:"id"`
GroupID string `json:"groupId"`
Roles []ProjectGroupRole
}

type CreateProjectGroupRequestRoles struct {
Role string `json:"role"`
IsTemporary bool `json:"isTemporary"`
TemporaryMode string `json:"temporaryMode"`
TemporaryRange string `json:"temporaryRange"`
TemporaryAccessStartTime time.Time `json:"temporaryAccessStartTime"`
}

type CreateProjectGroupRequest struct {
ProjectSlug string `json:"projectSlug"`
GroupSlug string `json:"groupSlug"`
Roles []CreateProjectGroupRequestRoles `json:"roles"`
}

type CreateProjectGroupResponseMembers struct {
ID string `json:"id"`
GroupID string `json:"groupId"`
}

type CreateProjectGroupResponse struct {
Membership CreateProjectGroupResponseMembers `json:"groupMembership"`
}

type GetProjectGroupMembershipRequest struct {
ProjectSlug string `json:"projectSlug"`
GroupSlug string `json:"groupSlug"`
}

type GetProjectGroupMembershipResponse struct {
Membership ProjectGroup `json:"groupMembership"`
}

type UpdateProjectGroupRequestRoles struct {
Role string `json:"role"`
IsTemporary bool `json:"isTemporary"`
TemporaryMode string `json:"temporaryMode"`
TemporaryRange string `json:"temporaryRange"`
TemporaryAccessStartTime time.Time `json:"temporaryAccessStartTime"`
}

type UpdateProjectGroupRequest struct {
ProjectSlug string `json:"projectSlug"`
GroupSlug string `json:"groupSlug"`
Roles []UpdateProjectGroupRequestRoles `json:"roles"`
}

type UpdateProjectGroupResponse struct {
Roles []struct {
ID string `json:"id"`
Role string `json:"role"`
CustomRoleId string `json:"customRoleId"`
IsTemporary bool `json:"isTemporary"`
TemporaryMode string `json:"temporaryMode"`
TemporaryRange string `json:"temporaryRange"`
TemporaryAccessStartTime time.Time `json:"temporaryAccessStartTime"`
TemporaryAccessEndTime time.Time `json:"temporaryAccessEndTime"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
} `json:"roles"`
}

type DeleteProjectGroupRequest struct {
ProjectSlug string `json:"projectSlug"`
GroupSlug string `json:"groupSlug"`
}

type DeleteProjectGroupResponseMembers struct {
ID string `json:"id"`
GroupID string `json:"groupId"`
}

type DeleteProjectGroupResponse struct {
Membership DeleteProjectGroupResponseMembers `json:"groupMembership"`
}

// tag

Check failure on line 866 in internal/client/model.go

View workflow job for this annotation

GitHub Actions / Build

Comment should end in a period (godot)

Check failure on line 866 in internal/client/model.go

View workflow job for this annotation

GitHub Actions / Build

Comment should end in a period (godot)
type GetProjectTagsResponse struct {
Tags []ProjectTag `json:"workspaceTags"`
}
Expand Down
19 changes: 19 additions & 0 deletions internal/client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,22 @@ func (client Client) UpdateProject(request UpdateProjectRequest) (UpdateProjectR

return projectResponse, nil
}

func (client Client) GetProjectById(request GetProjectByIdRequest) (ProjectWithEnvironments, error) {
var projectResponse ProjectWithEnvironments
response, err := client.Config.HttpClient.
R().
SetResult(&projectResponse).
SetHeader("User-Agent", USER_AGENT).
Get(fmt.Sprintf("api/v1/workspace/%s", request.ID))

if err != nil {
return ProjectWithEnvironments{}, fmt.Errorf("CallGetProjectById: Unable to complete api request [err=%s]", err)
}

if response.IsError() {
return ProjectWithEnvironments{}, fmt.Errorf("CallGetProjectById: Unsuccessful response. [response=%s]", response)
}

return projectResponse, nil
}
83 changes: 83 additions & 0 deletions internal/client/project_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package infisicalclient

import "fmt"

func (client Client) CreateProjectGroup(request CreateProjectGroupRequest) (CreateProjectGroupResponse, error) {
var responseData CreateProjectGroupResponse
response, err := client.Config.HttpClient.
R().
SetResult(&responseData).
SetHeader("User-Agent", USER_AGENT).
SetBody(request).
Post(fmt.Sprintf("api/v2/workspace/%s/groups/%s", request.ProjectSlug, request.GroupSlug))

if err != nil {
return CreateProjectGroupResponse{}, fmt.Errorf("CallCreateProjectGroup: Unable to complete api request [err=%s]", err)
}

if response.IsError() {
return CreateProjectGroupResponse{}, fmt.Errorf("CallCreateProjectGroup: Unsuccessful response. [response=%s]", response)
}

return responseData, nil
}

func (client Client) GetProjectGroupMembership(request GetProjectGroupMembershipRequest) (GetProjectGroupMembershipResponse, error) {
var responseData GetProjectGroupMembershipResponse
response, err := client.Config.HttpClient.
R().
SetResult(&responseData).
SetHeader("User-Agent", USER_AGENT).
SetBody(request).
Get(fmt.Sprintf("api/v2/workspace/%s/groups/%s", request.ProjectSlug, request.GroupSlug))

if err != nil {
return GetProjectGroupMembershipResponse{}, fmt.Errorf("GetProjectGroupMembershipResponse: Unable to complete api request [err=%s]", err)
}

if response.IsError() {
return GetProjectGroupMembershipResponse{}, fmt.Errorf("GetProjectGroupMembershipResponse: Unsuccessful response. [response=%s]", response)
}

return responseData, nil
}

func (client Client) UpdateProjectGroup(request UpdateProjectGroupRequest) (UpdateProjectGroupResponse, error) {
var responseData UpdateProjectGroupResponse
response, err := client.Config.HttpClient.
R().
SetResult(&responseData).
SetHeader("User-Agent", USER_AGENT).
SetBody(request).
Patch(fmt.Sprintf("api/v2/workspace/%s/groups/%s", request.ProjectSlug, request.GroupSlug))

if err != nil {
return UpdateProjectGroupResponse{}, fmt.Errorf("CallUpdateProjectGroup: Unable to complete api request [err=%s]", err)
}

if response.IsError() {
return UpdateProjectGroupResponse{}, fmt.Errorf("CallUpdateProjectGroup: Unsuccessful response. [response=%s]", response)
}

return responseData, nil
}

func (client Client) DeleteProjectGroup(request DeleteProjectGroupRequest) (DeleteProjectGroupResponse, error) {
var responseData DeleteProjectGroupResponse
response, err := client.Config.HttpClient.
R().
SetResult(&responseData).
SetHeader("User-Agent", USER_AGENT).
SetBody(request).
Delete(fmt.Sprintf("/api/v2/workspace/%s/groups/%s", request.ProjectSlug, request.GroupSlug))

if err != nil {
return DeleteProjectGroupResponse{}, fmt.Errorf("CallDeleteProjectGroup: Unable to complete api request [err=%s]", err)
}

if response.IsError() {
return DeleteProjectGroupResponse{}, fmt.Errorf("CallDeleteProjectGroup: Unsuccessful response. [response=%s]", response)
}

return responseData, nil
}
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ func (p *infisicalProvider) Resources(_ context.Context) []func() resource.Resou
infisicalResource.NewProjectIdentityResource,
infisicalResource.NewProjectRoleResource,
infisicalResource.NewProjectIdentitySpecificPrivilegeResource,
infisicalResource.NewProjectGroupResource,
infisicalResource.NewProjectSecretTagResource,
infisicalResource.NewProjectSecretFolderResource,
infisicalResource.NewProjectEnvironmentResource,
Expand Down
Loading

0 comments on commit 0a5d037

Please sign in to comment.