Skip to content

Commit

Permalink
feat: Support ability to pass identifier case (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
puthrayaharness authored Mar 15, 2023
1 parent 19bd1f1 commit 148c930
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
37 changes: 19 additions & 18 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,24 +234,25 @@ service.name: <+project.name>
## Global Flags
| Flag | Details |
|-----------------------|------------------------------------------------------------------------------------------------------------------------|
| --env | Your target environment. It can be either `Dev`, `QA`, `Prod` or `Prod3` |
| --account | `ACCOUNT_ID` of the account that you wish to migrate |
| --api-key | `API_KEY` to authenticate & authorise the migration. You may also use the `HARNESS_MIGRATOR_AUTH` env variable instead |
| --secret-scope | Scope at which the secret has to be created. It can be `project`, `org` or `account` |
| --connector-scope | Scope at which the connector has to be created. It can be `project`, `org` or `account` |
| --template-scope | Scope at which the templates has to be created. It can be `project`, `org` or `account` |
| --workflow-scope | Scope at which the workflow as template has to be created. It can be `project`, `org` or `account` |
| --org | Identifier of the target org |
| --project | Identifier of the target project |
| --app | Application ID from current gen |
| --workflows | Workflow Ids as comma separated values(ex. `workflow1,workflow2,workflow3`) |
| --pipelines | Pipeline Ids as comma separated values(ex. `pipeline1,pipeline2,pipeline3`) |
| --destination-project | URL of the project where we want to migrate |
| --source-app | URL of the application from which we will migrate the entities |
| --debug | If debug level logs need to be printed |
| --json | Formatted the logs as JSON |
| Flag | Details |
|-----------------------|----------------------------------------------------------------------------------------------------------------------------------|
| --env | Your target environment. It can be either `Dev`, `QA`, `Prod` or `Prod3` |
| --account | `ACCOUNT_ID` of the account that you wish to migrate |
| --api-key | `API_KEY` to authenticate & authorise the migration. You may also use the `HARNESS_MIGRATOR_AUTH` env variable instead |
| --secret-scope | Scope at which the secret has to be created. It can be `project`, `org` or `account` |
| --connector-scope | Scope at which the connector has to be created. It can be `project`, `org` or `account` |
| --template-scope | Scope at which the templates has to be created. It can be `project`, `org` or `account` |
| --workflow-scope | Scope at which the workflow as template has to be created. It can be `project`, `org` or `account` |
| --org | Identifier of the target org |
| --project | Identifier of the target project |
| --app | Application ID from current gen |
| --workflows | Workflow Ids as comma separated values(ex. `workflow1,workflow2,workflow3`) |
| --pipelines | Pipeline Ids as comma separated values(ex. `pipeline1,pipeline2,pipeline3`) |
| --destination-project | URL of the project where we want to migrate |
| --source-app | URL of the application from which we will migrate the entities |
| --identifier-format | To control the format of the identifier generated. It defaults to `CAMEL_CASE`, we currently support `CAMEL_CASE` & `LOWER_CASE` |
| --debug | If debug level logs need to be printed |
| --json | Formatted the logs as JSON |

If not all the required flags are provided we will fall back to prompt based technique to capture all the required details.

Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var migrationReq = struct {
PipelineIds string `survey:"pipelineIds"`
TriggerIds string `survey:"triggerIds"`
File string `survey:"load"`
IdentifierCase string `survey:"identifierCase"`
Debug bool `survey:"debug"`
Json bool `survey:"json"`
AllowInsecureReq bool `survey:"insecure"`
Expand Down Expand Up @@ -59,7 +60,7 @@ func getReqBody(entityType EntityType, filter Filter) RequestBody {
},
}
destination := DestinationDetails{ProjectIdentifier: migrationReq.ProjectIdentifier, OrgIdentifier: migrationReq.OrgIdentifier}
return RequestBody{Inputs: inputs, DestinationDetails: destination, EntityType: entityType, Filter: filter}
return RequestBody{Inputs: inputs, DestinationDetails: destination, EntityType: entityType, Filter: filter, IdentifierCaseFormat: migrationReq.IdentifierCase}
}

func logMigrationDetails() {
Expand Down Expand Up @@ -184,6 +185,13 @@ func main() {
Usage: "log as JSON instead of standard ASCII formatter",
Destination: &migrationReq.Json,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "identifier-format",
Usage: "`FORMAT` to use for generation of identifiers. Supported values as CAMEL_CASE & LOWER_CASE",
Destination: &migrationReq.IdentifierCase,
Value: "CAMEL_CASE",
DefaultText: "CAMEL_CASE",
}),
}
app := &cli.App{
Name: "harness-upgrade",
Expand Down
3 changes: 2 additions & 1 deletion projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func bulkCreateProject(*cli.Context) error {
log.Info("Creating the projects....")

resp, err := Post(url, migrationReq.Auth, BulkCreateBody{
Org: migrationReq.OrgIdentifier,
Org: migrationReq.OrgIdentifier,
IdentifierCaseFormat: migrationReq.IdentifierCase,
})

if err != nil {
Expand Down
12 changes: 7 additions & 5 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ type BulkProjectResult struct {
}

type BulkCreateBody struct {
Org string `json:"orgIdentifier"`
Org string `json:"orgIdentifier"`
IdentifierCaseFormat string `json:"identifierCaseFormat"`
}

type ProjectBody struct {
Expand All @@ -64,10 +65,11 @@ type ProjectListBody struct {
}

type RequestBody struct {
DestinationDetails DestinationDetails `json:"destinationDetails"`
EntityType EntityType `json:"entityType"`
Filter Filter `json:"filter"`
Inputs Inputs `json:"inputs"`
DestinationDetails DestinationDetails `json:"destinationDetails"`
EntityType EntityType `json:"entityType"`
Filter Filter `json:"filter"`
Inputs Inputs `json:"inputs"`
IdentifierCaseFormat string `json:"identifierCaseFormat"`
}

type CurrentGenEntity struct {
Expand Down

0 comments on commit 148c930

Please sign in to comment.