|
| 1 | +package docker |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "github.com/1Password/shell-plugins/sdk" |
| 6 | + "github.com/1Password/shell-plugins/sdk/importer" |
| 7 | + "github.com/1Password/shell-plugins/sdk/provision" |
| 8 | + "github.com/1Password/shell-plugins/sdk/schema" |
| 9 | + "github.com/1Password/shell-plugins/sdk/schema/fieldname" |
| 10 | +) |
| 11 | + |
| 12 | +func UserCredentials() schema.CredentialType { |
| 13 | + return schema.CredentialType{ |
| 14 | + Name: "", // TODO: Register name in project://sdk/schema/credname/names.go |
| 15 | + DocsURL: sdk.URL("https://docker.com/docs/user_credentials"), // TODO: Replace with actual URL |
| 16 | + ManagementURL: sdk.URL("https://console.docker.com/user/security/tokens"), // TODO: Replace with actual URL |
| 17 | + Fields: []schema.CredentialField{ |
| 18 | + { |
| 19 | + Name: fieldname.Username, |
| 20 | + MarkdownDescription: " used to authenticate to Docker.", |
| 21 | + }, |
| 22 | + { |
| 23 | + Name: fieldname.Password, |
| 24 | + MarkdownDescription: " used to authenticate to Docker.", |
| 25 | + Secret: true, |
| 26 | + }, |
| 27 | + }, |
| 28 | + DefaultProvisioner: provision.TempFile(dockerConfig, provision.AtFixedPath("~/.docker/config.json")), |
| 29 | + Importer: importer.TryAll( |
| 30 | + TryDockerConfigFile(), |
| 31 | + )} |
| 32 | +} |
| 33 | + |
| 34 | +type PerHostAuth struct { |
| 35 | + UsernamePassword string `json:"auth"` |
| 36 | +} |
| 37 | + |
| 38 | +type Config struct { |
| 39 | + Auths map[string]PerHostAuth `json:"auths"` |
| 40 | +} |
| 41 | + |
| 42 | +// TODO: Check if the platform stores the User Credentials in a local config file, and if so, |
| 43 | +// implement the function below to add support for importing it. |
| 44 | +func TryDockerConfigFile() sdk.Importer { |
| 45 | + return importer.TryFile("~/path/to/config/file.yml", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) { |
| 46 | + // var config Config |
| 47 | + // if err := contents.ToYAML(&config); err != nil { |
| 48 | + // out.AddError(err) |
| 49 | + // return |
| 50 | + // } |
| 51 | + |
| 52 | + // if config. == "" { |
| 53 | + // return |
| 54 | + // } |
| 55 | + |
| 56 | + // out.AddCandidate(sdk.ImportCandidate{ |
| 57 | + // Fields: map[sdk.FieldName]string{ |
| 58 | + // fieldname.: config., |
| 59 | + // }, |
| 60 | + // }) |
| 61 | + }) |
| 62 | +} |
| 63 | + |
| 64 | +// TODO: Implement the config file schema |
| 65 | +// type Config struct { |
| 66 | +// string |
| 67 | +// } |
0 commit comments