hashicorpdocs

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package hashicorpdocs contains helpers for working with HashiCorp's document templates.

Index

Constants

View Source
const (
	// MaxDocSize is the maximum size of a doc's content in bytes. If the doc is
	// larger than this, its content will be trimmed to this length.
	// Algolia has a hard limit of 100000 bytes total per record.
	MaxDocSize = 85000
)

Variables

View Source
var ValidCustomDocTypeFieldTypes = []string{
	"PEOPLE",
	"STRING",
}

Functions

func IsLocked added in v0.2.0

func IsLocked(
	fileID string,
	db *gorm.DB,
	goog *googleworkspace.Service,
	log hclog.Logger,
) (bool, error)

IsLocked checks if a document contains one or more suggestions in the header, locks/unlocks the document accordingly, and returns the lock status.

Types

type BaseDoc

type BaseDoc struct {
	// ObjectID is the Google Drive file ID for the document.
	ObjectID string `json:"objectID,omitempty"`

	// Title is the title of the document. It does not contain the document number
	// (e.g., "TF-123").
	Title string `json:"title,omitempty"`

	// DocType is the type of document (e.g., "RFC", "PRD").
	DocType string `json:"docType,omitempty"`

	// DocNumber is a unique document identifier containing a product/area
	// abbreviation and a unique number (e.g., "TF-123").
	DocNumber string `json:"docNumber,omitempty"`

	// AppCreated should be set to true if the document was created through this
	// application, and false if created directly in Google Docs and indexed
	// afterwards.
	AppCreated bool `json:"appCreated,omitempty"`

	// ApprovedBy is a slice of email address strings for users that have approved
	// the document.
	ApprovedBy []string `json:"approvedBy,omitempty"`

	// Approvers is a slice of email address strings for users whose approvals
	// are requested for the document.
	Approvers []string `json:"approvers,omitempty"`

	// ChangesRequestedBy is a slice of email address strings for users that have
	// requested changes for the document.
	ChangesRequestedBy []string `json:"changesRequestedBy,omitempty"`

	// Contributors is a slice of email address strings for users who have
	// contributed to the document.
	Contributors []string `json:"contributors,omitempty"`

	// Content is the plaintext content of the document.
	Content string `json:"content,omitempty"`

	// Created is the UTC time of document creation, in a RFC 3339 string format.
	Created string `json:"created,omitempty"`

	// CreatedTime is the time of document creation, in Unix time.
	CreatedTime int64 `json:"createdTime,omitempty"`

	// CustomEditableFields are all document-type-specific fields that are
	// editable.
	CustomEditableFields map[string]CustomDocTypeField `json:"customEditableFields,omitempty"`

	// FileRevisions is a map of file revision IDs to custom names.
	FileRevisions map[string]string `json:"fileRevisions,omitempty"`

	// TODO: LinkedDocs is not used yet.
	LinkedDocs []string `json:"linkedDocs,omitempty"`

	// Locked is true if the document is locked for editing.
	Locked bool `json:"locked,omitempty"`

	// MetaTags contains metadata tags that can be used for filtering in Algolia.
	MetaTags []string `json:"_tags,omitempty"`

	// Created is the time that the document was last modified, in Unix time.
	ModifiedTime int64 `json:"modifiedTime,omitempty"`

	// Owners is a slice of email address strings for document owners. Hermes
	// generally only uses the first element as the document owner, but this is a
	// slice for historical reasons as some HashiCorp documents have had multiple
	// owners in the past.
	Owners []string `json:"owners,omitempty"`

	// OwnerPhotos is a slice of URL strings for the profile photos of the
	// document owners (in the same order as the Owners field).
	OwnerPhotos []string `json:"ownerPhotos,omitempty"`

	// Product is the product or area that the document relates to.
	Product string `json:"product,omitempty"`

	// Summary is a summary of the document.
	Summary string `json:"summary,omitempty"`

	// Status is the status of the document (e.g., "WIP", "In-Review", "Approved",
	// "Obsolete").
	Status string `json:"status,omitempty"`

	// Tags is a slice of tags to help users discover the document based on their
	// interests.
	Tags []string `json:"tags,omitempty"`

	// ThumbnailLink is a URL string for the document thumbnail image.
	ThumbnailLink string `json:"thumbnailLink,omitempty"`
}

BaseDoc contains common document metadata fields used by Hermes.

func (*BaseDoc) DeleteFileRevision

func (d *BaseDoc) DeleteFileRevision(revisionID string)

func (BaseDoc) GetApprovedBy

func (d BaseDoc) GetApprovedBy() []string

func (BaseDoc) GetApprovers

func (d BaseDoc) GetApprovers() []string

func (BaseDoc) GetChangesRequestedBy

func (d BaseDoc) GetChangesRequestedBy() []string

func (BaseDoc) GetContributors

func (d BaseDoc) GetContributors() []string

func (BaseDoc) GetCreatedTime

func (d BaseDoc) GetCreatedTime() int64

func (BaseDoc) GetDocNumber

func (d BaseDoc) GetDocNumber() string

func (BaseDoc) GetDocType

func (d BaseDoc) GetDocType() string

func (BaseDoc) GetMetaTags

func (d BaseDoc) GetMetaTags() []string

func (BaseDoc) GetModifiedTime

func (d BaseDoc) GetModifiedTime() int64

func (BaseDoc) GetObjectID

func (d BaseDoc) GetObjectID() string

func (BaseDoc) GetOwners

func (d BaseDoc) GetOwners() []string

func (BaseDoc) GetProduct

func (d BaseDoc) GetProduct() string

func (BaseDoc) GetStatus

func (d BaseDoc) GetStatus() string

func (BaseDoc) GetSummary

func (d BaseDoc) GetSummary() string

func (BaseDoc) GetTitle

func (d BaseDoc) GetTitle() string

func (*BaseDoc) SetApprovedBy

func (d *BaseDoc) SetApprovedBy(s []string)

func (*BaseDoc) SetChangesRequestedBy

func (d *BaseDoc) SetChangesRequestedBy(s []string)

func (*BaseDoc) SetContent

func (d *BaseDoc) SetContent(s string)

func (*BaseDoc) SetDocNumber

func (d *BaseDoc) SetDocNumber(s string)

func (*BaseDoc) SetFileRevision

func (d *BaseDoc) SetFileRevision(revisionID, revisionName string)

func (*BaseDoc) SetLocked added in v0.2.0

func (d *BaseDoc) SetLocked(l bool)

func (*BaseDoc) SetModifiedTime

func (d *BaseDoc) SetModifiedTime(i int64)

func (*BaseDoc) SetStatus

func (d *BaseDoc) SetStatus(s string)

type CustomDocTypeField

type CustomDocTypeField struct {
	// DisplayName is the display name of the custom document-type field.
	DisplayName string `json:"displayName"`

	// Type is the type of the custom document-type field. It is used by the
	// frontend to display the proper input component.
	// Valid values: "PEOPLE", "STRING".
	Type string `json:"type"`
}

type Doc

type Doc interface {
	DeleteFileRevision(string)

	// Getters for fields common to all document types.
	GetApprovedBy() []string
	GetApprovers() []string
	GetChangesRequestedBy() []string
	GetContributors() []string
	GetCreatedTime() int64
	GetDocNumber() string
	GetDocType() string
	GetMetaTags() []string
	GetModifiedTime() int64
	GetObjectID() string
	GetOwners() []string
	GetProduct() string
	GetStatus() string
	GetSummary() string
	GetTitle() string

	MissingFields() []string
	ReplaceHeader(fileID, baseURL string, isDraft bool, s *gw.Service) error

	// Setters for fields common to all document types.
	SetApprovedBy([]string)
	SetChangesRequestedBy([]string)
	SetContent(s string)
	SetDocNumber(string)
	SetFileRevision(string, string)
	SetLocked(bool)
	SetModifiedTime(int64)
	SetStatus(string)

	GetCustomEditableFields() map[string]CustomDocTypeField
	SetCustomEditableFields()
}

func NewEmptyDoc

func NewEmptyDoc(docType string) (Doc, error)

NewEmptyDoc returns an empty doc struct for the provided doc type.

func ParseDoc

func ParseDoc(
	docType string,
	f *drive.File,
	s *gw.Service,
	allFolders []string) (Doc, error)

ParseDoc parses and returns a known document type, associated product name, document number or returns an error if the type is unknown.

type FRD

type FRD struct {
	BaseDoc `mapstructure:",squash"`

	// PRD is the associated PRD.
	PRD string `json:"prd,omitempty"`

	// PRFAQ is the associated PRFAQ.
	PRFAQ string `json:"prfaq,omitempty"`
}

FRD contains metadata for documents based off of the HashiCorp FRD template.

func NewFRD

func NewFRD(f *drive.File, s *gw.Service, allFolders []string) (*FRD, error)

NewFRD parses a Google Drive file based on the HashiCorp FRD template and returns the resulting FRD struct.

func (FRD) GetCustomEditableFields

func (d FRD) GetCustomEditableFields() map[string]CustomDocTypeField

func (FRD) MissingFields

func (d FRD) MissingFields() []string

MissingFields returns the missing fields of the doc struct.

func (*FRD) ReplaceHeader

func (doc *FRD) ReplaceHeader(fileID, baseURL string, isDraft bool, s *gw.Service) error

func (*FRD) SetCustomEditableFields

func (d *FRD) SetCustomEditableFields()

type MissingFields

type MissingFields struct {
	ObjectID      string   `json:"objectID,omitempty"`
	MissingFields []string `json:"missingFields,omitempty"`
}

type PRD

type PRD struct {
	BaseDoc `mapstructure:",squash"`

	// RFC is the associated RFC.
	RFC string `json:"rfc,omitempty"`

	// Stakeholders is a slice of email address strings for document stakeholders.
	Stakeholders []string `json:"stakeholders,omitempty"`
}

PRD contains metadata for documents based off of the HashiCorp PRD template.

func NewPRD

func NewPRD(f *drive.File, s *gw.Service, allFolders []string) (*PRD, error)

NewPRD parses a Google Drive file based on the HashiCorp PRD template and returns the resulting PRD struct.

func (PRD) GetCustomEditableFields

func (d PRD) GetCustomEditableFields() map[string]CustomDocTypeField

func (PRD) MissingFields

func (d PRD) MissingFields() []string

MissingFields returns the missing fields of the doc struct.

func (*PRD) ReplaceHeader

func (doc *PRD) ReplaceHeader(fileID, baseURL string, isDraft bool, s *gw.Service) error

func (*PRD) SetCustomEditableFields

func (d *PRD) SetCustomEditableFields()

type RFC

type RFC struct {
	BaseDoc `mapstructure:",squash"`

	// CurrentVersion is the current version of the product at the time of
	// document authoring.
	CurrentVersion string `json:"currentVersion,omitempty"`

	// PRD is the associated PRD.
	PRD string `json:"prd,omitempty"`

	// Stakeholders is a slice of email address strings for document stakeholders.
	Stakeholders []string `json:"stakeholders,omitempty"`

	// TargetVersion is the target version of the product for the changes being
	// proposed in the document.
	TargetVersion string `json:"targetVersion,omitempty"`
}

RFC contains metadata for documents based off of the HashiCorp RFC template.

func NewRFC

func NewRFC(f *drive.File, s *gw.Service, allFolders []string) (*RFC, error)

NewRFC parses a Google Drive file based on the HashiCorp RFC template and returns the resulting RFC struct.

func (RFC) GetCustomEditableFields

func (d RFC) GetCustomEditableFields() map[string]CustomDocTypeField

func (RFC) MissingFields

func (d RFC) MissingFields() []string

MissingFields returns the missing fields of the doc struct.

func (*RFC) ReplaceHeader

func (doc *RFC) ReplaceHeader(fileID, baseURL string, isDraft bool, s *gw.Service) error

func (*RFC) SetCustomEditableFields

func (d *RFC) SetCustomEditableFields()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL