Skip to content

Commit

Permalink
Draft
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielHougaard committed Feb 23, 2024
1 parent c5464da commit 1498c4f
Show file tree
Hide file tree
Showing 6 changed files with 426 additions and 1 deletion.
86 changes: 86 additions & 0 deletions client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,89 @@ func (client Client) CallGetSingleRawSecretByNameV3(request GetSingleSecretByNam

return secretsResponse, nil
}

func (client Client) CallCreateProject(request CreateProjectRequest) (CreateProjectResponse, error) {

if request.Slug == "" {
request = CreateProjectRequest{
ProjectName: request.ProjectName,
OrganizationId: request.OrganizationId,
}
}

var projectResponse CreateProjectResponse
response, err := client.Config.HttpClient.
R().
SetResult(&projectResponse).
SetHeader("User-Agent", USER_AGENT).
SetBody(request).
Post("api/v2/workspace")

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

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

return projectResponse, nil
}

func (client Client) CallDeleteProject(request DeleteProjectRequest) error {
var projectResponse DeleteProjectResponse
response, err := client.Config.HttpClient.
R().
SetResult(&projectResponse).
SetHeader("User-Agent", USER_AGENT).
Delete(fmt.Sprintf("api/v2/workspace/%s", request.Slug))

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

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

return nil
}

func (client Client) CallGetProject(request GetProjectRequest) (GetProjectResponse, error) {
var projectResponse GetProjectResponse
response, err := client.Config.HttpClient.
R().
SetResult(&projectResponse).
SetHeader("User-Agent", USER_AGENT).
Get(fmt.Sprintf("api/v2/workspace/%s", request.Slug))

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

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

return projectResponse, nil
}

func (client Client) CallUpdateProject(request UpdateProjectRequest) (UpdateProjectResponse, error) {
var projectResponse UpdateProjectResponse
response, err := client.Config.HttpClient.
R().
SetResult(&projectResponse).
SetHeader("User-Agent", USER_AGENT).
SetBody(request).
Patch(fmt.Sprintf("api/v2/workspace/%s", request.Slug))

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

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

return projectResponse, nil
}
50 changes: 50 additions & 0 deletions client/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,36 @@ type EncryptedSecretV3 struct {
UpdatedAt time.Time `json:"updatedAt"`
}

type Project struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
AutoCapitalization bool `json:"autoCapitalization"`
OrgID string `json:"orgId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Version int `json:"version"`

UpgradeStatus string `json:"upgradeStatus"` // can be null. if its null it will be converted to an empty string.
}

type ProjectWithEnvironments struct {
}

type CreateProjectResponse struct {
Project Project `json:"project"`
}

type DeleteProjectResponse struct {
Project Project `json:"workspace"`
}

type GetProjectResponse struct {
Project Project `json:"workspace"`
}

type UpdateProjectResponse Project

type GetEncryptedSecretsV3Response struct {
Secrets []EncryptedSecretV3 `json:"secrets"`
}
Expand Down Expand Up @@ -232,3 +262,23 @@ type UpdateRawSecretByNameV3Request struct {
SecretPath string `json:"secretPath"`
SecretValue string `json:"secretValue"`
}

type CreateProjectRequest struct {
ProjectName string `json:"projectName"`
Slug string `json:"slug"`
OrganizationId string `json:"organizationId"`
}

type DeleteProjectRequest struct {
Slug string `json:"slug"`
}

type GetProjectRequest struct {
Slug string `json:"slug"`
}

type UpdateProjectRequest struct {
Slug string `json:"slug"`
ProjectName string `json:"name"`
AutoCapitalization bool `json:"autoCapitalization"`
}
22 changes: 22 additions & 0 deletions examples/resources/infisical_project/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
terraform {
required_providers {
infisical = {
# version = <latest version>
source = "hashicorp.com/edu/infisical"
}
}
}

provider "infisical" {
host = "http://localhost:8080" # Only required if using self hosted instance of Infisical, default is https://app.infisical.com
client_id = "3f6135db-f237-421d-af66-a8f4e80d443b"
client_secret = "d1a9238d9fe9476e545ba92c25ece3866178e468d3b0b8f263af64026ac835bf"
}

resource "infisical_project" "a-new-project" {
name = "new name123"
slug = "a-new-project-slug"
organization_id = "180870b7-f464-4740-8ffe-9d11c9245ea7"
}


Loading

0 comments on commit 1498c4f

Please sign in to comment.