Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cashier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kevin Lyda
cashier
Commits
e4890eb8
Commit
e4890eb8
authored
8 years ago
by
Kevin Lyda
Browse files
Options
Downloads
Patches
Plain Diff
A first pass at saving public keys.
parent
51cc4c07
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/config.go
+20
-0
20 additions, 0 deletions
client/config.go
cmd/cashier/main.go
+15
-6
15 additions, 6 deletions
cmd/cashier/main.go
with
35 additions
and
6 deletions
client/config.go
+
20
−
0
View file @
e4890eb8
...
@@ -3,6 +3,8 @@ package client
...
@@ -3,6 +3,8 @@ package client
import
(
import
(
"github.com/spf13/pflag"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/spf13/viper"
"os/user"
"regexp"
)
)
// Config holds the client configuration.
// Config holds the client configuration.
...
@@ -12,6 +14,8 @@ type Config struct {
...
@@ -12,6 +14,8 @@ type Config struct {
Keysize
int
`mapstructure:"key_size"`
Keysize
int
`mapstructure:"key_size"`
Validity
string
`mapstructure:"validity"`
Validity
string
`mapstructure:"validity"`
ValidateTLSCertificate
bool
`mapstructure:"validate_tls_certificate"`
ValidateTLSCertificate
bool
`mapstructure:"validate_tls_certificate"`
PublicKey
string
`mapstructure:"public_key"`
PublicCert
string
`mapstructure:"public_cert"`
}
}
func
setDefaults
()
{
func
setDefaults
()
{
...
@@ -19,9 +23,25 @@ func setDefaults() {
...
@@ -19,9 +23,25 @@ func setDefaults() {
viper
.
BindPFlag
(
"key_type"
,
pflag
.
Lookup
(
"key_type"
))
viper
.
BindPFlag
(
"key_type"
,
pflag
.
Lookup
(
"key_type"
))
viper
.
BindPFlag
(
"key_size"
,
pflag
.
Lookup
(
"key_size"
))
viper
.
BindPFlag
(
"key_size"
,
pflag
.
Lookup
(
"key_size"
))
viper
.
BindPFlag
(
"validity"
,
pflag
.
Lookup
(
"validity"
))
viper
.
BindPFlag
(
"validity"
,
pflag
.
Lookup
(
"validity"
))
viper
.
BindPFlag
(
"public_key"
,
pflag
.
Lookup
(
"public_key"
))
viper
.
BindPFlag
(
"public_cert"
,
pflag
.
Lookup
(
"public_cert"
))
viper
.
SetDefault
(
"validateTLSCertificate"
,
true
)
viper
.
SetDefault
(
"validateTLSCertificate"
,
true
)
}
}
func
ExpandTilde
(
path
string
)
string
{
re
:=
regexp
.
MustCompile
(
"^~([^/]*)(/.*)"
)
if
m
:=
re
.
FindStringSubmatch
(
path
);
len
(
m
)
>
0
{
u
,
_
:=
user
.
Current
()
if
m
[
1
]
!=
""
{
u
,
_
=
user
.
Lookup
(
m
[
1
])
}
if
u
!=
nil
{
return
u
.
HomeDir
+
m
[
2
]
}
}
return
path
}
// ReadConfig reads the client configuration from a file into a Config struct.
// ReadConfig reads the client configuration from a file into a Config struct.
func
ReadConfig
(
path
string
)
(
*
Config
,
error
)
{
func
ReadConfig
(
path
string
)
(
*
Config
,
error
)
{
setDefaults
()
setDefaults
()
...
...
This diff is collapsed.
Click to expand it.
cmd/cashier/main.go
+
15
−
6
View file @
e4890eb8
package
main
package
main
import
(
import
(
"encoding/base64"
"fmt"
"fmt"
"io/ioutil"
"log"
"log"
"net"
"net"
"os"
"os"
...
@@ -12,6 +14,7 @@ import (
...
@@ -12,6 +14,7 @@ import (
"github.com/nsheridan/cashier/client"
"github.com/nsheridan/cashier/client"
"github.com/pkg/browser"
"github.com/pkg/browser"
"github.com/spf13/pflag"
"github.com/spf13/pflag"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
"golang.org/x/crypto/ssh/agent"
)
)
...
@@ -22,6 +25,8 @@ var (
...
@@ -22,6 +25,8 @@ var (
keysize
=
pflag
.
Int
(
"key_size"
,
2048
,
"Key size. Ignored for ed25519 keys"
)
keysize
=
pflag
.
Int
(
"key_size"
,
2048
,
"Key size. Ignored for ed25519 keys"
)
validity
=
pflag
.
Duration
(
"validity"
,
time
.
Hour
*
24
,
"Key validity"
)
validity
=
pflag
.
Duration
(
"validity"
,
time
.
Hour
*
24
,
"Key validity"
)
keytype
=
pflag
.
String
(
"key_type"
,
"rsa"
,
"Type of private key to generate - rsa, ecdsa or ed25519"
)
keytype
=
pflag
.
String
(
"key_type"
,
"rsa"
,
"Type of private key to generate - rsa, ecdsa or ed25519"
)
public_key
=
pflag
.
String
(
"public_key"
,
""
,
"Filename for public key"
)
public_cert
=
pflag
.
String
(
"public_cert"
,
""
,
"Filename for public cert"
)
)
)
func
main
()
{
func
main
()
{
...
@@ -58,5 +63,9 @@ func main() {
...
@@ -58,5 +63,9 @@ func main() {
if
err
:=
client
.
InstallCert
(
a
,
cert
,
priv
);
err
!=
nil
{
if
err
:=
client
.
InstallCert
(
a
,
cert
,
priv
);
err
!=
nil
{
log
.
Fatalln
(
err
)
log
.
Fatalln
(
err
)
}
}
ioutil
.
WriteFile
(
client
.
ExpandTilde
(
c
.
PublicKey
),
ssh
.
MarshalAuthorizedKey
(
pub
),
0644
)
ioutil
.
WriteFile
(
client
.
ExpandTilde
(
c
.
PublicCert
),
[]
byte
(
cert
.
Type
()
+
" "
+
base64
.
StdEncoding
.
EncodeToString
(
cert
.
Marshal
())),
0644
)
fmt
.
Println
(
"Credentials added."
)
fmt
.
Println
(
"Credentials added."
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment