@@ -18,8 +18,6 @@ package project
1818import (
1919 "context"
2020 "fmt"
21- "io"
22- "net/url"
2321
2422 "github.com/mia-platform/miactl/internal/client"
2523 "github.com/mia-platform/miactl/internal/clioptions"
@@ -46,12 +44,6 @@ type applyProjectOptions struct {
4644 FilePath string
4745}
4846
49- type ApplyProjectConfigurationRequest struct {
50- Title string `json:"title" yaml:"title"`
51- PreviousSave string `json:"previousSave,omitempty" yaml:"previousSave,omitempty"`
52- * configuration.DescribeConfiguration
53- }
54-
5547// ApplyCmd returns a cobra command for applying a project configuration
5648func ApplyCmd (options * clioptions.CLIOptions ) * cobra.Command {
5749 cmd := & cobra.Command {
@@ -71,7 +63,7 @@ func ApplyCmd(options *clioptions.CLIOptions) *cobra.Command {
7163 FilePath : options .InputFilePath ,
7264 }
7365
74- return handleApplyProjectConfigurationCmd (cmd .Context (), client , cmdOptions , cmd . OutOrStdout () )
66+ return handleApplyProjectConfigurationCmd (cmd .Context (), client , cmdOptions )
7567 },
7668 }
7769
@@ -87,7 +79,7 @@ func ApplyCmd(options *clioptions.CLIOptions) *cobra.Command {
8779 return cmd
8880}
8981
90- func handleApplyProjectConfigurationCmd (ctx context.Context , client * client.APIClient , options applyProjectOptions , writer io. Writer ) error {
82+ func handleApplyProjectConfigurationCmd (ctx context.Context , client * client.APIClient , options applyProjectOptions ) error {
9183 err := validateApplyProjectOptions (options )
9284 if err != nil {
9385 return err
@@ -98,7 +90,7 @@ func handleApplyProjectConfigurationCmd(ctx context.Context, client *client.APIC
9890 return fmt .Errorf ("failed to apply project configuration: %w" , err )
9991 }
10092
101- fmt .Fprintln ( writer , "Project configuration applied successfully" )
93+ fmt .Println ( "Project configuration applied successfully" )
10294 return nil
10395}
10496
@@ -119,7 +111,7 @@ func validateApplyProjectOptions(options applyProjectOptions) error {
119111}
120112
121113func applyConfiguration (ctx context.Context , client * client.APIClient , options applyProjectOptions ) error {
122- ref , err := getRevisionRef (options .RevisionName )
114+ ref , err := configuration . GetEncodedRevisionRef (options .RevisionName )
123115 if err != nil {
124116 return err
125117 }
@@ -135,10 +127,10 @@ func applyConfiguration(ctx context.Context, client *client.APIClient, options a
135127 }
136128
137129 previousSnapshotID := structuredConfig .Config ["commitId" ].(string )
138- applyConfig := ApplyProjectConfigurationRequest {
139- DescribeConfiguration : structuredConfig ,
140- Title : "[miactl] Applied project configuration" ,
141- PreviousSave : previousSnapshotID ,
130+ applyConfig := configuration. ApplyRequest {
131+ Configuration : structuredConfig ,
132+ Title : "[miactl] Applied project configuration" ,
133+ PreviousSave : previousSnapshotID ,
142134 }
143135
144136 body , err := resources .EncodeResourceToJSON (applyConfig )
@@ -161,12 +153,3 @@ func applyConfiguration(ctx context.Context, client *client.APIClient, options a
161153
162154 return nil
163155}
164-
165- func getRevisionRef (revisionName string ) (string , error ) {
166- if len (revisionName ) == 0 {
167- return "" , fmt .Errorf ("missing revision name, please provide a revision name" )
168- }
169-
170- encodedRevisionName := url .PathEscape (revisionName )
171- return fmt .Sprintf ("revisions/%s" , encodedRevisionName ), nil
172- }
0 commit comments