-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ensure id functionality to importer
- Loading branch information
Showing
38 changed files
with
394 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ package client | |
|
||
type GitScmExtension interface { | ||
GetId() string | ||
SetId(string) | ||
} |
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ package client | |
|
||
type JobAction interface { | ||
GetId() string | ||
SetId(string) | ||
} |
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ package client | |
|
||
type JobBuildDiscarderPropertyStrategy interface { | ||
GetId() string | ||
SetId(string) | ||
} |
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
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ package client | |
|
||
type JobGerritTriggerOnEvent interface { | ||
GetId() string | ||
SetId(string) | ||
} |
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
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ package client | |
|
||
type JobProperty interface { | ||
GetId() string | ||
SetId(string) | ||
} |
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ package client | |
|
||
type JobTrigger interface { | ||
GetId() string | ||
SetId(string) | ||
} |
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,23 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/jgramoll/terraform-provider-jenkins/client" | ||
) | ||
|
||
func init() { | ||
ensureDefinitionFuncs["*client.CpsScmFlowDefinition"] = ensureCpsScmFlowDefinition | ||
} | ||
|
||
func ensureCpsScmFlowDefinition(definitionInterface client.JobDefinition) error { | ||
definition := definitionInterface.(*client.CpsScmFlowDefinition) | ||
if err := ensureGitUserRemoteConfigs(definition.SCM.UserRemoteConfigs); err != nil { | ||
return err | ||
} | ||
if err := ensureGitScmBranches(definition.SCM.Branches); err != nil { | ||
return err | ||
} | ||
if err := ensureGitScmSubmoduleConfig(definition.SCM.SubmoduleCfg); err != nil { | ||
return err | ||
} | ||
return ensureGitScmExtensions(definition.SCM.Extensions) | ||
} |
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,32 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
|
||
"github.com/google/uuid" | ||
"github.com/jgramoll/terraform-provider-jenkins/client" | ||
) | ||
|
||
type ensureDefinitionFunc func(client.JobDefinition) error | ||
|
||
var ensureDefinitionFuncs = map[string]ensureDefinitionFunc{} | ||
|
||
func ensureJobDefinition(definition client.JobDefinition) error { | ||
if definition == nil { | ||
return nil | ||
} | ||
if definition.GetId() == "" { | ||
id, err := uuid.NewRandom() | ||
if err != nil { | ||
return err | ||
} | ||
definition.SetId(id.String()) | ||
} | ||
reflectType := reflect.TypeOf(definition).String() | ||
ensureFunc, ok := ensureDefinitionFuncs[reflectType] | ||
if !ok { | ||
return fmt.Errorf("Unknown Definition Type %s", reflectType) | ||
} | ||
return ensureFunc(definition) | ||
} |
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,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
"github.com/jgramoll/terraform-provider-jenkins/client" | ||
) | ||
|
||
func ensureGitScmBranches(branches *client.GitScmBranches) error { | ||
if branches == nil || branches.Items == nil { | ||
return nil | ||
} | ||
for _, item := range *branches.Items { | ||
if item.Id == "" { | ||
id, err := uuid.NewRandom() | ||
if err != nil { | ||
return err | ||
} | ||
item.Id = id.String() | ||
} | ||
} | ||
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 @@ | ||
package main |
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,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
"github.com/jgramoll/terraform-provider-jenkins/client" | ||
) | ||
|
||
func ensureGitScmExtensions(extensions *client.GitScmExtensions) error { | ||
if extensions == nil || extensions.Items == nil { | ||
return nil | ||
} | ||
for _, item := range *extensions.Items { | ||
if item.GetId() == "" { | ||
id, err := uuid.NewRandom() | ||
if err != nil { | ||
return err | ||
} | ||
item.SetId(id.String()) | ||
} | ||
} | ||
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,9 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/jgramoll/terraform-provider-jenkins/client" | ||
) | ||
|
||
func ensureGitScmSubmoduleConfig(branches *client.GitScmSubmodulesConfig) error { | ||
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,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
"github.com/jgramoll/terraform-provider-jenkins/client" | ||
) | ||
|
||
func ensureGitUserRemoteConfigs(configs *client.GitUserRemoteConfigs) error { | ||
if configs == nil || configs.Items == nil { | ||
return nil | ||
} | ||
for _, item := range *configs.Items { | ||
if item.Id == "" { | ||
id, err := uuid.NewRandom() | ||
if err != nil { | ||
return err | ||
} | ||
item.Id = id.String() | ||
} | ||
} | ||
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,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/google/uuid" | ||
"github.com/jgramoll/terraform-provider-jenkins/client" | ||
) | ||
|
||
func ensureJobActions(actions *client.JobActions) error { | ||
if actions == nil || actions.Items == nil { | ||
return nil | ||
} | ||
for _, item := range *actions.Items { | ||
if item.GetId() == "" { | ||
id, err := uuid.NewRandom() | ||
if err != nil { | ||
return err | ||
} | ||
item.SetId(id.String()) | ||
} | ||
} | ||
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 @@ | ||
package main |
Oops, something went wrong.