forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Damien Le Berrigaud <[email protected]>
- Loading branch information
Jeffrey Peckham
authored and
Damien Le Berrigaud
committed
Oct 30, 2013
1 parent
5a25a1a
commit 70f7a5e
Showing
16 changed files
with
96 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
set -e | ||
|
||
$(dirname $0)/go build -o out/agent main | ||
$(dirname $0)/go build -o out/agent bosh/main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
set -e | ||
|
||
$(dirname $0)/go run src/main/agent.go $* | ||
$(dirname $0)/go run src/bosh/main/agent.go $* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package bootstrap | ||
|
||
import ( | ||
"bosh/filesystem" | ||
"bosh/infrastructure" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
const ( | ||
VCAP_USERNAME = "vcap" | ||
) | ||
|
||
type boostrap struct { | ||
fs filesystem.FileSystem | ||
infrastructure infrastructure.Infrastructure | ||
} | ||
|
||
func New(fs filesystem.FileSystem, infrastructure infrastructure.Infrastructure) (b boostrap) { | ||
b.fs = fs | ||
b.infrastructure = infrastructure | ||
return | ||
} | ||
|
||
func (boot boostrap) Run() { | ||
publicKey, err := boot.infrastructure.GetPublicKey() | ||
if err != nil { | ||
failWithError("Error getting public key", err) | ||
return | ||
} | ||
|
||
homeDir, err := boot.fs.HomeDir(VCAP_USERNAME) | ||
if err != nil { | ||
failWithError("Error finding home dir for user", err) | ||
return | ||
} | ||
|
||
sshPath := filepath.Join(homeDir, ".ssh") | ||
boot.fs.MkdirAll(sshPath, os.FileMode(0700)) | ||
boot.fs.Chown(sshPath, VCAP_USERNAME) | ||
|
||
authKeysPath := filepath.Join(sshPath, "authorized_keys") | ||
err = boot.fs.WriteToFile(authKeysPath, publicKey) | ||
if err != nil { | ||
failWithError("Error creating authorized_keys file", err) | ||
return | ||
} | ||
|
||
boot.fs.Chown(authKeysPath, VCAP_USERNAME) | ||
boot.fs.Chmod(authKeysPath, os.FileMode(0600)) | ||
} | ||
|
||
func failWithError(message string, err error) { | ||
fmt.Fprintf(os.Stderr, "%s: %s", message, err.Error()) | ||
os.Exit(1) | ||
} |
12 changes: 7 additions & 5 deletions
12
src/agent/app_test.go → src/bosh/bootstrap/bootstrap_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/agent/file_system.go → src/bosh/filesystem/file_system_interface.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package agent | ||
package filesystem | ||
|
||
import "os" | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/agent/os_file_system.go → src/bosh/filesystem/os_file_system.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package agent | ||
package filesystem | ||
|
||
import ( | ||
"os" | ||
|
2 changes: 1 addition & 1 deletion
2
src/agent/os_file_system_test.go → src/bosh/filesystem/os_file_system_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package agent | ||
package filesystem | ||
|
||
import ( | ||
"bytes" | ||
|
2 changes: 1 addition & 1 deletion
2
src/agent/aws_infrastructure.go → ...bosh/infrastructure/aws_infrastructure.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package agent | ||
package infrastructure | ||
|
||
import ( | ||
"fmt" | ||
|
2 changes: 1 addition & 1 deletion
2
src/agent/aws_infrastructure_test.go → ...infrastructure/aws_infrastructure_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package agent | ||
package infrastructure | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
|
2 changes: 1 addition & 1 deletion
2
src/agent/infrastructure.go → ...nfrastructure/infrastructure_interface.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"bosh/bootstrap" | ||
"bosh/filesystem" | ||
"bosh/infrastructure" | ||
) | ||
|
||
func main() { | ||
fs := filesystem.OsFileSystem{} | ||
infrastructure := infrastructure.NewAwsInfrastructure("http://169.254.169.254") | ||
|
||
b := bootstrap.New(fs, infrastructure) | ||
b.Run() | ||
} |
8 changes: 4 additions & 4 deletions
8
src/testhelpers/agent/fake_file_system.go → ...esthelpers/filesystem/fake_file_system.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/testhelpers/agent/fake_infrastructure.go → ...ers/infrastructure/fake_infrastructure.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package agent | ||
package infrastructure | ||
|
||
type FakeInfrastructure struct { | ||
PublicKey string | ||
|
This file was deleted.
Oops, something went wrong.