This repository was archived by the owner on Aug 15, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathstacktemplate.go
More file actions
77 lines (67 loc) · 2.03 KB
/
Copy pathstacktemplate.go
File metadata and controls
77 lines (67 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package models
import (
"time"
"gopkg.in/mgo.v2/bson"
)
// StackTemplateConfig represents jStackTemplate.config field.
type StackTemplateConfig struct {
RequiredData map[string][]string `bson:"requiredData"`
RequiredProviders []string `bson:"requiredProviders"`
Verified bool `bson:"verified"`
}
const (
AccessPrivate = "private"
AccessGroup = "group"
AccessPublic = "public"
)
// StackTemplate is a document from jStackTemplates collection
type StackTemplate struct {
Id bson.ObjectId `bson:"_id" json:"-"`
AccessLevel string `bson:"accessLevel"`
Template struct {
Content string `bson:"content"`
RawContent string `bson:"rawContent"`
Sum string `bson:"sum"`
Details bson.M `bson:"details"`
} `bson:"template"`
Config *StackTemplateConfig `bson:"config"`
Credentials map[string][]string `bson:"credentials"`
Description string `bson:"description"`
Group string `bson:"group"`
Machines []bson.M `bson:"machines"`
Meta bson.M `bson:"meta"`
OriginID bson.ObjectId `bson:"originId"`
Title string `bson:"title"`
}
func NewStackTemplate(provider, identifier string) *StackTemplate {
now := time.Now().UTC()
return &StackTemplate{
Id: bson.NewObjectId(),
AccessLevel: "private",
Config: &StackTemplateConfig{
RequiredData: map[string][]string{
"user": {"username"},
"group": {"slug"},
},
RequiredProviders: []string{
"koding",
provider,
},
Verified: true,
},
Credentials: map[string][]string{
provider: {identifier},
},
Description: "##### Readme text for this stack template\n\nYou can write" +
" down a readme text for new users.\nThis text will be shown when they " +
"want to use this stack.\nYou can use markdown with the readme content.\n\n",
Meta: bson.M{
"createdAt": now,
"modifiedAt": now,
"tags": nil,
"views": nil,
"votes": nil,
"likes": 0,
},
}
}