Skip to content

Commit bf0e6c4

Browse files
committed
added appropriate attributions in source
1 parent 9dc692e commit bf0e6c4

File tree

8 files changed

+49
-0
lines changed

8 files changed

+49
-0
lines changed

taco/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,3 +635,23 @@ terraform init -reconfigure && terraform apply -auto-approve
635635
```
636636
637637
More details in `docs/s3-compat.md`.
638+
639+
640+
## Attribution
641+
642+
Portions of the state management piece that relate to TFE API compatability and domain models have been adopted from the OTF project: https://github.com/leg100/otf,
643+
it has really helped support the cloud{} block support in opentaco statesman without alot of reverse engineering the TFE API, so we are grateful for this work. The following
644+
is a detailed list of these items:
645+
646+
| File | Adapted Elements |
647+
|-----------------------------------|------------------------------------------------------------------------------------------------------------------------|
648+
| internal/domain/tfe_id.go | The `TFEID` struct and functions on it, including `MustHardcodeTfeID`, `ParseTfeID`, `NewTfeID`, and `NewTfeIDWithVal` |
649+
| internal/domain/tfe_kind.go | All the constants that end in `Kind` within this file have been adapted as enums |
650+
| internal/domain/tfe_org.go | `DefaultOrganizationPermissions`, `TFEOrganizationPermissions`, `TFEOrganization`, and `TFEEntitleÒments` structs |
651+
| internal/domain/tfe_workspace.go | `Workspace`, `TFEWorkspace`, and all their embedded structs adapted to match the domain model |
652+
| internal/tfe/organizations.go | `Entitlements`, `defaultEntitlements`, and `GetOranizationEntitlements` functions |
653+
| internal/tfe/well_known.go | Structs related to `DiscoverSpec` and the `GetWellKnownJson` function adapted for use with Opentaco |
654+
| internal/tfe_workspaces.go | `ToTFE` and `GetWorkspace` adapted for use with current Opentaco endpoints |
655+
656+
657+

taco/internal/domain/tfe_id.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import (
99

1010
const base58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
1111

12+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
1213
type ID interface {
1314
fmt.Stringer
1415
Kind() Kind
1516
}
1617

18+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
1719
func GenerateRandomStringFromAlphabet(size int, alphabet string) string {
1820
buf := make([]byte, size)
1921
for i := 0; i < size; i++ {
@@ -28,6 +30,7 @@ func ConvertTfeID(id TfeID, to Kind) TfeID {
2830
return TfeID{kind: to, id: id.id}
2931
}
3032

33+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
3134
func MustHardcodeTfeID(kind Kind, suffix string) TfeID {
3235
s := fmt.Sprintf("%s-%s", kind, suffix)
3336
id, err := ParseTfeID(s)
@@ -37,6 +40,7 @@ func MustHardcodeTfeID(kind Kind, suffix string) TfeID {
3740
return id
3841
}
3942

43+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
4044
// ParseTfeID parses the ID from a string representation.
4145
func ParseTfeID(s string) (TfeID, error) {
4246
parts := strings.Split(s, "-")
@@ -54,6 +58,8 @@ func ParseTfeID(s string) (TfeID, error) {
5458
return TfeID{kind: Kind(kind), id: id}, nil
5559
}
5660

61+
// The following struct and all struct methods have been
62+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
5763
type TfeID struct {
5864
kind Kind
5965
id string
@@ -107,10 +113,12 @@ func (id *TfeID) Value() (driver.Value, error) {
107113
return id.String(), nil
108114
}
109115

116+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
110117
func NewTfeID(kind Kind) TfeID {
111118
return TfeID{kind: kind, id: GenerateRandomStringFromAlphabet(16, base58)}
112119
}
113120

121+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
114122
func NewTfeIDWithVal(kind Kind, id string) TfeID {
115123
return TfeID{kind: kind, id: id}
116124
}

taco/internal/domain/tfe_kind.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ func (k Kind) String() string {
66
return string(k)
77
}
88

9+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
910
const (
1011
SiteKind Kind = "site"
1112
OrganizationKind Kind = "org"

taco/internal/domain/tfe_org.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package domain
22

33
import "time"
44

5+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
56
var DefaultOrganizationPermissions = TFEOrganizationPermissions{
67
CanCreateWorkspace: true,
78
CanUpdate: true,
89
CanDestroy: true,
910
}
1011

12+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
1113
type TFEOrganizationPermissions struct {
1214
CanCreateTeam bool `json:"can-create-team"`
1315
CanCreateWorkspace bool `json:"can-create-workspace"`
@@ -30,6 +32,7 @@ func NewName(name string) Name {
3032

3133
type TFEAuthPolicyType string
3234

35+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
3336
type TFEOrganization struct {
3437
// Primary ID
3538
Name string `jsonapi:"primary,organizations"`
@@ -58,6 +61,7 @@ type TFEOrganization struct {
5861
// DefaultProject *Project `jsonapi:"relation,default-project"`
5962
}
6063

64+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
6165
type TFEEntitlements struct {
6266
ID string `jsonapi:"primary,entitlement-sets"`
6367
Agents bool `jsonapi:"attr,agents" json:"agents"`

taco/internal/domain/tfe_workspace.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type VCSRepo struct {
1616
name string
1717
}
1818

19+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
1920
type VCSConnection struct {
2021
// Pushes to this VCS branch trigger runs. Empty string means the default
2122
// branch is used. Ignored if TagsRegex is non-empty.
@@ -33,6 +34,7 @@ type VCSConnection struct {
3334
AllowCLIApply bool
3435
}
3536

37+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
3638
type WorkspaceVersion struct {
3739
// Latest if true means runs use the Latest available version at time of
3840
// creation of the run.
@@ -44,6 +46,8 @@ type WorkspaceVersion struct {
4446
semver string
4547
}
4648

49+
// Following struct and its methods have been
50+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
4751
// If you ever marshal this domain type via jsonapi (you currently don't),
4852
// its tags must also be valid. Fixing them anyway for completeness.
4953
type Workspace struct {
@@ -89,10 +93,12 @@ func (ws *Workspace) Locked() bool {
8993

9094
// ---- JSON:API DTOs below ----
9195

96+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
9297
type TFEWorkspaceActions struct {
9398
IsDestroyable bool `json:"is-destroyable"`
9499
}
95100

101+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
96102
type TFEWorkspacePermissions struct {
97103
CanDestroy bool `json:"can-destroy"`
98104
CanForceUnlock bool `json:"can-force-unlock"`
@@ -106,6 +112,7 @@ type TFEWorkspacePermissions struct {
106112
CanUpdateVariable bool `json:"can-update-variable"`
107113
}
108114

115+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
109116
// TFEVCSRepo is carried as a single attribute object on the workspace.
110117
type TFEVCSRepo struct {
111118
Branch string `json:"branch"`
@@ -118,10 +125,12 @@ type TFEVCSRepo struct {
118125
ServiceProvider string `json:"service-provider"`
119126
}
120127

128+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
121129
type TFERun struct {
122130
ID string `jsonapi:"primary,runs"`
123131
}
124132

133+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
125134
type TFEWorkspace struct {
126135
ID string `jsonapi:"primary,workspaces"`
127136
Actions *TFEWorkspaceActions `jsonapi:"attr,actions" json:"actions"`
@@ -165,6 +174,7 @@ type TFEWorkspace struct {
165174
Outputs []*TFEWorkspaceOutput `jsonapi:"relation,outputs" json:"outputs"`
166175
}
167176

177+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
168178
type TFEWorkspaceOutput struct {
169179
ID string `jsonapi:"primary,workspace-outputs"`
170180
Name string `jsonapi:"attr,Name" json:"Name"`

taco/internal/tfe/organizations.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/labstack/echo/v4"
1111
)
1212

13+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
1314
type Entitlements struct {
1415
ID domain.TfeID
1516
Agents bool
@@ -24,6 +25,7 @@ type Entitlements struct {
2425
VCSIntegrations bool
2526
}
2627

28+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
2729
func defaultEntitlements(organizationID domain.TfeID) Entitlements {
2830
return Entitlements{
2931
ID: organizationID,
@@ -40,6 +42,7 @@ func defaultEntitlements(organizationID domain.TfeID) Entitlements {
4042
}
4143
}
4244

45+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
4346
func (h *TfeHandler) GetOrganizationEntitlements(c echo.Context) error {
4447
tfidStr := domain.NewTfeIDWithVal(domain.OrganizationKind, "RoiPNhWzpjaKhjcV")
4548
domain.NewTfeID(domain.OrganizationKind)

taco/internal/tfe/well_known.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const (
2121
TokenRoute = "/tfe/oauth2/token"
2222
)
2323

24+
// These Discovery structs have been
25+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
2426
// login stuff, TODO: move to own package etc
2527
type DiscoverySpec struct {
2628
Client string `json:"client"`

taco/internal/tfe/workspaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ func (h *TfeHandler) checkWorkspacePermission(c echo.Context, action string, wor
221221
return nil
222222
}
223223

224+
// Adapted from OTF (MPL License): https://github.com/leg100/otf
224225
func ToTFE(from *domain.Workspace) (*domain.TFEWorkspace, error) {
225226
perms := &domain.TFEWorkspacePermissions{
226227
CanLock: true,

0 commit comments

Comments
 (0)