-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add boostrap and serving command to mlp binary
Signed-off-by: Khor Shu Heng <khor.heng@gojek.com>
- Loading branch information
1 parent
21f31ed
commit 050b931
Showing
11 changed files
with
135 additions
and
17 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
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,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/caraml-dev/mlp/api/config" | ||
"github.com/caraml-dev/mlp/api/log" | ||
"github.com/caraml-dev/mlp/api/pkg/authz/enforcer" | ||
) | ||
|
||
type BootstrapOptions struct { | ||
ProjectReaders []string | ||
MLPAdmins []string | ||
} | ||
|
||
var ( | ||
bootstrapOpts = &BootstrapOptions{} | ||
bootstrapCmd = &cobra.Command{ | ||
Use: "bootstrap", | ||
Short: "Start bootstrap job to populate Keto", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := startKetoBootstrap(globalConfig, bootstrapOpts) | ||
if err != nil { | ||
log.Panicf("unable to bootstrap keto: %v", err) | ||
} | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
bootstrapCmd.Flags().StringSliceVarP(&bootstrapOpts.ProjectReaders, "project-readers", "r", | ||
[]string{}, "Comma separated list of project readers") | ||
bootstrapCmd.Flags().StringSliceVar(&bootstrapOpts.MLPAdmins, "mlp-admins", []string{}, | ||
"Comma separated list of MLP admins") | ||
} | ||
|
||
func startKetoBootstrap(globalCfg *config.Config, bootstrapOpts *BootstrapOptions) error { | ||
authEnforcer, err := enforcer.NewEnforcerBuilder(). | ||
KetoEndpoints(globalCfg.Authorization.KetoRemoteRead, globalCfg.Authorization.KetoRemoteWrite). | ||
Build() | ||
if err != nil { | ||
return err | ||
} | ||
updateRequest := enforcer.NewAuthorizationUpdateRequest() | ||
updateRequest.UpdateRoleMembers("mlp.projects.reader", bootstrapOpts.ProjectReaders) | ||
updateRequest.UpdateRoleMembers("mlp.admin", bootstrapOpts.MLPAdmins) | ||
err = authEnforcer.UpdateAuthorization(context.Background(), updateRequest) | ||
if err != nil { | ||
return err | ||
} | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/caraml-dev/mlp/api/config" | ||
"github.com/caraml-dev/mlp/api/log" | ||
) | ||
|
||
var ( | ||
configFiles []string | ||
globalConfig *config.Config | ||
rootCmd = &cobra.Command{ | ||
Use: "mlp", | ||
Short: "CaraML Machine Learning Platform Console", | ||
Long: "CaraML Machine Learning Platform Console, which provides a web UI to interact with different CaraML " + | ||
"services.", | ||
} | ||
) | ||
|
||
func init() { | ||
cobra.OnInitialize(initConfig) | ||
rootCmd.PersistentFlags().StringSliceVarP(&configFiles, "config", "c", []string{}, | ||
"Comma separated list of config files to load. The last config file will take precedence over the "+ | ||
"previous ones.") | ||
rootCmd.AddCommand(serveCmd) | ||
rootCmd.AddCommand(bootstrapCmd) | ||
} | ||
|
||
func initConfig() { | ||
var err error | ||
globalConfig, err = config.LoadAndValidate(configFiles...) | ||
if err != nil { | ||
log.Fatalf("failed initializing config: %v", err) | ||
} | ||
} | ||
|
||
func Execute() { | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
log.Fatalf("failed executing root command: %v", 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,9 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/caraml-dev/mlp/api/cmd" | ||
) | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ FROM ${MLP_API_IMAGE} | |
COPY ui/build ./ui/build | ||
|
||
ENTRYPOINT ["sh", "-c", "mlp \"$@\"", "--"] | ||
CMD ["serve"] |
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