Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit a979f5b

Browse files
committed
Make parsing methods local
The parsing methods are used only internally; they must not be exposed to users outside the respective packages.
1 parent e3086ae commit a979f5b

File tree

7 files changed

+29
-29
lines changed

7 files changed

+29
-29
lines changed

openstack/orchestration/v1/stacks/environment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (e *Environment) Validate() error {
3535
// Parse environment file to resolve the URL's of the resources. This is done by
3636
// reading from the `Resource Registry` section, which is why the function is
3737
// named GetRRFileContents.
38-
func (e *Environment) GetRRFileContents(ignoreIf igFunc) error {
38+
func (e *Environment) getRRFileContents(ignoreIf igFunc) error {
3939
// initialize environment if empty
4040
if e.Files == nil {
4141
e.Files = make(map[string]string)
@@ -72,7 +72,7 @@ func (e *Environment) GetRRFileContents(ignoreIf igFunc) error {
7272
tempTemplate.client = e.client
7373

7474
// Fetch the contents of remote resource URL's
75-
if err = tempTemplate.GetFileContents(rr, ignoreIf, false); err != nil {
75+
if err = tempTemplate.getFileContents(rr, ignoreIf, false); err != nil {
7676
return err
7777
}
7878
// check the `resources` section (if it exists) for more URL's. Note that
@@ -101,7 +101,7 @@ func (e *Environment) GetRRFileContents(ignoreIf igFunc) error {
101101
resourceBaseURL = baseURL
102102
}
103103
tempTemplate.baseURL = resourceBaseURL
104-
if err := tempTemplate.GetFileContents(v, ignoreIf, false); err != nil {
104+
if err := tempTemplate.getFileContents(v, ignoreIf, false); err != nil {
105105
return err
106106
}
107107
}

openstack/orchestration/v1/stacks/environment_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,15 @@ service_db:
161161

162162
err = env.Parse()
163163
th.AssertNoErr(t, err)
164-
err = env.GetRRFileContents(ignoreIfEnvironment)
164+
err = env.getRRFileContents(ignoreIfEnvironment)
165165
th.AssertNoErr(t, err)
166166
expected_env_files_content := "\nheat_template_version: 2013-05-23\n\ndescription:\n Heat WordPress template to support F18, using only Heat OpenStack-native\n resource types, and without the requirement for heat-cfntools in the image.\n WordPress is web software you can use to create a beautiful website or blog.\n This template installs a single-instance WordPress deployment using a local\n MySQL database to store the data.\n\nparameters:\n\n key_name:\n type: string\n description : Name of a KeyPair to enable SSH access to the instance\n\nresources:\n wordpress_instance:\n type: OS::Nova::Server\n properties:\n image: { get_param: image_id }\n flavor: { get_param: instance_type }\n key_name: { get_param: key_name }"
167167
expected_db_files_content := "\nheat_template_version: 2014-10-16\n\ndescription:\n Test template for Trove resource capabilities\n\nparameters:\n db_pass:\n type: string\n hidden: true\n description: Database access password\n default: secrete\n\nresources:\n\nservice_db:\n type: OS::Trove::Instance\n properties:\n name: trove_test_db\n datastore_type: mariadb\n flavor: 1GB Instance\n size: 10\n databases:\n - name: test_data\n users:\n - name: kitchen_sink\n password: { get_param: db_pass }\n databases: [ test_data ]"
168168

169169
th.AssertEquals(t, expected_env_files_content, env.Files[fakeEnvURL])
170170
th.AssertEquals(t, expected_db_files_content, env.Files[fakeDBURL])
171171

172-
env.FixFileRefs()
172+
env.fixFileRefs()
173173
expected_parsed := map[string]interface{}{
174174
"resource_registry": "2015-04-30",
175175
"My::WP::Server": fakeEnvURL,

openstack/orchestration/v1/stacks/requests.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ func (opts CreateOpts) ToStackCreateMap() (map[string]interface{}, error) {
100100
return nil, err
101101
}
102102

103-
if err := opts.TemplateOpts.GetFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
103+
if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
104104
return nil, err
105105
}
106-
opts.TemplateOpts.FixFileRefs()
106+
opts.TemplateOpts.fixFileRefs()
107107
s["template"] = string(opts.TemplateOpts.Bin)
108108

109109
for k, v := range opts.TemplateOpts.Files {
@@ -118,10 +118,10 @@ func (opts CreateOpts) ToStackCreateMap() (map[string]interface{}, error) {
118118
if err := opts.EnvironmentOpts.Parse(); err != nil {
119119
return nil, err
120120
}
121-
if err := opts.EnvironmentOpts.GetRRFileContents(ignoreIfEnvironment); err != nil {
121+
if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil {
122122
return nil, err
123123
}
124-
opts.EnvironmentOpts.FixFileRefs()
124+
opts.EnvironmentOpts.fixFileRefs()
125125
for k, v := range opts.EnvironmentOpts.Files {
126126
Files[k] = v
127127
}
@@ -250,10 +250,10 @@ func (opts AdoptOpts) ToStackAdoptMap() (map[string]interface{}, error) {
250250
return nil, err
251251
}
252252

253-
if err := opts.TemplateOpts.GetFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
253+
if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
254254
return nil, err
255255
}
256-
opts.TemplateOpts.FixFileRefs()
256+
opts.TemplateOpts.fixFileRefs()
257257
s["template"] = string(opts.TemplateOpts.Bin)
258258

259259
for k, v := range opts.TemplateOpts.Files {
@@ -273,10 +273,10 @@ func (opts AdoptOpts) ToStackAdoptMap() (map[string]interface{}, error) {
273273
if err := opts.EnvironmentOpts.Parse(); err != nil {
274274
return nil, err
275275
}
276-
if err := opts.EnvironmentOpts.GetRRFileContents(ignoreIfEnvironment); err != nil {
276+
if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil {
277277
return nil, err
278278
}
279-
opts.EnvironmentOpts.FixFileRefs()
279+
opts.EnvironmentOpts.fixFileRefs()
280280
for k, v := range opts.EnvironmentOpts.Files {
281281
Files[k] = v
282282
}
@@ -461,10 +461,10 @@ func (opts UpdateOpts) ToStackUpdateMap() (map[string]interface{}, error) {
461461
return nil, err
462462
}
463463

464-
if err := opts.TemplateOpts.GetFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
464+
if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
465465
return nil, err
466466
}
467-
opts.TemplateOpts.FixFileRefs()
467+
opts.TemplateOpts.fixFileRefs()
468468
s["template"] = string(opts.TemplateOpts.Bin)
469469

470470
for k, v := range opts.TemplateOpts.Files {
@@ -476,10 +476,10 @@ func (opts UpdateOpts) ToStackUpdateMap() (map[string]interface{}, error) {
476476
if err := opts.EnvironmentOpts.Parse(); err != nil {
477477
return nil, err
478478
}
479-
if err := opts.EnvironmentOpts.GetRRFileContents(ignoreIfEnvironment); err != nil {
479+
if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil {
480480
return nil, err
481481
}
482-
opts.EnvironmentOpts.FixFileRefs()
482+
opts.EnvironmentOpts.fixFileRefs()
483483
for k, v := range opts.EnvironmentOpts.Files {
484484
Files[k] = v
485485
}
@@ -607,10 +607,10 @@ func (opts PreviewOpts) ToStackPreviewMap() (map[string]interface{}, error) {
607607
return nil, err
608608
}
609609

610-
if err := opts.TemplateOpts.GetFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
610+
if err := opts.TemplateOpts.getFileContents(opts.TemplateOpts.Parsed, ignoreIfTemplate, true); err != nil {
611611
return nil, err
612612
}
613-
opts.TemplateOpts.FixFileRefs()
613+
opts.TemplateOpts.fixFileRefs()
614614
s["template"] = string(opts.TemplateOpts.Bin)
615615

616616
for k, v := range opts.TemplateOpts.Files {
@@ -625,10 +625,10 @@ func (opts PreviewOpts) ToStackPreviewMap() (map[string]interface{}, error) {
625625
if err := opts.EnvironmentOpts.Parse(); err != nil {
626626
return nil, err
627627
}
628-
if err := opts.EnvironmentOpts.GetRRFileContents(ignoreIfEnvironment); err != nil {
628+
if err := opts.EnvironmentOpts.getRRFileContents(ignoreIfEnvironment); err != nil {
629629
return nil, err
630630
}
631-
opts.EnvironmentOpts.FixFileRefs()
631+
opts.EnvironmentOpts.fixFileRefs()
632632
for k, v := range opts.EnvironmentOpts.Files {
633633
Files[k] = v
634634
}

openstack/orchestration/v1/stacks/template.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (t *Template) Validate() error {
3838
// parameter of the template structure. This is the only way that a user can
3939
// use child templates that are located in their filesystem; urls located on the
4040
// web (e.g. on github or swift) can be fetched directly by Heat engine.
41-
func (t *Template) GetFileContents(te interface{}, ignoreIf igFunc, recurse bool) error {
41+
func (t *Template) getFileContents(te interface{}, ignoreIf igFunc, recurse bool) error {
4242
// initialize template if empty
4343
if t.Files == nil {
4444
t.Files = make(map[string]string)
@@ -57,7 +57,7 @@ func (t *Template) GetFileContents(te interface{}, ignoreIf igFunc, recurse bool
5757
value, ok := v.(string)
5858
if !ok {
5959
// if the value is not a string, recursively parse that value
60-
if err := t.GetFileContents(v, ignoreIf, recurse); err != nil {
60+
if err := t.getFileContents(v, ignoreIf, recurse); err != nil {
6161
return err
6262
}
6363
} else if !ignoreIf(k, value) {
@@ -87,7 +87,7 @@ func (t *Template) GetFileContents(te interface{}, ignoreIf igFunc, recurse bool
8787
// required if the child template itself contains references to
8888
// other templates
8989
if recurse {
90-
if err := childTemplate.GetFileContents(childTemplate.Parsed, ignoreIf, recurse); err != nil {
90+
if err := childTemplate.getFileContents(childTemplate.Parsed, ignoreIf, recurse); err != nil {
9191
return err
9292
}
9393
}
@@ -103,7 +103,7 @@ func (t *Template) GetFileContents(te interface{}, ignoreIf igFunc, recurse bool
103103
case []interface{}:
104104
te_slice := te.([]interface{})
105105
for i := range te_slice {
106-
if err := t.GetFileContents(te_slice[i], ignoreIf, recurse); err != nil {
106+
if err := t.getFileContents(te_slice[i], ignoreIf, recurse); err != nil {
107107
return err
108108
}
109109
}

openstack/orchestration/v1/stacks/template_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ resources:
114114

115115
err = te.Parse()
116116
th.AssertNoErr(t, err)
117-
err = te.GetFileContents(te.Parsed, ignoreIfTemplate, true)
117+
err = te.getFileContents(te.Parsed, ignoreIfTemplate, true)
118118
th.AssertNoErr(t, err)
119119
expected_files := map[string]string{
120120
"my_nova.yaml": `heat_template_version: 2014-10-16
@@ -134,7 +134,7 @@ resources:
134134
networks:
135135
- {uuid: 11111111-1111-1111-1111-111111111111}`}
136136
th.AssertEquals(t, expected_files["my_nova.yaml"], te.Files[fakeURL])
137-
te.FixFileRefs()
137+
te.fixFileRefs()
138138
expected_parsed := map[string]interface{}{
139139
"heat_template_version": "2015-04-30",
140140
"resources": map[string]interface{}{

openstack/orchestration/v1/stacks/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func toStringKeys(m interface{}) (map[string]interface{}, error) {
150150

151151
// fix the template reference to files by replacing relative URL's by absolute
152152
// URL's
153-
func (t *TE) FixFileRefs() {
153+
func (t *TE) fixFileRefs() {
154154
t_str := string(t.Bin)
155155
if t.fileMaps == nil {
156156
return

openstack/orchestration/v1/stacks/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestTEFixFileRefs(t *testing.T) {
1717
"string_to_replace": "london bridge is falling down",
1818
},
1919
}
20-
te.FixFileRefs()
20+
te.fixFileRefs()
2121
th.AssertEquals(t, string(te.Bin), `london bridge is falling down: my fair lady`)
2222
}
2323

0 commit comments

Comments
 (0)