Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
13182d97
Commit
13182d97
authored
Jul 12, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #164 from mitchellh/do-env-vars
builder/digitalocean: use detected env variables for credentials
parents
e52f8e04
490279c6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
2 deletions
+40
-2
builder/digitalocean/builder.go
builder/digitalocean/builder.go
+11
-0
builder/digitalocean/builder_test.go
builder/digitalocean/builder_test.go
+25
-0
website/source/docs/builders/digitalocean.html.markdown
website/source/docs/builders/digitalocean.html.markdown
+4
-2
No files found.
builder/digitalocean/builder.go
View file @
13182d97
...
...
@@ -12,6 +12,7 @@ import (
"github.com/mitchellh/packer/builder/common"
"github.com/mitchellh/packer/packer"
"log"
"os"
"strconv"
"text/template"
"time"
...
...
@@ -64,6 +65,16 @@ func (b *Builder) Prepare(raws ...interface{}) error {
// Optional configuration with defaults
//
if
b
.
config
.
APIKey
==
""
{
// Default to environment variable for api_key, if it exists
b
.
config
.
APIKey
=
os
.
Getenv
(
"DIGITALOCEAN_API_KEY"
)
}
if
b
.
config
.
ClientID
==
""
{
// Default to environment variable for client_id, if it exists
b
.
config
.
ClientID
=
os
.
Getenv
(
"DIGITALOCEAN_CLIENT_ID"
)
}
if
b
.
config
.
RegionID
==
0
{
// Default to Region "New York"
b
.
config
.
RegionID
=
1
...
...
builder/digitalocean/builder_test.go
View file @
13182d97
...
...
@@ -2,10 +2,17 @@ package digitalocean
import
(
"github.com/mitchellh/packer/packer"
"os"
"strconv"
"testing"
)
func
init
()
{
// Clear out the credential env vars
os
.
Setenv
(
"DIGITALOCEAN_API_KEY"
,
""
)
os
.
Setenv
(
"DIGITALOCEAN_CLIENT_ID"
,
""
)
}
func
testConfig
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
"client_id"
:
"foo"
,
...
...
@@ -55,6 +62,15 @@ func TestBuilderPrepare_APIKey(t *testing.T) {
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
// Test env variable
delete
(
config
,
"api_key"
)
os
.
Setenv
(
"DIGITALOCEAN_API_KEY"
,
"foo"
)
defer
os
.
Setenv
(
"DIGITALOCEAN_API_KEY"
,
""
)
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
func
TestBuilderPrepare_ClientID
(
t
*
testing
.
T
)
{
...
...
@@ -79,6 +95,15 @@ func TestBuilderPrepare_ClientID(t *testing.T) {
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
// Test env variable
delete
(
config
,
"client_id"
)
os
.
Setenv
(
"DIGITALOCEAN_CLIENT_ID"
,
"foo"
)
defer
os
.
Setenv
(
"DIGITALOCEAN_CLIENT_ID"
,
""
)
err
=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
func
TestBuilderPrepare_RegionID
(
t
*
testing
.
T
)
{
...
...
website/source/docs/builders/digitalocean.html.markdown
View file @
13182d97
...
...
@@ -25,11 +25,13 @@ Required:
*
`api_key`
(string) - The API key to use to access your account. You can
retrieve this on the "API" page visible after logging into your account
on DigitalOcean.
on DigitalOcean. Alternatively, the builder looks for the environment
variable
`DIGITALOCEAN_API_KEY`
.
*
`client_id`
(string) - The client ID to use to access your account. You can
find this on the "API" page visible after logging into your account on
DigitalOcean.
DigitalOcean. Alternatively, the builder looks for the environment
variable
`DIGITALOCEAN_CLIENT_ID`
.
Optional:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment