@@ -5,6 +5,7 @@ package main
55
66import (
77 "context"
8+ "encoding/json"
89 "errors"
910 "fmt"
1011 "io"
@@ -44,6 +45,24 @@ func getServerCommands(serverConfig *types.ServerConfig, clientConfig *types.Cli
4445 return stopServer (cCtx , clientConfig )
4546 },
4647 },
48+ {
49+ Name : "show-config" ,
50+ Usage : "Show the server dynamic config" ,
51+ Flags : flags ,
52+ Before : altsrc .InitInputSourceWithContext (flags , altsrc .NewTomlSourceFromFlagFunc (configFileFlagName )),
53+ Action : func (cCtx * cli.Context ) error {
54+ return showConfig (cCtx , clientConfig )
55+ },
56+ },
57+ {
58+ Name : "update-config" ,
59+ Usage : "Update the server dynamic config" ,
60+ Flags : flags ,
61+ Before : altsrc .InitInputSourceWithContext (flags , altsrc .NewTomlSourceFromFlagFunc (configFileFlagName )),
62+ Action : func (cCtx * cli.Context ) error {
63+ return updateConfig (cCtx , clientConfig )
64+ },
65+ },
4766 },
4867 },
4968 }, nil
@@ -127,3 +146,49 @@ func stopServer(_ *cli.Context, clientConfig *types.ClientConfig) error {
127146 }
128147 return nil
129148}
149+
150+ func showConfig (_ * cli.Context , clientConfig * types.ClientConfig ) error {
151+ client := system .NewHttpClient (clientConfig .ServerUri , clientConfig .AdminUser , clientConfig .Client .AdminPassword , clientConfig .Client .SkipCertCheck )
152+
153+ var response types.ConfigResponse
154+ err := client .Get ("/_openrun/config" , nil , & response )
155+ if err != nil {
156+ return err
157+ }
158+ json , err := json .MarshalIndent (response .DynamicConfig , "" , " " )
159+ if err != nil {
160+ return err
161+ }
162+ fmt .Printf ("%s\n " , string (json ))
163+ return nil
164+ }
165+
166+ func updateConfig (cCtx * cli.Context , clientConfig * types.ClientConfig ) error {
167+ client := system .NewHttpClient (clientConfig .ServerUri , clientConfig .AdminUser , clientConfig .Client .AdminPassword , clientConfig .Client .SkipCertCheck )
168+
169+ if cCtx .NArg () != 1 {
170+ return fmt .Errorf ("expected one argument: <configFilePath>" )
171+ }
172+ configFilePath := cCtx .Args ().Get (0 )
173+ configFile , err := os .ReadFile (configFilePath )
174+ if err != nil {
175+ return err
176+ }
177+ var inputConfig types.DynamicConfig
178+ err = json .Unmarshal (configFile , & inputConfig )
179+ if err != nil {
180+ return err
181+ }
182+ var response types.ConfigResponse
183+ err = client .Post ("/_openrun/config" , nil , & inputConfig , & response )
184+ if err != nil {
185+ return err
186+ }
187+
188+ json , err := json .MarshalIndent (response .DynamicConfig , "" , " " )
189+ if err != nil {
190+ return err
191+ }
192+ fmt .Printf ("%s\n " , string (json ))
193+ return nil
194+ }
0 commit comments