Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion docs/azdo_help_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -935,10 +935,24 @@ Aliases
service-endpoints, serviceendpoints, se
```

### `azdo service-endpoint create`
### `azdo service-endpoint create [ORGANIZATION/]PROJECT --from-file <path> [flags]`

Create service connections

```
-e, --encoding string File encoding (utf-8, ascii, utf-16be, utf-16le). (default "utf-8")
-f, --from-file string Path to the JSON service endpoint definition or '-' for stdin.
-q, --jq expression Filter JSON output using a jq expression
--json fields[=*] Output JSON with the specified fields. Prefix a field with '-' to exclude it.
-t, --template string Format JSON output using a Go template; see "azdo help formatting"
```

Aliases

```
import
```

#### `azdo service-endpoint create azurerm [ORGANIZATION/]PROJECT --name <name> --authentication-scheme <scheme> [flags]`

Create an Azure Resource Manager service connection
Expand Down
54 changes: 53 additions & 1 deletion docs/azdo_service-endpoint_create.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,63 @@
## Command `azdo service-endpoint create`

Create service connections
```
azdo service-endpoint create [ORGANIZATION/]PROJECT --from-file <path> [flags]
```

Create Azure DevOps service endpoints (service connections) from a JSON definition file.

The project scope accepts the form [ORGANIZATION/]PROJECT. When the organization segment
is omitted the default organization from configuration is used.

Check the available subcommands to create service connections of specific well-known types.


### Available commands

* [azdo service-endpoint create azurerm](./azdo_service-endpoint_create_azurerm.md)

### Options


* `-e`, `--encoding` `string` (default `&#34;utf-8&#34;`)

File encoding (utf-8, ascii, utf-16be, utf-16le).

* `-f`, `--from-file` `string`

Path to the JSON service endpoint definition or &#39;-&#39; for stdin.

* `-q`, `--jq` `expression`

Filter JSON output using a jq expression

* `--json` `fields`

Output JSON with the specified fields. Prefix a field with &#39;-&#39; to exclude it.

* `-t`, `--template` `string`

Format JSON output using a Go template; see &#34;azdo help formatting&#34;


### ALIASES

- `import`

### JSON Fields

`administratorsGroup`, `authorization`, `createdBy`, `data`, `description`, `groupScopeId`, `id`, `isReady`, `isShared`, `name`, `operationStatus`, `owner`, `readersGroup`, `serviceEndpointProjectReferences`, `type`, `url`

### Examples

```bash
# Create a service endpoint from a UTF-8 JSON file
azdo service-endpoint create my-org/my-project --from-file ./endpoint.json

# Read the definition from stdin using UTF-16LE encoding
cat endpoint.json | azdo service-endpoint create my-org/my-project --from-file - --encoding utf-16le
```

### See also

* [azdo service-endpoint](./azdo_service-endpoint.md)
2 changes: 1 addition & 1 deletion docs/azdo_service-endpoint_create_azurerm.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ This command is modeled after the Azure DevOps Terraform Provider's implementati

### JSON Fields

`authorization`, `description`, `id`, `name`, `type`, `url`
`administratorsGroup`, `authorization`, `createdBy`, `data`, `description`, `groupScopeId`, `id`, `isReady`, `isShared`, `name`, `operationStatus`, `owner`, `readersGroup`, `serviceEndpointProjectReferences`, `type`, `url`

### Examples

Expand Down
44 changes: 19 additions & 25 deletions internal/cmd/serviceendpoint/create/azurerm/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/MakeNowJust/heredoc"
"github.com/google/uuid"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/core"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/serviceendpoint"
"github.com/spf13/cobra"
"go.uber.org/zap"
Expand Down Expand Up @@ -182,7 +181,24 @@ func NewCmd(ctx util.CmdContext) *cobra.Command {
cmd.Flags().BoolVarP(&opts.yes, "yes", "y", false, "Skip confirmation prompts")
cmd.Flags().BoolVar(&opts.grantPermissionToAllPipelines, "grant-permission-to-all-pipelines", false, "Grant access permission to all pipelines to use the service connection")

util.AddJSONFlags(cmd, &opts.exporter, []string{"id", "name", "type", "url", "description", "authorization"})
util.AddJSONFlags(cmd, &opts.exporter, []string{
"administratorsGroup",
"authorization",
"createdBy",
"data",
"description",
"groupScopeId",
"id",
"isReady",
"isShared",
"name",
"operationStatus",
"owner",
"readersGroup",
"serviceEndpointProjectReferences",
"type",
"url",
})

_ = cmd.MarkFlagRequired("name")
_ = cmd.MarkFlagRequired("authentication-scheme")
Expand Down Expand Up @@ -220,7 +236,7 @@ func runCreate(ctx util.CmdContext, opts *createOptions) error {
}
}

projectRef, err := resolveProjectReference(ctx, scope)
projectRef, err := shared.ResolveProjectReference(ctx, scope)
if err != nil {
return util.FlagErrorWrap(err)
}
Expand Down Expand Up @@ -467,25 +483,3 @@ func getEndpointURL(opts *createOptions) (string, error) {
return "", fmt.Errorf("unknown environment: %s", opts.environment)
}
}

func resolveProjectReference(ctx util.CmdContext, scope *util.Scope) (*serviceendpoint.ProjectReference, error) {
coreClient, err := ctx.ClientFactory().Core(ctx.Context(), scope.Organization)
if err != nil {
return nil, fmt.Errorf("failed to create core client: %w", err)
}

project, err := coreClient.GetProject(ctx.Context(), core.GetProjectArgs{
ProjectId: types.ToPtr(scope.Project),
})
if err != nil {
return nil, fmt.Errorf("failed to resolve project %q: %w", scope.Project, err)
}
if project == nil || project.Id == nil {
return nil, fmt.Errorf("project %q does not expose an ID", scope.Project)
}

return &serviceendpoint.ProjectReference{
Id: project.Id,
Name: project.Name,
}, nil
}
Loading
Loading