-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Untangle certificate acquisition * Make gRPC server accept different registrable APIs * Move postgres setup logic out of tink-server's main.go to an internal package * Move gRPC server implementation to the new /server package * Remove unused global `workflowData` Signed-off-by: Micah Hausler <[email protected]>
- Loading branch information
1 parent
e1e2af6
commit ae45cce
Showing
15 changed files
with
479 additions
and
236 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package internal | ||
|
||
import ( | ||
"database/sql" | ||
|
||
"github.com/packethost/pkg/log" | ||
"github.com/tinkerbell/tink/db" | ||
) | ||
|
||
// SetupPostgres initializes a connection to a postgres database. | ||
func SetupPostgres(connInfo string, onlyMigrate bool, logger log.Logger) (db.Database, error) { | ||
dbCon, err := sql.Open("postgres", connInfo) | ||
if err != nil { | ||
return nil, err | ||
} | ||
tinkDB := db.Connect(dbCon, logger) | ||
|
||
if onlyMigrate { | ||
logger.Info("Applying migrations. This process will end when migrations will take place.") | ||
numAppliedMigrations, err := tinkDB.Migrate() | ||
if err != nil { | ||
return nil, err | ||
} | ||
logger.With("num_applied_migrations", numAppliedMigrations).Info("Migrations applied successfully") | ||
return nil, nil | ||
} | ||
|
||
numAvailableMigrations, err := tinkDB.CheckRequiredMigrations() | ||
if err != nil { | ||
return nil, err | ||
} | ||
if numAvailableMigrations != 0 { | ||
logger.Info("Your database schema is not up to date. Please apply migrations running tink-server with env var ONLY_MIGRATION set.") | ||
} | ||
return *tinkDB, 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 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.