@@ -37,12 +37,7 @@ func (c *client) CreateEnvironment(ctx context.Context, environmentID string, cr
3737
3838// GetEnvironment gets the environment by id.
3939func (c * client ) GetEnvironment (ctx context.Context , environmentName string ) (* v1pb.Environment , error ) {
40- req , err := http .NewRequestWithContext (ctx , "GET" , fmt .Sprintf ("%s/%s/%s" , c .url , c .version , environmentName ), nil )
41- if err != nil {
42- return nil , err
43- }
44-
45- body , err := c .doRequest (req )
40+ body , err := c .getResource (ctx , environmentName )
4641 if err != nil {
4742 return nil , err
4843 }
@@ -76,18 +71,8 @@ func (c *client) ListEnvironment(ctx context.Context, showDeleted bool) (*v1pb.L
7671}
7772
7873// UpdateEnvironment updates the environment.
79- func (c * client ) UpdateEnvironment (ctx context.Context , patch * v1pb.Environment , updateMask []string ) (* v1pb.Environment , error ) {
80- payload , err := protojson .Marshal (patch )
81- if err != nil {
82- return nil , err
83- }
84-
85- req , err := http .NewRequestWithContext (ctx , "PATCH" , fmt .Sprintf ("%s/%s/%s?update_mask=%s" , c .url , c .version , patch .Name , strings .Join (updateMask , "," )), strings .NewReader (string (payload )))
86- if err != nil {
87- return nil , err
88- }
89-
90- body , err := c .doRequest (req )
74+ func (c * client ) UpdateEnvironment (ctx context.Context , patch * v1pb.Environment , updateMasks []string ) (* v1pb.Environment , error ) {
75+ body , err := c .updateResource (ctx , patch .Name , patch , updateMasks , false /* allow missing = false*/ )
9176 if err != nil {
9277 return nil , err
9378 }
@@ -102,25 +87,12 @@ func (c *client) UpdateEnvironment(ctx context.Context, patch *v1pb.Environment,
10287
10388// DeleteEnvironment deletes the environment.
10489func (c * client ) DeleteEnvironment (ctx context.Context , environmentName string ) error {
105- req , err := http .NewRequestWithContext (ctx , "DELETE" , fmt .Sprintf ("%s/%s/%s" , c .url , c .version , environmentName ), nil )
106- if err != nil {
107- return err
108- }
109-
110- if _ , err := c .doRequest (req ); err != nil {
111- return err
112- }
113- return nil
90+ return c .deleteResource (ctx , environmentName )
11491}
11592
11693// UndeleteEnvironment undeletes the environment.
11794func (c * client ) UndeleteEnvironment (ctx context.Context , environmentName string ) (* v1pb.Environment , error ) {
118- req , err := http .NewRequestWithContext (ctx , "POST" , fmt .Sprintf ("%s/%s/%s:undelete" , c .url , c .version , environmentName ), nil )
119- if err != nil {
120- return nil , err
121- }
122-
123- body , err := c .doRequest (req )
95+ body , err := c .undeleteResource (ctx , environmentName )
12496 if err != nil {
12597 return nil , err
12698 }
0 commit comments