Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1102)

Side by Side Diff: state/apiserver/client/client.go

Issue 63790045: State policy based config validation.
Patch Set: State policy based config validation. Created 10 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package client 4 package client
5 5
6 import ( 6 import (
7 "fmt" 7 "fmt"
8 "net/url" 8 "net/url"
9 "os" 9 "os"
10 "strings" 10 "strings"
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 if v, found := args.Config["agent-version"]; found { 781 if v, found := args.Config["agent-version"]; found {
782 oldVersion, _ := oldConfig.AgentVersion() 782 oldVersion, _ := oldConfig.AgentVersion()
783 if v != oldVersion.String() { 783 if v != oldVersion.String() {
784 return fmt.Errorf("agent-version cannot be changed") 784 return fmt.Errorf("agent-version cannot be changed")
785 } 785 }
786 } 786 }
787 // Apply the attributes specified for the command to the state config. 787 // Apply the attributes specified for the command to the state config.
788 newConfig, err := oldConfig.Apply(args.Config) 788 newConfig, err := oldConfig.Apply(args.Config)
789 if err != nil { 789 if err != nil {
790 return err 790 return err
791 } 791 }
fwereade 2014/02/27 13:36:34 Shouldn't all this code above here move into state
792 » env, err := environs.New(oldConfig) 792 » // Now try to apply the new config.
793 » if err != nil { 793 » return c.api.state.SetEnvironConfig(newConfig, oldConfig)
794 » » return err
795 » }
796 » // Now validate this new config against the existing config via the prov ider.
797 » provider := env.Provider()
798 » newProviderConfig, err := provider.Validate(newConfig, oldConfig)
799 » if err != nil {
800 » » return err
801 » }
802 » // Now try to apply the new validated config.
803 » return c.api.state.SetEnvironConfig(newProviderConfig, oldConfig)
804 } 794 }
805 795
806 // SetEnvironAgentVersion sets the environment agent version. 796 // SetEnvironAgentVersion sets the environment agent version.
807 func (c *Client) SetEnvironAgentVersion(args params.SetEnvironAgentVersion) erro r { 797 func (c *Client) SetEnvironAgentVersion(args params.SetEnvironAgentVersion) erro r {
808 return c.api.state.SetEnvironAgentVersion(args.Version) 798 return c.api.state.SetEnvironAgentVersion(args.Version)
809 } 799 }
810 800
811 func destroyErr(desc string, ids, errs []string) error { 801 func destroyErr(desc string, ids, errs []string) error {
812 if len(errs) == 0 { 802 if len(errs) == 0 {
813 return nil 803 return nil
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 // CharmArchiveName returns a string that is suitable as a file name 904 // CharmArchiveName returns a string that is suitable as a file name
915 // in a storage URL. It is constructed from the charm name, revision 905 // in a storage URL. It is constructed from the charm name, revision
916 // and a random UUID string. 906 // and a random UUID string.
917 func CharmArchiveName(name string, revision int) (string, error) { 907 func CharmArchiveName(name string, revision int) (string, error) {
918 uuid, err := utils.NewUUID() 908 uuid, err := utils.NewUUID()
919 if err != nil { 909 if err != nil {
920 return "", err 910 return "", err
921 } 911 }
922 return charm.Quote(fmt.Sprintf("%s-%d-%s", name, revision, uuid)), nil 912 return charm.Quote(fmt.Sprintf("%s-%d-%s", name, revision, uuid)), nil
923 } 913 }
OLDNEW
« no previous file with comments | « environs/statepolicy.go ('k') | state/configvalidator_test.go » ('j') | state/policy.go » ('J')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b