-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MySQL storage and tests #5
Merged
jessepeterson
merged 19 commits into
micromdm:main
from
mikermcneil:issue-4-add-mysql-storage-and-tests
Oct 3, 2022
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cd04701
Add MySQL storage and tests
lucasmrod e5554fb
go mod tidy
lucasmrod 37aed61
Move docker-compose-test.yml file to storage/mysql
lucasmrod 4aafd64
Fix flag storage default value
lucasmrod fa61974
Remove defaultDays TODO comment
lucasmrod 15a774b
Add mysql storage to docs/operations-guide.md
lucasmrod f0dd734
Move mysql imports
lucasmrod 1c988d7
Fix spacing
lucasmrod 478cc3e
Remove config guard check
lucasmrod 2ef1eca
Use MySQL 8.0.19 for tests
lucasmrod ea941b4
Use storage.ErrNotFound
lucasmrod 31fced2
Do not rely on parseTime in dsn
lucasmrod 95a8f2b
Use MySQL 8 syntax for ON DUPLICATE KEY UPDATE
lucasmrod 0a82006
Export schema as Go variable
lucasmrod 21464cb
Move RSAKeyFromPEM from package api to tokenpki
lucasmrod bb4cb0f
Format time to string for storage
lucasmrod 1bb90ee
Address review comments
lucasmrod 465df8b
Merge branch 'main' into issue-4-add-mysql-storage-and-tests
lucasmrod 63fe581
Rename to cli package
lucasmrod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,29 @@ | ||
// Package cli contains shared command-line helpers and utilities. | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
_ "github.com/go-sql-driver/mysql" | ||
"github.com/micromdm/nanodep/storage" | ||
"github.com/micromdm/nanodep/storage/file" | ||
"github.com/micromdm/nanodep/storage/mysql" | ||
) | ||
|
||
// Storage parses a storage name and dsn to determine which and return a storage backend. | ||
func Storage(storageName, dsn string) (storage.AllStorage, error) { | ||
var store storage.AllStorage | ||
var err error | ||
switch storageName { | ||
case "file": | ||
if dsn == "" { | ||
dsn = "db" | ||
} | ||
store, err = file.New(dsn) | ||
case "mysql": | ||
store, err = mysql.New(mysql.WithDSN(dsn)) | ||
default: | ||
return nil, fmt.Errorf("unknown storage: %q", storageName) | ||
} | ||
return store, err | ||
} |
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,53 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestDefaultConfigRetreiver(t *testing.T) { | ||
for _, cfg := range []struct { | ||
name string | ||
cfg *Config | ||
expectedCfg *Config | ||
}{ | ||
{ | ||
name: "nil", | ||
cfg: nil, | ||
expectedCfg: &Config{BaseURL: DefaultBaseURL}, | ||
}, | ||
{ | ||
name: "empty", | ||
cfg: &Config{}, | ||
expectedCfg: &Config{BaseURL: DefaultBaseURL}, | ||
}, | ||
{ | ||
name: "existent", | ||
cfg: &Config{BaseURL: "foo"}, | ||
expectedCfg: &Config{BaseURL: "foo"}, | ||
}, | ||
} { | ||
t.Run(cfg.name, func(t *testing.T) { | ||
c := NewDefaultConfigRetreiver(cfgRetriever{cfg: cfg.cfg}) | ||
actualCfg, err := c.RetrieveConfig(context.Background(), "foo") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if actualCfg == nil { | ||
t.Fatal("expected not-nil config") | ||
} | ||
if *actualCfg != *cfg.expectedCfg { | ||
t.Fatalf("unexpected base URL: %+v vs %+v", actualCfg, cfg.expectedCfg) | ||
} | ||
}) | ||
} | ||
|
||
} | ||
|
||
type cfgRetriever struct { | ||
cfg *Config | ||
} | ||
|
||
func (c cfgRetriever) RetrieveConfig(context.Context, string) (*Config, error) { | ||
return c.cfg, nil | ||
} |
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
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️